Absolutely barbaric rewrite
This commit is contained in:
parent
d0b721e332
commit
8fcccc40ee
|
@ -4,25 +4,22 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cpw.mods.ironchest.client.IronChestTextureHandler;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.particle.EffectRenderer;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
@ -37,9 +34,9 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.EnumBlockRenderType;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
@ -47,7 +44,7 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class BlockIronChest extends BlockContainer
|
||||
public class BlockIronChest extends Block
|
||||
{
|
||||
public static final PropertyEnum<IronChestType> VARIANT_PROP = PropertyEnum.create("variant", IronChestType.class);
|
||||
protected static final AxisAlignedBB IRON_CHEST_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.875D, 0.9375D);
|
||||
|
@ -55,6 +52,7 @@ public class BlockIronChest extends BlockContainer
|
|||
public BlockIronChest()
|
||||
{
|
||||
super(Material.IRON);
|
||||
this.setRegistryName(new ResourceLocation(IronChest.MOD_ID, "BlockIronChest"));
|
||||
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, IronChestType.IRON));
|
||||
|
||||
|
@ -114,16 +112,22 @@ public class BlockIronChest extends BlockContainer
|
|||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int metadata)
|
||||
public boolean hasTileEntity(IBlockState state)
|
||||
{
|
||||
return IronChestType.makeEntity(metadata);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, IBlockState state)
|
||||
{
|
||||
return state.getValue(VARIANT_PROP).makeEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
|
||||
{
|
||||
for (IronChestType type : IronChestType.values())
|
||||
for (IronChestType type : IronChestType.VALUES)
|
||||
{
|
||||
if (type.isValidForCreativeMode())
|
||||
{
|
||||
|
@ -135,7 +139,7 @@ public class BlockIronChest extends BlockContainer
|
|||
@Override
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
return this.getDefaultState().withProperty(VARIANT_PROP, IronChestType.values()[meta]);
|
||||
return this.getDefaultState().withProperty(VARIANT_PROP, IronChestType.VALUES[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -147,17 +151,7 @@ public class BlockIronChest extends BlockContainer
|
|||
@Override
|
||||
protected BlockStateContainer createBlockState()
|
||||
{
|
||||
return new BlockStateContainer(this, new IProperty<?>[] { VARIANT_PROP });
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
|
||||
{
|
||||
ArrayList<ItemStack> items = Lists.newArrayList();
|
||||
ItemStack stack = new ItemStack(this, 1, this.getMetaFromState(state));
|
||||
IronChestType.values()[IronChestType.validateMeta(this.getMetaFromState(state))].adornItemDrop(stack);
|
||||
items.add(stack);
|
||||
return items;
|
||||
return new BlockStateContainer(this, VARIANT_PROP);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -170,30 +164,12 @@ public class BlockIronChest extends BlockContainer
|
|||
@Override
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState blockState, EntityLivingBase entityliving, ItemStack itemStack)
|
||||
{
|
||||
byte chestFacing = 0;
|
||||
int facing = MathHelper.floor_double((entityliving.rotationYaw * 4F) / 360F + 0.5D) & 3;
|
||||
if (facing == 0)
|
||||
{
|
||||
chestFacing = 2;
|
||||
}
|
||||
if (facing == 1)
|
||||
{
|
||||
chestFacing = 5;
|
||||
}
|
||||
if (facing == 2)
|
||||
{
|
||||
chestFacing = 3;
|
||||
}
|
||||
if (facing == 3)
|
||||
{
|
||||
chestFacing = 4;
|
||||
}
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te != null && te instanceof TileEntityIronChest)
|
||||
{
|
||||
TileEntityIronChest teic = (TileEntityIronChest) te;
|
||||
teic.wasPlaced(entityliving, itemStack);
|
||||
teic.setFacing(chestFacing);
|
||||
teic.setFacing(entityliving.getHorizontalFacing().getOpposite());
|
||||
world.notifyBlockUpdate(pos, blockState, blockState, 3);
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +177,7 @@ public class BlockIronChest extends BlockContainer
|
|||
@Override
|
||||
public int damageDropped(IBlockState state)
|
||||
{
|
||||
return IronChestType.validateMeta(state.getValue(VARIANT_PROP).ordinal());
|
||||
return state.getValue(VARIANT_PROP).ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -268,9 +244,14 @@ public class BlockIronChest extends BlockContainer
|
|||
return super.getExplosionResistance(world, pos, exploder, explosion);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Override public boolean addLandingEffects(IBlockState state, WorldServer world, BlockPos pos, IBlockState iblockstate, EntityLivingBase entity, int numberOfParticles) {
|
||||
* IronChestTextureHandler.addDestroyEffects(world, pos, state); return true; }
|
||||
*/
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean addHitEffects(IBlockState state, World worldObj, RayTraceResult target, net.minecraft.client.particle.EffectRenderer effectRenderer)
|
||||
public boolean addHitEffects(IBlockState state, World worldObj, RayTraceResult target, EffectRenderer effectRenderer)
|
||||
{
|
||||
IronChestTextureHandler.addHitEffects(worldObj, target.getBlockPos(), target.sideHit);
|
||||
return true;
|
||||
|
@ -278,7 +259,7 @@ public class BlockIronChest extends BlockContainer
|
|||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean addDestroyEffects(World world, BlockPos pos, net.minecraft.client.particle.EffectRenderer effectRenderer)
|
||||
public boolean addDestroyEffects(World world, BlockPos pos, EffectRenderer effectRenderer)
|
||||
{
|
||||
IronChestTextureHandler.addDestroyEffects(world, pos, world.getBlockState(pos));
|
||||
return true;
|
||||
|
@ -328,4 +309,12 @@ public class BlockIronChest extends BlockContainer
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockEventReceived(World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam)
|
||||
{
|
||||
super.onBlockEventReceived(worldIn, pos, state, eventID, eventParam);
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
return tileentity != null && tileentity.receiveClientEvent(eventID, eventParam);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw. All rights reserved. This program and the accompanying materials are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors: cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
@ -15,40 +15,37 @@ import static cpw.mods.ironchest.IronChestType.OBSIDIAN;
|
|||
import static cpw.mods.ironchest.IronChestType.SILVER;
|
||||
import static cpw.mods.ironchest.IronChestType.WOOD;
|
||||
|
||||
import cpw.mods.ironchest.client.ModelHelper;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
public enum ChestChangerType
|
||||
{
|
||||
//@formatter:off
|
||||
IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "Iron to Gold Chest Upgrade", "mmm", "msm", "mmm"),
|
||||
GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade", "Gold to Diamond Chest Upgrade", "GGG", "msm", "GGG"),
|
||||
COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "Copper to Silver Chest Upgrade", "mmm", "msm", "mmm"),
|
||||
SILVERGOLD(SILVER, GOLD, "silverGoldUpgrade", "Silver to Gold Chest Upgrade", "mGm", "GsG", "mGm"),
|
||||
COPPERIRON(COPPER, IRON, "copperIronUpgrade", "Copper to Iron Chest Upgrade", "mGm", "GsG", "mGm"),
|
||||
DIAMONDCRYSTAL(DIAMOND, CRYSTAL, "diamondCrystalUpgrade", "Diamond to Crystal Chest Upgrade", "GGG", "GOG", "GGG"),
|
||||
WOODIRON(WOOD, IRON, "woodIronUpgrade", "Normal chest to Iron Chest Upgrade", "mmm", "msm", "mmm"),
|
||||
WOODCOPPER(WOOD, COPPER, "woodCopperUpgrade", "Normal chest to Copper Chest Upgrade", "mmm", "msm", "mmm"),
|
||||
DIAMONDOBSIDIAN(DIAMOND, OBSIDIAN, "diamondObsidianUpgrade", "Diamond to Obsidian Chest Upgrade", "mmm", "mGm", "mmm");
|
||||
IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "mmm", "msm", "mmm"),
|
||||
GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade", "GGG", "msm", "GGG"),
|
||||
COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "mmm", "msm", "mmm"),
|
||||
SILVERGOLD(SILVER, GOLD, "silverGoldUpgrade", "mGm", "GsG", "mGm"),
|
||||
COPPERIRON(COPPER, IRON, "copperIronUpgrade", "mGm", "GsG", "mGm"),
|
||||
DIAMONDCRYSTAL(DIAMOND, CRYSTAL, "diamondCrystalUpgrade", "GGG", "GOG", "GGG"),
|
||||
WOODIRON(WOOD, IRON, "woodIronUpgrade", "mmm", "msm", "mmm"),
|
||||
WOODCOPPER(WOOD, COPPER, "woodCopperUpgrade", "mmm", "msm", "mmm"),
|
||||
DIAMONDOBSIDIAN(DIAMOND, OBSIDIAN, "diamondObsidianUpgrade", "mmm", "mGm", "mmm");
|
||||
//@formatter:on
|
||||
|
||||
public static final ChestChangerType[] VALUES = values();
|
||||
|
||||
private IronChestType source;
|
||||
private IronChestType target;
|
||||
public String itemName;
|
||||
public String descriptiveName;
|
||||
public ItemChestChanger item;
|
||||
private String[] recipe;
|
||||
|
||||
private ChestChangerType(IronChestType source, IronChestType target, String itemName, String descriptiveName, String... recipe)
|
||||
ChestChangerType(IronChestType source, IronChestType target, String itemName, String... recipe)
|
||||
{
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
this.itemName = itemName;
|
||||
this.descriptiveName = descriptiveName;
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
|
@ -62,31 +59,24 @@ public enum ChestChangerType
|
|||
return from == this.source;
|
||||
}
|
||||
|
||||
public int getTarget()
|
||||
public IronChestType getTarget()
|
||||
{
|
||||
return this.target.ordinal();
|
||||
return this.target;
|
||||
}
|
||||
|
||||
public ItemChestChanger buildItem()
|
||||
{
|
||||
this.item = new ItemChestChanger(this);
|
||||
this.item.setRegistryName(this.itemName);
|
||||
|
||||
GameRegistry.register(this.item);
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
|
||||
{
|
||||
ModelHelper.registerItem(this.item, "ironchest:" + this.itemName);
|
||||
}
|
||||
|
||||
return this.item;
|
||||
}
|
||||
|
||||
public void addRecipes()
|
||||
{
|
||||
for (String sourceMat : this.source.getMatList())
|
||||
for (String sourceMat : this.source.matList)
|
||||
{
|
||||
for (String targetMat : this.target.getMatList())
|
||||
for (String targetMat : this.target.matList)
|
||||
{
|
||||
Object targetMaterial = IronChestType.translateOreName(targetMat);
|
||||
Object sourceMaterial = IronChestType.translateOreName(sourceMat);
|
||||
|
@ -99,7 +89,7 @@ public enum ChestChangerType
|
|||
|
||||
public static void buildItems()
|
||||
{
|
||||
for (ChestChangerType type : values())
|
||||
for (ChestChangerType type : VALUES)
|
||||
{
|
||||
type.buildItem();
|
||||
}
|
||||
|
@ -107,7 +97,7 @@ public enum ChestChangerType
|
|||
|
||||
public static void generateRecipes()
|
||||
{
|
||||
for (ChestChangerType item : values())
|
||||
for (ChestChangerType item : VALUES)
|
||||
{
|
||||
item.addRecipes();
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
|
@ -20,12 +20,6 @@ public class CommonProxy implements IGuiHandler
|
|||
{
|
||||
public void registerRenderInformation()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public <T extends TileEntityIronChest> void registerTileEntitySpecialRenderer(Class<T> typ)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -48,10 +42,4 @@ public class CommonProxy implements IGuiHandler
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public World getClientWorld()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -4,9 +4,9 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class ContainerIronChest extends Container
|
|||
public ItemStack transferStackInSlot(EntityPlayer p, int i)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(i);
|
||||
Slot slot = this.inventorySlots.get(i);
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
|
@ -93,9 +93,9 @@ public class ContainerIronChest extends Container
|
|||
{
|
||||
for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++)
|
||||
{
|
||||
for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++)
|
||||
for (int chestCol = 0; chestCol < type.rowLength; chestCol++)
|
||||
{
|
||||
this.addSlotToContainer(type.makeSlot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18));
|
||||
this.addSlotToContainer(type.makeSlot(chestInventory, chestCol + chestRow * type.rowLength, 12 + chestCol * 18, 8 + chestRow * 18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,6 +125,6 @@ public class ContainerIronChest extends Container
|
|||
@ChestContainer.RowSizeCallback
|
||||
public int getNumColumns()
|
||||
{
|
||||
return this.type.getRowLength();
|
||||
return this.type.rowLength;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,66 +4,68 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import cpw.mods.ironchest.client.IronChestEventHandler;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.Mod.Instance;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
@Mod(modid = "IronChest", name = "Iron Chests", dependencies = "required-after:Forge@[12.16.0.1819,)", acceptedMinecraftVersions = "[1.9]")
|
||||
@Mod(modid = IronChest.MOD_ID, name = "Iron Chests", dependencies = "required-after:Forge@[12.16.0.1819,)", acceptedMinecraftVersions = "[1.9]")
|
||||
public class IronChest
|
||||
{
|
||||
public static BlockIronChest ironChestBlock;
|
||||
public static ItemIronChest ironChestItemBlock;
|
||||
public static final String MOD_ID = "IronChest";
|
||||
|
||||
@Instance(IronChest.MOD_ID)
|
||||
public static IronChest instance;
|
||||
|
||||
@SidedProxy(clientSide = "cpw.mods.ironchest.client.ClientProxy", serverSide = "cpw.mods.ironchest.CommonProxy")
|
||||
public static CommonProxy proxy;
|
||||
@Instance("IronChest")
|
||||
public static IronChest instance;
|
||||
|
||||
public static BlockIronChest ironChestBlock;
|
||||
public static ItemIronChest ironChestItemBlock;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
Version.init(event.getVersionProperties());
|
||||
event.getModMetadata().version = Version.fullVersionString();
|
||||
}
|
||||
Properties properties = event.getVersionProperties();
|
||||
|
||||
if (properties != null)
|
||||
{
|
||||
String major = properties.getProperty("IronChest.build.major.number");
|
||||
String minor = properties.getProperty("IronChest.build.minor.number");
|
||||
String rev = properties.getProperty("IronChest.build.revision.number");
|
||||
String build = properties.getProperty("IronChest.build.number");
|
||||
// String mcversion = properties.getProperty("IronChest.build.mcversion");
|
||||
event.getModMetadata().version = String.format("%s.%s.%s build %s", major, minor, rev, build);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void load(FMLInitializationEvent evt)
|
||||
{
|
||||
// Registration has been moved to init to account for the registration of inventory models
|
||||
// Minecraft.getRenderItem() returns null before this stage
|
||||
ChestChangerType.buildItems();
|
||||
ironChestBlock = new BlockIronChest();
|
||||
ironChestItemBlock = new ItemIronChest(ironChestBlock);
|
||||
|
||||
ironChestBlock.setRegistryName("BlockIronChest");
|
||||
ironChestItemBlock.setRegistryName("BlockIronChest");
|
||||
|
||||
GameRegistry.register(ironChestBlock);
|
||||
ironChestBlock = GameRegistry.register(new BlockIronChest());
|
||||
ironChestItemBlock = GameRegistry.register(new ItemIronChest(ironChestBlock));
|
||||
GameRegistry.register(ironChestItemBlock);
|
||||
|
||||
for (IronChestType typ : IronChestType.values())
|
||||
for (IronChestType typ : IronChestType.VALUES)
|
||||
{
|
||||
GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest." + typ.name(), typ.name());
|
||||
proxy.registerTileEntitySpecialRenderer(typ.clazz);
|
||||
GameRegistry.registerTileEntity(typ.clazz, "IronChest." + typ.name());
|
||||
}
|
||||
|
||||
IronChestType.registerBlocksAndRecipes(ironChestBlock);
|
||||
ChestChangerType.generateRecipes();
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
|
||||
proxy.registerRenderInformation();
|
||||
MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler());
|
||||
|
||||
// FIXME: MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler());
|
||||
MinecraftForge.EVENT_BUS.register(IronChestEventHandler.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,15 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
@ -21,94 +21,77 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagByte;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
||||
public enum IronChestType implements IStringSerializable
|
||||
{
|
||||
//@formatter:off
|
||||
IRON(54, 9, true, "Iron Chest", "ironchest.png", 0, Arrays.asList("ingotIron", "ingotRefinedIron"), TileEntityIronChest.class, "mmmmPmmmm", "mGmG3GmGm"),
|
||||
GOLD(81, 9, true, "Gold Chest", "goldchest.png", 1, Arrays.asList("ingotGold"), TileEntityGoldChest.class, "mmmmPmmmm", "mGmG4GmGm"),
|
||||
DIAMOND(108, 12, true, "Diamond Chest", "diamondchest.png", 2, Arrays.asList("gemDiamond"), TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"),
|
||||
COPPER(45, 9, false, "Copper Chest", "copperchest.png", 3, Arrays.asList("ingotCopper"), TileEntityCopperChest.class, "mmmmCmmmm"),
|
||||
SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, Arrays.asList("ingotSilver"), TileEntitySilverChest.class, "mmmm3mmmm", "mGmG0GmGm"),
|
||||
CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"),
|
||||
OBSIDIAN(108, 12, false, "Obsidian Chest", "obsidianchest.png", 6, Arrays.asList("obsidian"), TileEntityObsidianChest.class, "mmmm2mmmm"),
|
||||
DIRTCHEST9000(1, 1, false, "Dirt Chest 9000", "dirtchest.png", 7, Arrays.asList("dirt"), TileEntityDirtChest.class, Item.getItemFromBlock(Blocks.DIRT), "mmmmCmmmm"),
|
||||
WOOD(0, 0, false, "", "", -1, Arrays.asList("plankWood"), null);
|
||||
IRON(54, 9, true, "ironchest.png", Arrays.asList("ingotIron", "ingotRefinedIron"), TileEntityIronChest.class, "mmmmPmmmm", "mGmG3GmGm"),
|
||||
GOLD(81, 9, true, "goldchest.png", Collections.singleton("ingotGold"), TileEntityGoldChest.class, "mmmmPmmmm", "mGmG4GmGm"),
|
||||
DIAMOND(108, 12, true, "diamondchest.png", Collections.singleton("gemDiamond"), TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"),
|
||||
COPPER(45, 9, false, "copperchest.png", Collections.singleton("ingotCopper"), TileEntityCopperChest.class, "mmmmCmmmm"),
|
||||
SILVER(72, 9, false, "silverchest.png", Collections.singleton("ingotSilver"), TileEntitySilverChest.class, "mmmm3mmmm", "mGmG0GmGm"),
|
||||
CRYSTAL(108, 12, true, "crystalchest.png", Collections.singleton("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"),
|
||||
OBSIDIAN(108, 12, false, "obsidianchest.png", Collections.singleton("obsidian"), TileEntityObsidianChest.class, "mmmm2mmmm"),
|
||||
DIRTCHEST9000(1, 1, false, "dirtchest.png", Collections.singleton("dirt"), TileEntityDirtChest.class, "mmmmCmmmm"),
|
||||
WOOD(0, 0, false, "", Collections.singleton("plankWood"), null);
|
||||
//@formatter:on
|
||||
int size;
|
||||
private int rowLength;
|
||||
public String friendlyName;
|
||||
private boolean tieredChest;
|
||||
private String modelTexture;
|
||||
private int textureRow;
|
||||
public Class<? extends TileEntityIronChest> clazz;
|
||||
private String[] recipes;
|
||||
private ArrayList<String> matList;
|
||||
private Item itemFilter;
|
||||
|
||||
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats,
|
||||
Class<? extends TileEntityIronChest> clazz, String... recipes)
|
||||
{
|
||||
this(size, rowLength, tieredChest, friendlyName, modelTexture, textureRow, mats, clazz, (Item) null, recipes);
|
||||
}
|
||||
public static final IronChestType VALUES[] = values();
|
||||
|
||||
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats,
|
||||
Class<? extends TileEntityIronChest> clazz, Item itemFilter, String... recipes)
|
||||
public final String name;
|
||||
public final int size;
|
||||
public final int rowLength;
|
||||
public final boolean tieredChest;
|
||||
public final ResourceLocation modelTexture;
|
||||
private String breakTexture;
|
||||
public final Class<? extends TileEntityIronChest> clazz;
|
||||
public final Collection<String> recipes;
|
||||
public final Collection<String> matList;
|
||||
|
||||
IronChestType(int size, int rowLength, boolean tieredChest, String modelTexture, Collection<String> mats, Class<? extends TileEntityIronChest> clazz,
|
||||
String... recipes)
|
||||
{
|
||||
this.name = this.name().toLowerCase();
|
||||
this.size = size;
|
||||
this.rowLength = rowLength;
|
||||
this.tieredChest = tieredChest;
|
||||
this.friendlyName = friendlyName;
|
||||
this.modelTexture = modelTexture;
|
||||
this.textureRow = textureRow;
|
||||
this.modelTexture = new ResourceLocation("ironchest", "textures/model/" + modelTexture);
|
||||
this.matList = Collections.unmodifiableCollection(mats);
|
||||
this.clazz = clazz;
|
||||
this.itemFilter = itemFilter;
|
||||
this.recipes = recipes;
|
||||
this.matList = new ArrayList<String>();
|
||||
this.matList.addAll(mats);
|
||||
this.recipes = Collections.unmodifiableCollection(Arrays.asList(recipes));
|
||||
}
|
||||
|
||||
public String getBreakTexture()
|
||||
{
|
||||
if (this.breakTexture == null)
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case DIRTCHEST9000:
|
||||
{
|
||||
this.breakTexture = "minecraft:blocks/dirt";
|
||||
}
|
||||
case OBSIDIAN:
|
||||
{
|
||||
this.breakTexture = "minecraft:blocks/obsidian";
|
||||
}
|
||||
default:
|
||||
{
|
||||
this.breakTexture = "ironchest:blocks/" + this.getName() + "break";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.breakTexture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
|
||||
public String getModelTexture()
|
||||
{
|
||||
return this.modelTexture;
|
||||
}
|
||||
|
||||
public int getTextureRow()
|
||||
{
|
||||
return this.textureRow;
|
||||
}
|
||||
|
||||
public static TileEntityIronChest makeEntity(int metadata)
|
||||
{
|
||||
// Compatibility
|
||||
int chesttype = validateMeta(metadata);
|
||||
if (chesttype == metadata)
|
||||
{
|
||||
try
|
||||
{
|
||||
TileEntityIronChest te = values()[chesttype].clazz.newInstance();
|
||||
return te;
|
||||
}
|
||||
catch (InstantiationException e)
|
||||
{
|
||||
// unpossible
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
// unpossible
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public static void registerBlocksAndRecipes(BlockIronChest blockResult)
|
||||
|
@ -136,15 +119,12 @@ public enum IronChestType implements IStringSerializable
|
|||
{
|
||||
mainMaterial = translateOreName(mat);
|
||||
//@formatter:off
|
||||
addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit,
|
||||
'm', mainMaterial, 'P', previousTier, /* previous tier of chest */
|
||||
'G', "blockGlass", 'C', "chestWood",
|
||||
'0', new ItemStack(blockResult, 1, 0), /* Iron Chest */
|
||||
addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, 'm', mainMaterial, 'P', previousTier, /* previous tier of chest */
|
||||
'G', "blockGlass", 'C', "chestWood", '0', new ItemStack(blockResult, 1, 0), /* Iron Chest */
|
||||
'1', new ItemStack(blockResult, 1, 1), /* Gold Chest */
|
||||
'2', new ItemStack(blockResult, 1, 2), /* Diamond Chest */
|
||||
'3', new ItemStack(blockResult, 1, 3), /* Copper Chest */
|
||||
'4', new ItemStack(blockResult, 1, 4) /* Silver Chest */
|
||||
);
|
||||
'4', new ItemStack(blockResult, 1, 4) /* Silver Chest */);
|
||||
//@formatter:on
|
||||
}
|
||||
}
|
||||
|
@ -174,36 +154,14 @@ public enum IronChestType implements IStringSerializable
|
|||
return this.size / this.rowLength;
|
||||
}
|
||||
|
||||
public int getRowLength()
|
||||
{
|
||||
return this.rowLength;
|
||||
}
|
||||
|
||||
public boolean isTransparent()
|
||||
{
|
||||
return this == CRYSTAL;
|
||||
}
|
||||
|
||||
public List<String> getMatList()
|
||||
{
|
||||
return this.matList;
|
||||
}
|
||||
|
||||
public static int validateMeta(int i)
|
||||
{
|
||||
if (i < values().length && values()[i].size > 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValidForCreativeMode()
|
||||
{
|
||||
return validateMeta(this.ordinal()) == this.ordinal();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isExplosionResistant()
|
||||
|
@ -216,9 +174,16 @@ public enum IronChestType implements IStringSerializable
|
|||
return new ValidatingSlot(chestInventory, index, x, y, this);
|
||||
}
|
||||
|
||||
private static final Item DIRT_ITEM = Item.getItemFromBlock(Blocks.DIRT);
|
||||
|
||||
public boolean acceptsStack(ItemStack itemstack)
|
||||
{
|
||||
return this.itemFilter == null || itemstack == null || itemstack.getItem() == this.itemFilter;
|
||||
if (this == DIRTCHEST9000)
|
||||
{
|
||||
return itemstack == null || itemstack.getItem() == DIRT_ITEM;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void adornItemDrop(ItemStack item)
|
||||
|
@ -228,4 +193,29 @@ public enum IronChestType implements IStringSerializable
|
|||
item.setTagInfo("dirtchest", new NBTTagByte((byte) 1));
|
||||
}
|
||||
}
|
||||
|
||||
public TileEntityIronChest makeEntity()
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case IRON:
|
||||
return new TileEntityIronChest();
|
||||
case GOLD:
|
||||
return new TileEntityGoldChest();
|
||||
case DIAMOND:
|
||||
return new TileEntityDiamondChest();
|
||||
case COPPER:
|
||||
return new TileEntityCopperChest();
|
||||
case SILVER:
|
||||
return new TileEntitySilverChest();
|
||||
case CRYSTAL:
|
||||
return new TileEntityCrystalChest();
|
||||
case OBSIDIAN:
|
||||
return new TileEntityObsidianChest();
|
||||
case DIRTCHEST9000:
|
||||
return new TileEntityDirtChest();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,9 +4,9 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
|
@ -26,12 +26,11 @@ import net.minecraft.world.World;
|
|||
|
||||
public class ItemChestChanger extends Item
|
||||
{
|
||||
private ChestChangerType type;
|
||||
public final ChestChangerType type;
|
||||
|
||||
public ItemChestChanger(ChestChangerType type)
|
||||
{
|
||||
this.type = type;
|
||||
|
||||
this.setMaxStackSize(1);
|
||||
this.setUnlocalizedName("ironchest:" + type.name());
|
||||
this.setCreativeTab(CreativeTabs.MISC);
|
||||
|
@ -64,14 +63,14 @@ public class ItemChestChanger extends Item
|
|||
TileEntity te = worldIn.getTileEntity(pos);
|
||||
TileEntityIronChest newchest = new TileEntityIronChest();
|
||||
ItemStack[] chestContents = new ItemStack[27];
|
||||
int chestFacing = 0;
|
||||
EnumFacing chestFacing = EnumFacing.DOWN;
|
||||
if (te != null)
|
||||
{
|
||||
if (te instanceof TileEntityIronChest)
|
||||
{
|
||||
chestContents = ((TileEntityIronChest) te).chestContents;
|
||||
chestFacing = ((TileEntityIronChest) te).getFacing();
|
||||
newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal()));
|
||||
newchest = this.type.getTarget().makeEntity();
|
||||
if (newchest == null)
|
||||
{
|
||||
return EnumActionResult.PASS;
|
||||
|
@ -80,37 +79,23 @@ public class ItemChestChanger extends Item
|
|||
else if (te instanceof TileEntityChest)
|
||||
{
|
||||
IBlockState chestState = worldIn.getBlockState(pos);
|
||||
EnumFacing orientation = chestState.getValue(BlockChest.FACING);
|
||||
if (orientation == EnumFacing.NORTH)
|
||||
{
|
||||
chestFacing = 2;
|
||||
}
|
||||
if (orientation == EnumFacing.EAST)
|
||||
{
|
||||
chestFacing = 5;
|
||||
}
|
||||
if (orientation == EnumFacing.SOUTH)
|
||||
{
|
||||
chestFacing = 3;
|
||||
}
|
||||
if (orientation == EnumFacing.WEST)
|
||||
{
|
||||
chestFacing = 4;
|
||||
}
|
||||
if (((TileEntityChest) te).numPlayersUsing > 0)
|
||||
chestFacing = chestState.getValue(BlockChest.FACING);
|
||||
TileEntityChest chest = (TileEntityChest) te;
|
||||
|
||||
if (chest.numPlayersUsing > 0)
|
||||
{
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
if (!this.getType().canUpgrade(IronChestType.WOOD))
|
||||
if (!this.type.canUpgrade(IronChestType.WOOD))
|
||||
{
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
chestContents = new ItemStack[((TileEntityChest) te).getSizeInventory()];
|
||||
chestContents = new ItemStack[chest.getSizeInventory()];
|
||||
for (int i = 0; i < chestContents.length; i++)
|
||||
{
|
||||
chestContents[i] = ((TileEntityChest) te).getStackInSlot(i);
|
||||
chestContents[i] = chest.getStackInSlot(i);
|
||||
}
|
||||
newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal()));
|
||||
newchest = this.type.getTarget().makeEntity();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,20 +119,10 @@ public class ItemChestChanger extends Item
|
|||
if (te2 instanceof TileEntityIronChest)
|
||||
{
|
||||
((TileEntityIronChest) te2).setContents(chestContents);
|
||||
((TileEntityIronChest) te2).setFacing((byte) chestFacing);
|
||||
((TileEntityIronChest) te2).setFacing(chestFacing);
|
||||
}
|
||||
|
||||
stack.stackSize = playerIn.capabilities.isCreativeMode ? stack.stackSize : stack.stackSize - 1;
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
public int getTargetChestOrdinal(int sourceOrdinal)
|
||||
{
|
||||
return this.type.getTarget();
|
||||
}
|
||||
|
||||
public ChestChangerType getType()
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,21 +4,23 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class ItemIronChest extends ItemBlock
|
||||
{
|
||||
public ItemIronChest(Block block)
|
||||
{
|
||||
super(block);
|
||||
this.setRegistryName(new ResourceLocation(IronChest.MOD_ID, "BlockIronChest"));
|
||||
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
|
@ -27,12 +29,12 @@ public class ItemIronChest extends ItemBlock
|
|||
@Override
|
||||
public int getMetadata(int meta)
|
||||
{
|
||||
return IronChestType.validateMeta(meta);
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemstack)
|
||||
{
|
||||
return "tile.ironchest:" + IronChestType.values()[itemstack.getMetadata()].name();
|
||||
return "tile.ironchest:" + IronChestType.VALUES[itemstack.getMetadata()].getName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|||
|
||||
public class OcelotsSitOnChestsHandler
|
||||
{
|
||||
|
||||
@SubscribeEvent
|
||||
public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt)
|
||||
{
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
|
@ -16,5 +16,4 @@ public class TileEntityCopperChest extends TileEntityIronChest
|
|||
{
|
||||
super(IronChestType.COPPER);
|
||||
}
|
||||
|
||||
}
|
|
@ -4,9 +4,9 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
|
@ -40,10 +40,9 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
public float prevLidAngle;
|
||||
public float lidAngle;
|
||||
private int numUsingPlayers;
|
||||
private IronChestType type;
|
||||
public ItemStack[] chestContents;
|
||||
private ItemStack[] topStacks;
|
||||
private byte facing;
|
||||
private EnumFacing facing;
|
||||
private boolean inventoryTouched;
|
||||
private boolean hadStuff;
|
||||
private String customName;
|
||||
|
@ -56,19 +55,14 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
protected TileEntityIronChest(IronChestType type)
|
||||
{
|
||||
super();
|
||||
this.type = type;
|
||||
this.chestContents = new ItemStack[this.getSizeInventory()];
|
||||
this.chestContents = new ItemStack[type.size];
|
||||
this.topStacks = new ItemStack[8];
|
||||
}
|
||||
|
||||
public ItemStack[] getContents()
|
||||
{
|
||||
return this.chestContents;
|
||||
this.facing = EnumFacing.NORTH;
|
||||
}
|
||||
|
||||
public void setContents(ItemStack[] contents)
|
||||
{
|
||||
this.chestContents = new ItemStack[this.getSizeInventory()];
|
||||
this.chestContents = new ItemStack[this.getType().size];
|
||||
for (int i = 0; i < contents.length; i++)
|
||||
{
|
||||
if (i < this.chestContents.length)
|
||||
|
@ -82,17 +76,17 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.type.size;
|
||||
return this.chestContents.length;
|
||||
}
|
||||
|
||||
public int getFacing()
|
||||
public EnumFacing getFacing()
|
||||
{
|
||||
return this.facing;
|
||||
}
|
||||
|
||||
public IronChestType getType()
|
||||
{
|
||||
return this.type;
|
||||
return this.hasWorldObj() ? this.worldObj.getBlockState(this.pos).getValue(BlockIronChest.VARIANT_PROP) : IronChestType.WOOD;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,7 +105,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
|
||||
protected void sortTopStacks()
|
||||
{
|
||||
if (!this.type.isTransparent() || (this.worldObj != null && this.worldObj.isRemote))
|
||||
if (!this.getType().isTransparent() || (this.worldObj != null && this.worldObj.isRemote))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -230,7 +224,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return this.hasCustomName() ? this.customName : this.type.name();
|
||||
return this.hasCustomName() ? this.customName : this.getType().name();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -266,7 +260,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
this.chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
this.facing = nbttagcompound.getByte("facing");
|
||||
this.facing = EnumFacing.VALUES[nbttagcompound.getByte("facing")];
|
||||
this.sortTopStacks();
|
||||
}
|
||||
|
||||
|
@ -287,7 +281,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
}
|
||||
|
||||
nbttagcompound.setTag("Items", nbttaglist);
|
||||
nbttagcompound.setByte("facing", this.facing);
|
||||
nbttagcompound.setByte("facing", (byte) this.facing.ordinal());
|
||||
|
||||
if (this.hasCustomName())
|
||||
{
|
||||
|
@ -339,7 +333,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
|
||||
if (this.worldObj != null && !this.worldObj.isRemote && this.ticksSinceSync < 0)
|
||||
{
|
||||
this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 3, ((this.numUsingPlayers << 3) & 0xF8) | (this.facing & 0x7));
|
||||
this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 3, ((this.numUsingPlayers << 3) & 0xF8) | (this.facing.ordinal() & 0x7));
|
||||
}
|
||||
if (!this.worldObj.isRemote && this.inventoryTouched)
|
||||
{
|
||||
|
@ -355,7 +349,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
double d = this.pos.getX() + 0.5D;
|
||||
double d1 = this.pos.getZ() + 0.5D;
|
||||
//@formatter:off
|
||||
this.worldObj.playSound((EntityPlayer) null, d, this.pos.getY() + 0.5D, d1, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
|
||||
this.worldObj.playSound(null, d, this.pos.getY() + 0.5D, d1, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
|
||||
//@formatter:on
|
||||
}
|
||||
if (this.numUsingPlayers == 0 && this.lidAngle > 0.0F || this.numUsingPlayers > 0 && this.lidAngle < 1.0F)
|
||||
|
@ -379,7 +373,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
double d2 = this.pos.getX() + 0.5D;
|
||||
double d3 = this.pos.getZ() + 0.5D;
|
||||
//@formatter:off
|
||||
this.worldObj.playSound((EntityPlayer) null, d2, this.pos.getY() + 0.5D, d3, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
|
||||
this.worldObj.playSound(null, d2, this.pos.getY() + 0.5D, d3, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
|
||||
//@formatter:on
|
||||
}
|
||||
if (this.lidAngle < 0.0F)
|
||||
|
@ -398,11 +392,11 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
}
|
||||
else if (i == 2)
|
||||
{
|
||||
this.facing = (byte) j;
|
||||
this.facing = EnumFacing.VALUES[j];
|
||||
}
|
||||
else if (i == 3)
|
||||
{
|
||||
this.facing = (byte) (j & 0x7);
|
||||
this.facing = EnumFacing.VALUES[j & 0x7];
|
||||
this.numUsingPlayers = (j & 0xF8) >> 3;
|
||||
}
|
||||
return true;
|
||||
|
@ -430,7 +424,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 1, this.numUsingPlayers);
|
||||
}
|
||||
|
||||
public void setFacing(byte facing2)
|
||||
public void setFacing(EnumFacing facing2)
|
||||
{
|
||||
this.facing = facing2;
|
||||
}
|
||||
|
@ -440,26 +434,12 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
return this.topStacks;
|
||||
}
|
||||
|
||||
public TileEntityIronChest updateFromMetadata(int l)
|
||||
{
|
||||
if (this.worldObj != null && this.worldObj.isRemote)
|
||||
{
|
||||
if (l != this.type.ordinal())
|
||||
{
|
||||
this.worldObj.setTileEntity(this.pos, IronChestType.makeEntity(l));
|
||||
return (TileEntityIronChest) this.worldObj.getTileEntity(this.pos);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet<?> getDescriptionPacket()
|
||||
{
|
||||
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setInteger("type", this.getType().ordinal());
|
||||
nbt.setByte("facing", this.facing);
|
||||
nbt.setByte("facing", (byte) this.facing.ordinal());
|
||||
ItemStack[] stacks = this.buildItemStackDataList();
|
||||
if (stacks != null)
|
||||
{
|
||||
|
@ -486,8 +466,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
if (pkt.getTileEntityType() == 0)
|
||||
{
|
||||
NBTTagCompound nbt = pkt.getNbtCompound();
|
||||
this.type = IronChestType.values()[nbt.getInteger("type")];
|
||||
this.facing = nbt.getByte("facing");
|
||||
this.facing = EnumFacing.VALUES[nbt.getByte("facing")];
|
||||
|
||||
NBTTagList tagList = nbt.getTagList("stacks", Constants.NBT.TAG_COMPOUND);
|
||||
ItemStack[] stacks = new ItemStack[this.topStacks.length];
|
||||
|
@ -502,7 +481,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
}
|
||||
}
|
||||
|
||||
if (this.type.isTransparent() && stacks != null)
|
||||
if (this.getType().isTransparent() && stacks != null)
|
||||
{
|
||||
int pos = 0;
|
||||
for (int i = 0; i < this.topStacks.length; i++)
|
||||
|
@ -523,7 +502,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
|
||||
public ItemStack[] buildItemStackDataList()
|
||||
{
|
||||
if (this.type.isTransparent())
|
||||
if (this.getType().isTransparent())
|
||||
{
|
||||
ItemStack[] sortList = new ItemStack[this.topStacks.length];
|
||||
int pos = 0;
|
||||
|
@ -561,18 +540,13 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return this.type.acceptsStack(itemstack);
|
||||
return this.getType().acceptsStack(itemstack);
|
||||
}
|
||||
|
||||
public void rotateAround()
|
||||
{
|
||||
this.facing++;
|
||||
if (this.facing > EnumFacing.EAST.ordinal())
|
||||
{
|
||||
this.facing = (byte) EnumFacing.NORTH.ordinal();
|
||||
}
|
||||
this.setFacing(this.facing);
|
||||
this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 2, this.facing);
|
||||
this.setFacing(this.facing.rotateY());
|
||||
this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 2, this.facing.ordinal());
|
||||
}
|
||||
|
||||
public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack)
|
||||
|
@ -618,7 +592,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
|
|||
@Override
|
||||
public String getGuiID()
|
||||
{
|
||||
return "IronChest:" + this.type.name();
|
||||
return "IronChest:" + this.getType().name();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw. All rights reserved. This program and the accompanying materials are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors: cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public class Version
|
||||
{
|
||||
private static String major;
|
||||
private static String minor;
|
||||
private static String rev;
|
||||
private static String build;
|
||||
@SuppressWarnings("unused")
|
||||
private static String mcversion;
|
||||
|
||||
static void init(Properties properties)
|
||||
{
|
||||
if (properties != null)
|
||||
{
|
||||
major = properties.getProperty("IronChest.build.major.number");
|
||||
minor = properties.getProperty("IronChest.build.minor.number");
|
||||
rev = properties.getProperty("IronChest.build.revision.number");
|
||||
build = properties.getProperty("IronChest.build.number");
|
||||
mcversion = properties.getProperty("IronChest.build.mcversion");
|
||||
}
|
||||
}
|
||||
|
||||
public static String fullVersionString()
|
||||
{
|
||||
return String.format("%s.%s.%s build %s", major, minor, rev, build);
|
||||
}
|
||||
}
|
|
@ -4,19 +4,17 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest.client;
|
||||
|
||||
import cpw.mods.ironchest.ChestChangerType;
|
||||
import cpw.mods.ironchest.CommonProxy;
|
||||
import cpw.mods.ironchest.IronChest;
|
||||
import cpw.mods.ironchest.IronChestType;
|
||||
import cpw.mods.ironchest.TileEntityIronChest;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ItemModelMesher;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
|
@ -24,40 +22,41 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ClientProxy extends CommonProxy
|
||||
{
|
||||
@Override
|
||||
public void registerRenderInformation()
|
||||
{
|
||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getBlockModelShapes().registerBuiltInBlocks(IronChest.ironChestBlock);
|
||||
Item chestItem = Item.getItemFromBlock(IronChest.ironChestBlock);
|
||||
|
||||
ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
|
||||
for (IronChestType chestType : IronChestType.values())
|
||||
for (IronChestType type : IronChestType.values())
|
||||
{
|
||||
if (chestType != IronChestType.WOOD)
|
||||
if (type != IronChestType.WOOD)
|
||||
{
|
||||
Item chestItem = Item.getItemFromBlock(IronChest.ironChestBlock);
|
||||
mesher.register(chestItem, chestType.ordinal(), new ModelResourceLocation("ironchest:chest_" + chestType.getName().toLowerCase(), "inventory"));
|
||||
ModelBakery.registerItemVariants(chestItem, new ResourceLocation("ironchest:chest_" + chestType.getName().toLowerCase()));
|
||||
ModelLoader.setCustomModelResourceLocation(chestItem, type.ordinal(),
|
||||
new ModelResourceLocation(new ResourceLocation(IronChest.MOD_ID, "chest_" + type.getName()), "inventory"));
|
||||
}
|
||||
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(type.clazz, new TileEntityIronChestRenderer());
|
||||
}
|
||||
|
||||
for (ChestChangerType type : ChestChangerType.VALUES)
|
||||
{
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
|
||||
{
|
||||
ModelLoader.setCustomModelResourceLocation(type.item, 0,
|
||||
new ModelResourceLocation(new ResourceLocation(IronChest.MOD_ID, type.itemName), "inventory"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends TileEntityIronChest> void registerTileEntitySpecialRenderer(Class<T> type)
|
||||
{
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(type, new TileEntityIronChestRenderer<T>(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getClientWorld()
|
||||
{
|
||||
return FMLClientHandler.instance().getClient().theWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
||||
{
|
||||
|
|
|
@ -4,18 +4,17 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest.client;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.ironchest.ContainerIronChest;
|
||||
import cpw.mods.ironchest.IronChestType;
|
||||
import cpw.mods.ironchest.TileEntityIronChest;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
@ -24,15 +23,17 @@ public class GUIChest extends GuiContainer
|
|||
{
|
||||
public enum ResourceList
|
||||
{
|
||||
IRON(new ResourceLocation("ironchest", "textures/gui/ironcontainer.png")), COPPER(
|
||||
new ResourceLocation("ironchest", "textures/gui/coppercontainer.png")), SILVER(
|
||||
new ResourceLocation("ironchest", "textures/gui/silvercontainer.png")), GOLD(
|
||||
new ResourceLocation("ironchest", "textures/gui/goldcontainer.png")), DIAMOND(
|
||||
new ResourceLocation("ironchest", "textures/gui/diamondcontainer.png")), DIRT(
|
||||
new ResourceLocation("ironchest", "textures/gui/dirtcontainer.png"));
|
||||
//@formatter:off
|
||||
IRON(new ResourceLocation("ironchest", "textures/gui/ironcontainer.png")),
|
||||
COPPER(new ResourceLocation("ironchest", "textures/gui/coppercontainer.png")),
|
||||
SILVER(new ResourceLocation("ironchest", "textures/gui/silvercontainer.png")),
|
||||
GOLD(new ResourceLocation("ironchest", "textures/gui/goldcontainer.png")),
|
||||
DIAMOND(new ResourceLocation("ironchest", "textures/gui/diamondcontainer.png")),
|
||||
DIRT(new ResourceLocation("ironchest", "textures/gui/dirtcontainer.png"));
|
||||
//@formatter:on
|
||||
public final ResourceLocation location;
|
||||
|
||||
private ResourceList(ResourceLocation loc)
|
||||
ResourceList(ResourceLocation loc)
|
||||
{
|
||||
this.location = loc;
|
||||
}
|
||||
|
@ -40,23 +41,28 @@ public class GUIChest extends GuiContainer
|
|||
|
||||
public enum GUI
|
||||
{
|
||||
IRON(184, 202, ResourceList.IRON, IronChestType.IRON), GOLD(184, 256, ResourceList.GOLD, IronChestType.GOLD), DIAMOND(238, 256, ResourceList.DIAMOND,
|
||||
IronChestType.DIAMOND), COPPER(184, 184, ResourceList.COPPER, IronChestType.COPPER), SILVER(184, 238, ResourceList.SILVER,
|
||||
IronChestType.SILVER), CRYSTAL(238, 256, ResourceList.DIAMOND, IronChestType.CRYSTAL), OBSIDIAN(238, 256, ResourceList.DIAMOND,
|
||||
IronChestType.OBSIDIAN), DIRTCHEST9000(184, 184, ResourceList.DIRT, IronChestType.DIRTCHEST9000);
|
||||
//@formatter:off
|
||||
IRON(184, 202, ResourceList.IRON, IronChestType.IRON),
|
||||
GOLD(184, 256, ResourceList.GOLD, IronChestType.GOLD),
|
||||
DIAMOND(238, 256, ResourceList.DIAMOND, IronChestType.DIAMOND),
|
||||
COPPER(184, 184, ResourceList.COPPER, IronChestType.COPPER),
|
||||
SILVER(184, 238, ResourceList.SILVER, IronChestType.SILVER),
|
||||
CRYSTAL(238, 256, ResourceList.DIAMOND, IronChestType.CRYSTAL),
|
||||
OBSIDIAN(238, 256, ResourceList.DIAMOND,IronChestType.OBSIDIAN),
|
||||
DIRTCHEST9000(184, 184, ResourceList.DIRT, IronChestType.DIRTCHEST9000);
|
||||
//@formatter:on
|
||||
|
||||
private int xSize;
|
||||
private int ySize;
|
||||
private ResourceList guiResourceList;
|
||||
private IronChestType mainType;
|
||||
|
||||
private GUI(int xSize, int ySize, ResourceList guiResourceList, IronChestType mainType)
|
||||
GUI(int xSize, int ySize, ResourceList guiResourceList, IronChestType mainType)
|
||||
{
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.guiResourceList = guiResourceList;
|
||||
this.mainType = mainType;
|
||||
|
||||
}
|
||||
|
||||
protected Container makeContainer(IInventory player, IInventory chest)
|
||||
|
@ -70,11 +76,6 @@ public class GUIChest extends GuiContainer
|
|||
}
|
||||
}
|
||||
|
||||
public int getRowLength()
|
||||
{
|
||||
return this.type.mainType.getRowLength();
|
||||
}
|
||||
|
||||
private GUI type;
|
||||
|
||||
private GUIChest(GUI type, IInventory player, IInventory chest)
|
||||
|
@ -89,7 +90,7 @@ public class GUIChest extends GuiContainer
|
|||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
|
||||
{
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
// new "bind tex"
|
||||
this.mc.getTextureManager().bindTexture(this.type.guiResourceList.location);
|
||||
int x = (this.width - this.xSize) / 2;
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package cpw.mods.ironchest.client;
|
||||
|
||||
import cpw.mods.ironchest.IronChestType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class IronChestEventHandler
|
||||
{
|
||||
|
@ -17,12 +18,10 @@ public class IronChestEventHandler
|
|||
{
|
||||
if (event.getMap() == FMLClientHandler.instance().getClient().getTextureMapBlocks())
|
||||
{
|
||||
event.getMap().registerSprite(new ResourceLocation("ironchest:blocks/copperbreak"));
|
||||
event.getMap().registerSprite(new ResourceLocation("ironchest:blocks/crystalbreak"));
|
||||
event.getMap().registerSprite(new ResourceLocation("ironchest:blocks/diamondbreak"));
|
||||
event.getMap().registerSprite(new ResourceLocation("ironchest:blocks/goldbreak"));
|
||||
event.getMap().registerSprite(new ResourceLocation("ironchest:blocks/ironbreak"));
|
||||
event.getMap().registerSprite(new ResourceLocation("ironchest:blocks/silverbreak"));
|
||||
for (IronChestType t : IronChestType.VALUES)
|
||||
{
|
||||
event.getMap().registerSprite(new ResourceLocation(t.getBreakTexture()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package cpw.mods.ironchest.client;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
|
||||
import cpw.mods.ironchest.BlockIronChest;
|
||||
import cpw.mods.ironchest.IronChestType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -15,37 +12,19 @@ import net.minecraft.client.renderer.block.model.ModelManager;
|
|||
import net.minecraft.util.EnumBlockRenderType;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class IronChestTextureHandler
|
||||
{
|
||||
private static Map<IronChestType, ResourceLocation> locations;
|
||||
|
||||
static
|
||||
{
|
||||
Builder<IronChestType, ResourceLocation> builder = ImmutableMap.<IronChestType, ResourceLocation> builder();
|
||||
for (IronChestType typ : IronChestType.values())
|
||||
{
|
||||
if (typ != IronChestType.DIRTCHEST9000 && typ != IronChestType.OBSIDIAN)
|
||||
builder.put(typ, new ResourceLocation("ironchest", "blocks/" + typ.getModelTexture().replace("chest", "break").replace(".png", "")));
|
||||
else if (typ == IronChestType.DIRTCHEST9000)
|
||||
builder.put(typ, new ResourceLocation("minecraft", "blocks/dirt"));
|
||||
else if (typ == IronChestType.OBSIDIAN)
|
||||
builder.put(typ, new ResourceLocation("minecraft", "blocks/obsidian"));
|
||||
}
|
||||
locations = builder.build();
|
||||
}
|
||||
|
||||
public static void addHitEffects(World world, BlockPos pos, EnumFacing side)
|
||||
{
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
state = block.getActualState(state, world, pos);
|
||||
Random rand = new Random();
|
||||
IronChestType type = IronChestType.values()[IronChestType.validateMeta(block.getMetaFromState(state))];
|
||||
IronChestType type = state.getValue(BlockIronChest.VARIANT_PROP);
|
||||
ModelManager modelmanager = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager();
|
||||
|
||||
if (block.getRenderType(state) != EnumBlockRenderType.INVISIBLE)
|
||||
|
@ -96,13 +75,7 @@ public class IronChestTextureHandler
|
|||
fx.setBlockPos(pos);
|
||||
fx.multiplyVelocity(0.2F);
|
||||
fx.multipleParticleScaleBy(0.6F);
|
||||
|
||||
if (type != IronChestType.DIRTCHEST9000 && type != IronChestType.OBSIDIAN)
|
||||
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite("ironchest:" + locations.get(type).getResourcePath()));
|
||||
else if (type == IronChestType.DIRTCHEST9000)
|
||||
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite("minecraft:" + locations.get(type).getResourcePath()));
|
||||
else if (type == IronChestType.OBSIDIAN)
|
||||
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite("minecraft:" + locations.get(type).getResourcePath()));
|
||||
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite(type.getBreakTexture()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,7 +83,7 @@ public class IronChestTextureHandler
|
|||
{
|
||||
state = state.getBlock().getActualState(state, world, pos);
|
||||
int i = 4;
|
||||
IronChestType type = IronChestType.values()[IronChestType.validateMeta(state.getBlock().getMetaFromState(state))];
|
||||
IronChestType type = state.getValue(BlockIronChest.VARIANT_PROP);
|
||||
ModelManager modelmanager = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager();
|
||||
|
||||
for (int j = 0; j < i; ++j)
|
||||
|
@ -126,12 +99,7 @@ public class IronChestTextureHandler
|
|||
EnumParticleTypes.BLOCK_CRACK.getParticleID(), d0, d1, d2, d0 - pos.getX() - 0.5D, d1 - pos.getY() - 0.5D, d2 - pos.getZ() - 0.5D,
|
||||
Block.getIdFromBlock(state.getBlock())));
|
||||
fx.setBlockPos(pos);
|
||||
if (type != IronChestType.DIRTCHEST9000 && type != IronChestType.OBSIDIAN)
|
||||
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite("ironchest:" + locations.get(type).getResourcePath()));
|
||||
else if (type == IronChestType.DIRTCHEST9000)
|
||||
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite("minecraft:" + locations.get(type).getResourcePath()));
|
||||
else if (type == IronChestType.OBSIDIAN)
|
||||
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite("minecraft:" + locations.get(type).getResourcePath()));
|
||||
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite(type.getBreakTexture()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest.client;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ItemModelMesher;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ModelHelper
|
||||
{
|
||||
public static void registerItem(Item item, int metadata, String itemName)
|
||||
{
|
||||
ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
|
||||
mesher.register(item, metadata, new ModelResourceLocation(itemName, "inventory"));
|
||||
}
|
||||
|
||||
public static void registerBlock(Block block, int metadata, String blockName)
|
||||
{
|
||||
registerItem(Item.getItemFromBlock(block), metadata, blockName);
|
||||
}
|
||||
|
||||
public static void registerBlock(Block block, String blockName)
|
||||
{
|
||||
registerBlock(block, 0, blockName);
|
||||
}
|
||||
|
||||
public static void registerItem(Item item, String itemName)
|
||||
{
|
||||
registerItem(item, 0, itemName);
|
||||
}
|
||||
}
|
|
@ -4,17 +4,14 @@
|
|||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest.client;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.primitives.SignedBytes;
|
||||
|
||||
import cpw.mods.ironchest.BlockIronChest;
|
||||
|
@ -29,67 +26,39 @@ import net.minecraft.client.renderer.entity.RenderEntityItem;
|
|||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends TileEntitySpecialRenderer<T>
|
||||
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer<TileEntityIronChest>
|
||||
{
|
||||
private static Map<IronChestType, ResourceLocation> locations;
|
||||
|
||||
static
|
||||
{
|
||||
Builder<IronChestType, ResourceLocation> builder = ImmutableMap.<IronChestType, ResourceLocation> builder();
|
||||
for (IronChestType typ : IronChestType.values())
|
||||
{
|
||||
builder.put(typ, new ResourceLocation("ironchest", "textures/model/" + typ.getModelTexture()));
|
||||
}
|
||||
locations = builder.build();
|
||||
}
|
||||
|
||||
private Random random;
|
||||
private RenderEntityItem itemRenderer;
|
||||
private ModelChest model;
|
||||
|
||||
private static float[][] shifts = { { 0.3F, 0.45F, 0.3F }, { 0.7F, 0.45F, 0.3F }, { 0.3F, 0.45F, 0.7F }, { 0.7F, 0.45F, 0.7F }, { 0.3F, 0.1F, 0.3F },
|
||||
{ 0.7F, 0.1F, 0.3F }, { 0.3F, 0.1F, 0.7F }, { 0.7F, 0.1F, 0.7F }, { 0.5F, 0.32F, 0.5F }, };
|
||||
private static EntityItem customitem = new EntityItem(null);
|
||||
private static float halfPI = (float) (Math.PI / 2D);
|
||||
|
||||
public TileEntityIronChestRenderer(Class<T> type)
|
||||
public TileEntityIronChestRenderer()
|
||||
{
|
||||
this.model = new ModelChest();
|
||||
this.random = new Random();
|
||||
this.itemRenderer = new RenderEntityItem(Minecraft.getMinecraft().getRenderManager(), Minecraft.getMinecraft().getRenderItem()) {
|
||||
@Override
|
||||
public int getModelCount(ItemStack stack)
|
||||
{
|
||||
return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 15) + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBob()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSpreadItems()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick, int breakStage)
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntityIronChest tile, double x, double y, double z, float partialTick, int breakStage)
|
||||
{
|
||||
if (tile == null)
|
||||
if (tile == null || tile.isInvalid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
int facing = 3;
|
||||
|
||||
EnumFacing facing = EnumFacing.SOUTH;
|
||||
IronChestType type = tile.getType();
|
||||
|
||||
if (tile != null && tile.hasWorldObj() && tile.getWorld().getBlockState(tile.getPos()).getBlock() == IronChest.ironChestBlock)
|
||||
if (tile.hasWorldObj() && tile.getWorld().getBlockState(tile.getPos()).getBlock() == IronChest.ironChestBlock)
|
||||
{
|
||||
facing = tile.getFacing();
|
||||
type = tile.getType();
|
||||
IBlockState state = tile.getWorld().getBlockState(tile.getPos());
|
||||
type = state.getValue(BlockIronChest.VARIANT_PROP);
|
||||
}
|
||||
|
@ -99,46 +68,59 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
|
|||
this.bindTexture(DESTROY_STAGES[breakStage]);
|
||||
GlStateManager.matrixMode(5890);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(4.0F, 4.0F, 1.0F);
|
||||
GlStateManager.scale(4F, 4F, 1F);
|
||||
GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
|
||||
GlStateManager.matrixMode(5888);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bindTexture(locations.get(type));
|
||||
this.bindTexture(type.modelTexture);
|
||||
}
|
||||
GlStateManager.pushMatrix();
|
||||
if (type == IronChestType.CRYSTAL)
|
||||
{
|
||||
GlStateManager.disableCull();
|
||||
}
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.translate((float) x, (float) y + 1.0F, (float) z + 1.0F);
|
||||
GlStateManager.scale(1.0F, -1F, -1F);
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
GlStateManager.translate((float) x, (float) y + 1F, (float) z + 1F);
|
||||
GlStateManager.scale(1F, -1F, -1F);
|
||||
GlStateManager.translate(0.5F, 0.5F, 0.5F);
|
||||
int k = 0;
|
||||
if (facing == 2)
|
||||
|
||||
switch (facing)
|
||||
{
|
||||
k = 180;
|
||||
}
|
||||
if (facing == 3)
|
||||
case NORTH:
|
||||
{
|
||||
k = 0;
|
||||
GlStateManager.rotate(180F, 0F, 1F, 0F);
|
||||
break;
|
||||
}
|
||||
if (facing == 4)
|
||||
case SOUTH:
|
||||
{
|
||||
k = 90;
|
||||
GlStateManager.rotate(0F, 0F, 1F, 0F);
|
||||
break;
|
||||
}
|
||||
if (facing == 5)
|
||||
case WEST:
|
||||
{
|
||||
k = -90;
|
||||
GlStateManager.rotate(90F, 0F, 1F, 0F);
|
||||
break;
|
||||
}
|
||||
GlStateManager.rotate(k, 0.0F, 1.0F, 0.0F);
|
||||
case EAST:
|
||||
{
|
||||
GlStateManager.rotate(270F, 0F, 1F, 0F);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GlStateManager.translate(-0.5F, -0.5F, -0.5F);
|
||||
float lidangle = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * partialTick;
|
||||
lidangle = 1.0F - lidangle;
|
||||
lidangle = 1.0F - lidangle * lidangle * lidangle;
|
||||
this.model.chestLid.rotateAngleX = -((lidangle * 3.141593F) / 2.0F);
|
||||
lidangle = 1F - lidangle;
|
||||
lidangle = 1F - lidangle * lidangle * lidangle;
|
||||
|
||||
if (type.isTransparent())
|
||||
{
|
||||
GlStateManager.scale(1F, 0.99F, 1F);
|
||||
}
|
||||
|
||||
this.model.chestLid.rotateAngleX = -lidangle * halfPI;
|
||||
// Render the chest itself
|
||||
this.model.renderAll();
|
||||
if (breakStage >= 0)
|
||||
|
@ -152,7 +134,7 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
|
|||
GlStateManager.enableCull();
|
||||
}
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
|
||||
if (type.isTransparent()
|
||||
&& tile.getDistanceSq(this.rendererDispatcher.entityX, this.rendererDispatcher.entityY, this.rendererDispatcher.entityZ) < 128d)
|
||||
|
@ -163,7 +145,7 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
|
|||
float shiftZ;
|
||||
int shift = 0;
|
||||
float blockScale = 0.70F;
|
||||
float timeD = (float) (360.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL);
|
||||
float timeD = (float) (360D * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL);
|
||||
if (tile.getTopItemStacks()[1] == null)
|
||||
{
|
||||
shift = 8;
|
||||
|
@ -171,8 +153,9 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
|
|||
}
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate((float) x, (float) y, (float) z);
|
||||
EntityItem customitem = new EntityItem(this.getWorld());
|
||||
customitem.hoverStart = 0f;
|
||||
|
||||
customitem.setWorld(this.getWorld());
|
||||
customitem.hoverStart = 0F;
|
||||
for (ItemStack item : tile.getTopItemStacks())
|
||||
{
|
||||
if (shift > shifts.length)
|
||||
|
@ -190,19 +173,39 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
|
|||
shift++;
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(shiftX, shiftY, shiftZ);
|
||||
GlStateManager.rotate(timeD, 0.0F, 1.0F, 0.0F);
|
||||
GlStateManager.rotate(timeD, 0F, 1F, 0F);
|
||||
GlStateManager.scale(blockScale, blockScale, blockScale);
|
||||
customitem.setEntityItemStack(item);
|
||||
this.itemRenderer.doRender(customitem, 0, 0, 0, 0, 0);
|
||||
|
||||
if (this.itemRenderer == null)
|
||||
{
|
||||
this.itemRenderer = new RenderEntityItem(Minecraft.getMinecraft().getRenderManager(), Minecraft.getMinecraft().getRenderItem()) {
|
||||
@Override
|
||||
public int getModelCount(ItemStack stack)
|
||||
{
|
||||
return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 15) + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBob()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSpreadItems()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.itemRenderer.doRender(customitem, 0D, 0D, 0D, 0F, partialTick);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntityIronChest tileentity, double x, double y, double z, float partialTick, int breakStage)
|
||||
{
|
||||
this.render(tileentity, x, y, z, partialTick, breakStage);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue