Absolutely barbaric rewrite

This commit is contained in:
LatvianModder 2016-05-19 02:47:25 +03:00
parent d0b721e332
commit 8fcccc40ee
23 changed files with 383 additions and 585 deletions

View File

@ -4,25 +4,22 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest; package cpw.mods.ironchest;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import com.google.common.collect.Lists;
import cpw.mods.ironchest.client.IronChestTextureHandler; 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.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
@ -37,9 +34,9 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.Explosion; import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess; 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.Side;
import net.minecraftforge.fml.relauncher.SideOnly; 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); 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); 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() public BlockIronChest()
{ {
super(Material.IRON); super(Material.IRON);
this.setRegistryName(new ResourceLocation(IronChest.MOD_ID, "BlockIronChest"));
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, IronChestType.IRON)); this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, IronChestType.IRON));
@ -114,16 +112,22 @@ public class BlockIronChest extends BlockContainer
} }
@Override @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 @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
{ {
for (IronChestType type : IronChestType.values()) for (IronChestType type : IronChestType.VALUES)
{ {
if (type.isValidForCreativeMode()) if (type.isValidForCreativeMode())
{ {
@ -135,7 +139,7 @@ public class BlockIronChest extends BlockContainer
@Override @Override
public IBlockState getStateFromMeta(int meta) public IBlockState getStateFromMeta(int meta)
{ {
return this.getDefaultState().withProperty(VARIANT_PROP, IronChestType.values()[meta]); return this.getDefaultState().withProperty(VARIANT_PROP, IronChestType.VALUES[meta]);
} }
@Override @Override
@ -147,17 +151,7 @@ public class BlockIronChest extends BlockContainer
@Override @Override
protected BlockStateContainer createBlockState() protected BlockStateContainer createBlockState()
{ {
return new BlockStateContainer(this, new IProperty<?>[] { VARIANT_PROP }); return new BlockStateContainer(this, 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;
} }
@Override @Override
@ -170,30 +164,12 @@ public class BlockIronChest extends BlockContainer
@Override @Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState blockState, EntityLivingBase entityliving, ItemStack itemStack) 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); TileEntity te = world.getTileEntity(pos);
if (te != null && te instanceof TileEntityIronChest) if (te != null && te instanceof TileEntityIronChest)
{ {
TileEntityIronChest teic = (TileEntityIronChest) te; TileEntityIronChest teic = (TileEntityIronChest) te;
teic.wasPlaced(entityliving, itemStack); teic.wasPlaced(entityliving, itemStack);
teic.setFacing(chestFacing); teic.setFacing(entityliving.getHorizontalFacing().getOpposite());
world.notifyBlockUpdate(pos, blockState, blockState, 3); world.notifyBlockUpdate(pos, blockState, blockState, 3);
} }
} }
@ -201,7 +177,7 @@ public class BlockIronChest extends BlockContainer
@Override @Override
public int damageDropped(IBlockState state) public int damageDropped(IBlockState state)
{ {
return IronChestType.validateMeta(state.getValue(VARIANT_PROP).ordinal()); return state.getValue(VARIANT_PROP).ordinal();
} }
@Override @Override
@ -268,9 +244,14 @@ public class BlockIronChest extends BlockContainer
return super.getExplosionResistance(world, pos, exploder, explosion); 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 @Override
@SideOnly(Side.CLIENT) @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); IronChestTextureHandler.addHitEffects(worldObj, target.getBlockPos(), target.sideHit);
return true; return true;
@ -278,7 +259,7 @@ public class BlockIronChest extends BlockContainer
@Override @Override
@SideOnly(Side.CLIENT) @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)); IronChestTextureHandler.addDestroyEffects(world, pos, world.getBlockState(pos));
return true; return true;
@ -328,4 +309,12 @@ public class BlockIronChest extends BlockContainer
} }
return false; 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);
}
} }

View File

@ -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 * 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 * which accompanies this distribution, and is available at http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: cpw - initial API and implementation * Contributors: cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest; 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.SILVER;
import static cpw.mods.ironchest.IronChestType.WOOD; import static cpw.mods.ironchest.IronChestType.WOOD;
import cpw.mods.ironchest.client.ModelHelper;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
public enum ChestChangerType public enum ChestChangerType
{ {
//@formatter:off //@formatter:off
IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "Iron to Gold Chest Upgrade", "mmm", "msm", "mmm"), IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "mmm", "msm", "mmm"),
GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade", "Gold to Diamond Chest Upgrade", "GGG", "msm", "GGG"), GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade", "GGG", "msm", "GGG"),
COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "Copper to Silver Chest Upgrade", "mmm", "msm", "mmm"), COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "mmm", "msm", "mmm"),
SILVERGOLD(SILVER, GOLD, "silverGoldUpgrade", "Silver to Gold Chest Upgrade", "mGm", "GsG", "mGm"), SILVERGOLD(SILVER, GOLD, "silverGoldUpgrade", "mGm", "GsG", "mGm"),
COPPERIRON(COPPER, IRON, "copperIronUpgrade", "Copper to Iron Chest Upgrade", "mGm", "GsG", "mGm"), COPPERIRON(COPPER, IRON, "copperIronUpgrade", "mGm", "GsG", "mGm"),
DIAMONDCRYSTAL(DIAMOND, CRYSTAL, "diamondCrystalUpgrade", "Diamond to Crystal Chest Upgrade", "GGG", "GOG", "GGG"), DIAMONDCRYSTAL(DIAMOND, CRYSTAL, "diamondCrystalUpgrade", "GGG", "GOG", "GGG"),
WOODIRON(WOOD, IRON, "woodIronUpgrade", "Normal chest to Iron Chest Upgrade", "mmm", "msm", "mmm"), WOODIRON(WOOD, IRON, "woodIronUpgrade", "mmm", "msm", "mmm"),
WOODCOPPER(WOOD, COPPER, "woodCopperUpgrade", "Normal chest to Copper Chest Upgrade", "mmm", "msm", "mmm"), WOODCOPPER(WOOD, COPPER, "woodCopperUpgrade", "mmm", "msm", "mmm"),
DIAMONDOBSIDIAN(DIAMOND, OBSIDIAN, "diamondObsidianUpgrade", "Diamond to Obsidian Chest Upgrade", "mmm", "mGm", "mmm"); DIAMONDOBSIDIAN(DIAMOND, OBSIDIAN, "diamondObsidianUpgrade", "mmm", "mGm", "mmm");
//@formatter:on //@formatter:on
public static final ChestChangerType[] VALUES = values();
private IronChestType source; private IronChestType source;
private IronChestType target; private IronChestType target;
public String itemName; public String itemName;
public String descriptiveName;
public ItemChestChanger item; public ItemChestChanger item;
private String[] recipe; 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.source = source;
this.target = target; this.target = target;
this.itemName = itemName; this.itemName = itemName;
this.descriptiveName = descriptiveName;
this.recipe = recipe; this.recipe = recipe;
} }
@ -62,31 +59,24 @@ public enum ChestChangerType
return from == this.source; return from == this.source;
} }
public int getTarget() public IronChestType getTarget()
{ {
return this.target.ordinal(); return this.target;
} }
public ItemChestChanger buildItem() public ItemChestChanger buildItem()
{ {
this.item = new ItemChestChanger(this); this.item = new ItemChestChanger(this);
this.item.setRegistryName(this.itemName); this.item.setRegistryName(this.itemName);
GameRegistry.register(this.item); GameRegistry.register(this.item);
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
{
ModelHelper.registerItem(this.item, "ironchest:" + this.itemName);
}
return this.item; return this.item;
} }
public void addRecipes() 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 targetMaterial = IronChestType.translateOreName(targetMat);
Object sourceMaterial = IronChestType.translateOreName(sourceMat); Object sourceMaterial = IronChestType.translateOreName(sourceMat);
@ -99,7 +89,7 @@ public enum ChestChangerType
public static void buildItems() public static void buildItems()
{ {
for (ChestChangerType type : values()) for (ChestChangerType type : VALUES)
{ {
type.buildItem(); type.buildItem();
} }
@ -107,7 +97,7 @@ public enum ChestChangerType
public static void generateRecipes() public static void generateRecipes()
{ {
for (ChestChangerType item : values()) for (ChestChangerType item : VALUES)
{ {
item.addRecipes(); item.addRecipes();
} }

View File

@ -4,7 +4,7 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
@ -20,12 +20,6 @@ public class CommonProxy implements IGuiHandler
{ {
public void registerRenderInformation() public void registerRenderInformation()
{ {
}
public <T extends TileEntityIronChest> void registerTileEntitySpecialRenderer(Class<T> typ)
{
} }
@Override @Override
@ -48,10 +42,4 @@ public class CommonProxy implements IGuiHandler
return null; return null;
} }
} }
public World getClientWorld()
{
return null;
}
} }

View File

@ -4,7 +4,7 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
@ -44,7 +44,7 @@ public class ContainerIronChest extends Container
public ItemStack transferStackInSlot(EntityPlayer p, int i) public ItemStack transferStackInSlot(EntityPlayer p, int i)
{ {
ItemStack itemstack = null; ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(i); Slot slot = this.inventorySlots.get(i);
if (slot != null && slot.getHasStack()) if (slot != null && slot.getHasStack())
{ {
ItemStack itemstack1 = slot.getStack(); ItemStack itemstack1 = slot.getStack();
@ -93,9 +93,9 @@ public class ContainerIronChest extends Container
{ {
for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++) 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 @ChestContainer.RowSizeCallback
public int getNumColumns() public int getNumColumns()
{ {
return this.type.getRowLength(); return this.type.rowLength;
} }
} }

View File

@ -4,66 +4,68 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest; package cpw.mods.ironchest;
import java.util.Properties;
import cpw.mods.ironchest.client.IronChestEventHandler; import cpw.mods.ironchest.client.IronChestEventHandler;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy; 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.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry; 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 class IronChest
{ {
public static BlockIronChest ironChestBlock; public static final String MOD_ID = "IronChest";
public static ItemIronChest ironChestItemBlock;
@Instance(IronChest.MOD_ID)
public static IronChest instance;
@SidedProxy(clientSide = "cpw.mods.ironchest.client.ClientProxy", serverSide = "cpw.mods.ironchest.CommonProxy") @SidedProxy(clientSide = "cpw.mods.ironchest.client.ClientProxy", serverSide = "cpw.mods.ironchest.CommonProxy")
public static CommonProxy proxy; public static CommonProxy proxy;
@Instance("IronChest")
public static IronChest instance; public static BlockIronChest ironChestBlock;
public static ItemIronChest ironChestItemBlock;
@EventHandler @EventHandler
public void preInit(FMLPreInitializationEvent event) public void preInit(FMLPreInitializationEvent event)
{ {
Version.init(event.getVersionProperties()); Properties properties = event.getVersionProperties();
event.getModMetadata().version = Version.fullVersionString();
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(); ChestChangerType.buildItems();
ironChestBlock = new BlockIronChest(); ironChestBlock = GameRegistry.register(new BlockIronChest());
ironChestItemBlock = new ItemIronChest(ironChestBlock); ironChestItemBlock = GameRegistry.register(new ItemIronChest(ironChestBlock));
ironChestBlock.setRegistryName("BlockIronChest");
ironChestItemBlock.setRegistryName("BlockIronChest");
GameRegistry.register(ironChestBlock);
GameRegistry.register(ironChestItemBlock); GameRegistry.register(ironChestItemBlock);
for (IronChestType typ : IronChestType.values()) for (IronChestType typ : IronChestType.VALUES)
{ {
GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest." + typ.name(), typ.name()); GameRegistry.registerTileEntity(typ.clazz, "IronChest." + typ.name());
proxy.registerTileEntitySpecialRenderer(typ.clazz);
} }
IronChestType.registerBlocksAndRecipes(ironChestBlock); IronChestType.registerBlocksAndRecipes(ironChestBlock);
ChestChangerType.generateRecipes(); ChestChangerType.generateRecipes();
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy); NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
proxy.registerRenderInformation(); proxy.registerRenderInformation();
MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler()); // FIXME: MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler());
MinecraftForge.EVENT_BUS.register(IronChestEventHandler.INSTANCE); MinecraftForge.EVENT_BUS.register(IronChestEventHandler.INSTANCE);
} }
} }

View File

@ -4,15 +4,15 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest; package cpw.mods.ironchest;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.Collection;
import java.util.Collections;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
@ -21,94 +21,77 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagByte; import net.minecraft.nbt.NBTTagByte;
import net.minecraft.util.IStringSerializable; import net.minecraft.util.IStringSerializable;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapedOreRecipe;
public enum IronChestType implements IStringSerializable public enum IronChestType implements IStringSerializable
{ {
//@formatter:off //@formatter:off
IRON(54, 9, true, "Iron Chest", "ironchest.png", 0, Arrays.asList("ingotIron", "ingotRefinedIron"), TileEntityIronChest.class, "mmmmPmmmm", "mGmG3GmGm"), IRON(54, 9, true, "ironchest.png", Arrays.asList("ingotIron", "ingotRefinedIron"), TileEntityIronChest.class, "mmmmPmmmm", "mGmG3GmGm"),
GOLD(81, 9, true, "Gold Chest", "goldchest.png", 1, Arrays.asList("ingotGold"), TileEntityGoldChest.class, "mmmmPmmmm", "mGmG4GmGm"), GOLD(81, 9, true, "goldchest.png", Collections.singleton("ingotGold"), TileEntityGoldChest.class, "mmmmPmmmm", "mGmG4GmGm"),
DIAMOND(108, 12, true, "Diamond Chest", "diamondchest.png", 2, Arrays.asList("gemDiamond"), TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"), DIAMOND(108, 12, true, "diamondchest.png", Collections.singleton("gemDiamond"), TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"),
COPPER(45, 9, false, "Copper Chest", "copperchest.png", 3, Arrays.asList("ingotCopper"), TileEntityCopperChest.class, "mmmmCmmmm"), COPPER(45, 9, false, "copperchest.png", Collections.singleton("ingotCopper"), TileEntityCopperChest.class, "mmmmCmmmm"),
SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, Arrays.asList("ingotSilver"), TileEntitySilverChest.class, "mmmm3mmmm", "mGmG0GmGm"), SILVER(72, 9, false, "silverchest.png", Collections.singleton("ingotSilver"), TileEntitySilverChest.class, "mmmm3mmmm", "mGmG0GmGm"),
CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"), CRYSTAL(108, 12, true, "crystalchest.png", Collections.singleton("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"),
OBSIDIAN(108, 12, false, "Obsidian Chest", "obsidianchest.png", 6, Arrays.asList("obsidian"), TileEntityObsidianChest.class, "mmmm2mmmm"), OBSIDIAN(108, 12, false, "obsidianchest.png", Collections.singleton("obsidian"), TileEntityObsidianChest.class, "mmmm2mmmm"),
DIRTCHEST9000(1, 1, false, "Dirt Chest 9000", "dirtchest.png", 7, Arrays.asList("dirt"), TileEntityDirtChest.class, Item.getItemFromBlock(Blocks.DIRT), "mmmmCmmmm"), DIRTCHEST9000(1, 1, false, "dirtchest.png", Collections.singleton("dirt"), TileEntityDirtChest.class, "mmmmCmmmm"),
WOOD(0, 0, false, "", "", -1, Arrays.asList("plankWood"), null); WOOD(0, 0, false, "", Collections.singleton("plankWood"), null);
//@formatter:on //@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, public static final IronChestType VALUES[] = values();
Class<? extends TileEntityIronChest> clazz, String... recipes)
{
this(size, rowLength, tieredChest, friendlyName, modelTexture, textureRow, mats, clazz, (Item) null, recipes);
}
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats, public final String name;
Class<? extends TileEntityIronChest> clazz, Item itemFilter, String... recipes) 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.size = size;
this.rowLength = rowLength; this.rowLength = rowLength;
this.tieredChest = tieredChest; this.tieredChest = tieredChest;
this.friendlyName = friendlyName; this.modelTexture = new ResourceLocation("ironchest", "textures/model/" + modelTexture);
this.modelTexture = modelTexture; this.matList = Collections.unmodifiableCollection(mats);
this.textureRow = textureRow;
this.clazz = clazz; this.clazz = clazz;
this.itemFilter = itemFilter; this.recipes = Collections.unmodifiableCollection(Arrays.asList(recipes));
this.recipes = recipes; }
this.matList = new ArrayList<String>();
this.matList.addAll(mats); 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 @Override
public String getName() public String getName()
{ {
return this.name().toLowerCase(); return this.name;
}
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;
} }
public static void registerBlocksAndRecipes(BlockIronChest blockResult) public static void registerBlocksAndRecipes(BlockIronChest blockResult)
@ -136,15 +119,12 @@ public enum IronChestType implements IStringSerializable
{ {
mainMaterial = translateOreName(mat); mainMaterial = translateOreName(mat);
//@formatter:off //@formatter:off
addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, 'm', mainMaterial, 'P', previousTier, /* previous tier of chest */
'm', mainMaterial, 'P', previousTier, /* previous tier of chest */ 'G', "blockGlass", 'C', "chestWood", '0', new ItemStack(blockResult, 1, 0), /* Iron Chest */
'G', "blockGlass", 'C', "chestWood",
'0', new ItemStack(blockResult, 1, 0), /* Iron Chest */
'1', new ItemStack(blockResult, 1, 1), /* Gold Chest */ '1', new ItemStack(blockResult, 1, 1), /* Gold Chest */
'2', new ItemStack(blockResult, 1, 2), /* Diamond Chest */ '2', new ItemStack(blockResult, 1, 2), /* Diamond Chest */
'3', new ItemStack(blockResult, 1, 3), /* Copper 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 //@formatter:on
} }
} }
@ -174,36 +154,14 @@ public enum IronChestType implements IStringSerializable
return this.size / this.rowLength; return this.size / this.rowLength;
} }
public int getRowLength()
{
return this.rowLength;
}
public boolean isTransparent() public boolean isTransparent()
{ {
return this == CRYSTAL; 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() public boolean isValidForCreativeMode()
{ {
return validateMeta(this.ordinal()) == this.ordinal(); return true;
} }
public boolean isExplosionResistant() public boolean isExplosionResistant()
@ -216,9 +174,16 @@ public enum IronChestType implements IStringSerializable
return new ValidatingSlot(chestInventory, index, x, y, this); return new ValidatingSlot(chestInventory, index, x, y, this);
} }
private static final Item DIRT_ITEM = Item.getItemFromBlock(Blocks.DIRT);
public boolean acceptsStack(ItemStack itemstack) 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) public void adornItemDrop(ItemStack item)
@ -228,4 +193,29 @@ public enum IronChestType implements IStringSerializable
item.setTagInfo("dirtchest", new NBTTagByte((byte) 1)); 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;
}
}
} }

View File

@ -4,7 +4,7 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
@ -26,12 +26,11 @@ import net.minecraft.world.World;
public class ItemChestChanger extends Item public class ItemChestChanger extends Item
{ {
private ChestChangerType type; public final ChestChangerType type;
public ItemChestChanger(ChestChangerType type) public ItemChestChanger(ChestChangerType type)
{ {
this.type = type; this.type = type;
this.setMaxStackSize(1); this.setMaxStackSize(1);
this.setUnlocalizedName("ironchest:" + type.name()); this.setUnlocalizedName("ironchest:" + type.name());
this.setCreativeTab(CreativeTabs.MISC); this.setCreativeTab(CreativeTabs.MISC);
@ -64,14 +63,14 @@ public class ItemChestChanger extends Item
TileEntity te = worldIn.getTileEntity(pos); TileEntity te = worldIn.getTileEntity(pos);
TileEntityIronChest newchest = new TileEntityIronChest(); TileEntityIronChest newchest = new TileEntityIronChest();
ItemStack[] chestContents = new ItemStack[27]; ItemStack[] chestContents = new ItemStack[27];
int chestFacing = 0; EnumFacing chestFacing = EnumFacing.DOWN;
if (te != null) if (te != null)
{ {
if (te instanceof TileEntityIronChest) if (te instanceof TileEntityIronChest)
{ {
chestContents = ((TileEntityIronChest) te).chestContents; chestContents = ((TileEntityIronChest) te).chestContents;
chestFacing = ((TileEntityIronChest) te).getFacing(); chestFacing = ((TileEntityIronChest) te).getFacing();
newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal())); newchest = this.type.getTarget().makeEntity();
if (newchest == null) if (newchest == null)
{ {
return EnumActionResult.PASS; return EnumActionResult.PASS;
@ -80,37 +79,23 @@ public class ItemChestChanger extends Item
else if (te instanceof TileEntityChest) else if (te instanceof TileEntityChest)
{ {
IBlockState chestState = worldIn.getBlockState(pos); IBlockState chestState = worldIn.getBlockState(pos);
EnumFacing orientation = chestState.getValue(BlockChest.FACING); chestFacing = chestState.getValue(BlockChest.FACING);
if (orientation == EnumFacing.NORTH) TileEntityChest chest = (TileEntityChest) te;
{
chestFacing = 2; if (chest.numPlayersUsing > 0)
}
if (orientation == EnumFacing.EAST)
{
chestFacing = 5;
}
if (orientation == EnumFacing.SOUTH)
{
chestFacing = 3;
}
if (orientation == EnumFacing.WEST)
{
chestFacing = 4;
}
if (((TileEntityChest) te).numPlayersUsing > 0)
{ {
return EnumActionResult.PASS; return EnumActionResult.PASS;
} }
if (!this.getType().canUpgrade(IronChestType.WOOD)) if (!this.type.canUpgrade(IronChestType.WOOD))
{ {
return EnumActionResult.PASS; return EnumActionResult.PASS;
} }
chestContents = new ItemStack[((TileEntityChest) te).getSizeInventory()]; chestContents = new ItemStack[chest.getSizeInventory()];
for (int i = 0; i < chestContents.length; i++) 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) if (te2 instanceof TileEntityIronChest)
{ {
((TileEntityIronChest) te2).setContents(chestContents); ((TileEntityIronChest) te2).setContents(chestContents);
((TileEntityIronChest) te2).setFacing((byte) chestFacing); ((TileEntityIronChest) te2).setFacing(chestFacing);
} }
stack.stackSize = playerIn.capabilities.isCreativeMode ? stack.stackSize : stack.stackSize - 1; stack.stackSize = playerIn.capabilities.isCreativeMode ? stack.stackSize : stack.stackSize - 1;
return EnumActionResult.SUCCESS; return EnumActionResult.SUCCESS;
} }
public int getTargetChestOrdinal(int sourceOrdinal)
{
return this.type.getTarget();
}
public ChestChangerType getType()
{
return this.type;
}
} }

View File

@ -4,7 +4,7 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
@ -13,12 +13,14 @@ package cpw.mods.ironchest;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
public class ItemIronChest extends ItemBlock public class ItemIronChest extends ItemBlock
{ {
public ItemIronChest(Block block) public ItemIronChest(Block block)
{ {
super(block); super(block);
this.setRegistryName(new ResourceLocation(IronChest.MOD_ID, "BlockIronChest"));
this.setMaxDamage(0); this.setMaxDamage(0);
this.setHasSubtypes(true); this.setHasSubtypes(true);
@ -27,12 +29,12 @@ public class ItemIronChest extends ItemBlock
@Override @Override
public int getMetadata(int meta) public int getMetadata(int meta)
{ {
return IronChestType.validateMeta(meta); return meta;
} }
@Override @Override
public String getUnlocalizedName(ItemStack itemstack) public String getUnlocalizedName(ItemStack itemstack)
{ {
return "tile.ironchest:" + IronChestType.values()[itemstack.getMetadata()].name(); return "tile.ironchest:" + IronChestType.VALUES[itemstack.getMetadata()].getName();
} }
} }

View File

@ -6,7 +6,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class OcelotsSitOnChestsHandler public class OcelotsSitOnChestsHandler
{ {
@SubscribeEvent @SubscribeEvent
public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt) public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt)
{ {

View File

@ -4,7 +4,7 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
@ -16,5 +16,4 @@ public class TileEntityCopperChest extends TileEntityIronChest
{ {
super(IronChestType.COPPER); super(IronChestType.COPPER);
} }
} }

View File

@ -4,7 +4,7 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/

View File

@ -4,7 +4,7 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/

View File

@ -4,7 +4,7 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/

View File

@ -4,7 +4,7 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
@ -40,10 +40,9 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
public float prevLidAngle; public float prevLidAngle;
public float lidAngle; public float lidAngle;
private int numUsingPlayers; private int numUsingPlayers;
private IronChestType type;
public ItemStack[] chestContents; public ItemStack[] chestContents;
private ItemStack[] topStacks; private ItemStack[] topStacks;
private byte facing; private EnumFacing facing;
private boolean inventoryTouched; private boolean inventoryTouched;
private boolean hadStuff; private boolean hadStuff;
private String customName; private String customName;
@ -56,19 +55,14 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
protected TileEntityIronChest(IronChestType type) protected TileEntityIronChest(IronChestType type)
{ {
super(); super();
this.type = type; this.chestContents = new ItemStack[type.size];
this.chestContents = new ItemStack[this.getSizeInventory()];
this.topStacks = new ItemStack[8]; this.topStacks = new ItemStack[8];
} this.facing = EnumFacing.NORTH;
public ItemStack[] getContents()
{
return this.chestContents;
} }
public void setContents(ItemStack[] contents) 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++) for (int i = 0; i < contents.length; i++)
{ {
if (i < this.chestContents.length) if (i < this.chestContents.length)
@ -82,17 +76,17 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
@Override @Override
public int getSizeInventory() public int getSizeInventory()
{ {
return this.type.size; return this.chestContents.length;
} }
public int getFacing() public EnumFacing getFacing()
{ {
return this.facing; return this.facing;
} }
public IronChestType getType() public IronChestType getType()
{ {
return this.type; return this.hasWorldObj() ? this.worldObj.getBlockState(this.pos).getValue(BlockIronChest.VARIANT_PROP) : IronChestType.WOOD;
} }
@Override @Override
@ -111,7 +105,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
protected void sortTopStacks() protected void sortTopStacks()
{ {
if (!this.type.isTransparent() || (this.worldObj != null && this.worldObj.isRemote)) if (!this.getType().isTransparent() || (this.worldObj != null && this.worldObj.isRemote))
{ {
return; return;
} }
@ -230,7 +224,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
@Override @Override
public String getName() public String getName()
{ {
return this.hasCustomName() ? this.customName : this.type.name(); return this.hasCustomName() ? this.customName : this.getType().name();
} }
@Override @Override
@ -266,7 +260,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
this.chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); this.chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
} }
} }
this.facing = nbttagcompound.getByte("facing"); this.facing = EnumFacing.VALUES[nbttagcompound.getByte("facing")];
this.sortTopStacks(); this.sortTopStacks();
} }
@ -287,7 +281,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
} }
nbttagcompound.setTag("Items", nbttaglist); nbttagcompound.setTag("Items", nbttaglist);
nbttagcompound.setByte("facing", this.facing); nbttagcompound.setByte("facing", (byte) this.facing.ordinal());
if (this.hasCustomName()) if (this.hasCustomName())
{ {
@ -339,7 +333,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
if (this.worldObj != null && !this.worldObj.isRemote && this.ticksSinceSync < 0) 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) 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 d = this.pos.getX() + 0.5D;
double d1 = this.pos.getZ() + 0.5D; double d1 = this.pos.getZ() + 0.5D;
//@formatter:off //@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 //@formatter:on
} }
if (this.numUsingPlayers == 0 && this.lidAngle > 0.0F || this.numUsingPlayers > 0 && this.lidAngle < 1.0F) 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 d2 = this.pos.getX() + 0.5D;
double d3 = this.pos.getZ() + 0.5D; double d3 = this.pos.getZ() + 0.5D;
//@formatter:off //@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 //@formatter:on
} }
if (this.lidAngle < 0.0F) if (this.lidAngle < 0.0F)
@ -398,11 +392,11 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
} }
else if (i == 2) else if (i == 2)
{ {
this.facing = (byte) j; this.facing = EnumFacing.VALUES[j];
} }
else if (i == 3) else if (i == 3)
{ {
this.facing = (byte) (j & 0x7); this.facing = EnumFacing.VALUES[j & 0x7];
this.numUsingPlayers = (j & 0xF8) >> 3; this.numUsingPlayers = (j & 0xF8) >> 3;
} }
return true; return true;
@ -430,7 +424,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 1, this.numUsingPlayers); this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 1, this.numUsingPlayers);
} }
public void setFacing(byte facing2) public void setFacing(EnumFacing facing2)
{ {
this.facing = facing2; this.facing = facing2;
} }
@ -440,26 +434,12 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
return this.topStacks; 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 @Override
public Packet<?> getDescriptionPacket() public Packet<?> getDescriptionPacket()
{ {
NBTTagCompound nbt = new NBTTagCompound(); NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("type", this.getType().ordinal()); nbt.setByte("facing", (byte) this.facing.ordinal());
nbt.setByte("facing", this.facing);
ItemStack[] stacks = this.buildItemStackDataList(); ItemStack[] stacks = this.buildItemStackDataList();
if (stacks != null) if (stacks != null)
{ {
@ -486,8 +466,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
if (pkt.getTileEntityType() == 0) if (pkt.getTileEntityType() == 0)
{ {
NBTTagCompound nbt = pkt.getNbtCompound(); NBTTagCompound nbt = pkt.getNbtCompound();
this.type = IronChestType.values()[nbt.getInteger("type")]; this.facing = EnumFacing.VALUES[nbt.getByte("facing")];
this.facing = nbt.getByte("facing");
NBTTagList tagList = nbt.getTagList("stacks", Constants.NBT.TAG_COMPOUND); NBTTagList tagList = nbt.getTagList("stacks", Constants.NBT.TAG_COMPOUND);
ItemStack[] stacks = new ItemStack[this.topStacks.length]; 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; int pos = 0;
for (int i = 0; i < this.topStacks.length; i++) for (int i = 0; i < this.topStacks.length; i++)
@ -523,7 +502,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
public ItemStack[] buildItemStackDataList() public ItemStack[] buildItemStackDataList()
{ {
if (this.type.isTransparent()) if (this.getType().isTransparent())
{ {
ItemStack[] sortList = new ItemStack[this.topStacks.length]; ItemStack[] sortList = new ItemStack[this.topStacks.length];
int pos = 0; int pos = 0;
@ -561,18 +540,13 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) public boolean isItemValidForSlot(int i, ItemStack itemstack)
{ {
return this.type.acceptsStack(itemstack); return this.getType().acceptsStack(itemstack);
} }
public void rotateAround() public void rotateAround()
{ {
this.facing++; this.setFacing(this.facing.rotateY());
if (this.facing > EnumFacing.EAST.ordinal()) this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 2, this.facing.ordinal());
{
this.facing = (byte) EnumFacing.NORTH.ordinal();
}
this.setFacing(this.facing);
this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 2, this.facing);
} }
public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack) public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack)
@ -618,7 +592,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
@Override @Override
public String getGuiID() public String getGuiID()
{ {
return "IronChest:" + this.type.name(); return "IronChest:" + this.getType().name();
} }
@Override @Override

View File

@ -4,7 +4,7 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/

View File

@ -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);
}
}

View File

@ -4,19 +4,17 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest.client; package cpw.mods.ironchest.client;
import cpw.mods.ironchest.ChestChangerType;
import cpw.mods.ironchest.CommonProxy; import cpw.mods.ironchest.CommonProxy;
import cpw.mods.ironchest.IronChest; import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.IronChestType; import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest; 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.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -24,38 +22,39 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; 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.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 public class ClientProxy extends CommonProxy
{ {
@Override @Override
public void registerRenderInformation() public void registerRenderInformation()
{
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getBlockModelShapes().registerBuiltInBlocks(IronChest.ironChestBlock);
ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
for (IronChestType chestType : IronChestType.values())
{
if (chestType != IronChestType.WOOD)
{ {
Item chestItem = Item.getItemFromBlock(IronChest.ironChestBlock); 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())); for (IronChestType type : IronChestType.values())
} {
} if (type != IronChestType.WOOD)
{
ModelLoader.setCustomModelResourceLocation(chestItem, type.ordinal(),
new ModelResourceLocation(new ResourceLocation(IronChest.MOD_ID, "chest_" + type.getName()), "inventory"));
} }
@Override ClientRegistry.bindTileEntitySpecialRenderer(type.clazz, new TileEntityIronChestRenderer());
public <T extends TileEntityIronChest> void registerTileEntitySpecialRenderer(Class<T> type)
{
ClientRegistry.bindTileEntitySpecialRenderer(type, new TileEntityIronChestRenderer<T>(type));
} }
@Override for (ChestChangerType type : ChestChangerType.VALUES)
public World getClientWorld()
{ {
return FMLClientHandler.instance().getClient().theWorld; if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
{
ModelLoader.setCustomModelResourceLocation(type.item, 0,
new ModelResourceLocation(new ResourceLocation(IronChest.MOD_ID, type.itemName), "inventory"));
}
}
} }
@Override @Override

View File

@ -4,18 +4,17 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest.client; package cpw.mods.ironchest.client;
import org.lwjgl.opengl.GL11;
import cpw.mods.ironchest.ContainerIronChest; import cpw.mods.ironchest.ContainerIronChest;
import cpw.mods.ironchest.IronChestType; import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest; import cpw.mods.ironchest.TileEntityIronChest;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -24,15 +23,17 @@ public class GUIChest extends GuiContainer
{ {
public enum ResourceList public enum ResourceList
{ {
IRON(new ResourceLocation("ironchest", "textures/gui/ironcontainer.png")), COPPER( //@formatter:off
new ResourceLocation("ironchest", "textures/gui/coppercontainer.png")), SILVER( IRON(new ResourceLocation("ironchest", "textures/gui/ironcontainer.png")),
new ResourceLocation("ironchest", "textures/gui/silvercontainer.png")), GOLD( COPPER(new ResourceLocation("ironchest", "textures/gui/coppercontainer.png")),
new ResourceLocation("ironchest", "textures/gui/goldcontainer.png")), DIAMOND( SILVER(new ResourceLocation("ironchest", "textures/gui/silvercontainer.png")),
new ResourceLocation("ironchest", "textures/gui/diamondcontainer.png")), DIRT( GOLD(new ResourceLocation("ironchest", "textures/gui/goldcontainer.png")),
new ResourceLocation("ironchest", "textures/gui/dirtcontainer.png")); DIAMOND(new ResourceLocation("ironchest", "textures/gui/diamondcontainer.png")),
DIRT(new ResourceLocation("ironchest", "textures/gui/dirtcontainer.png"));
//@formatter:on
public final ResourceLocation location; public final ResourceLocation location;
private ResourceList(ResourceLocation loc) ResourceList(ResourceLocation loc)
{ {
this.location = loc; this.location = loc;
} }
@ -40,23 +41,28 @@ public class GUIChest extends GuiContainer
public enum GUI public enum GUI
{ {
IRON(184, 202, ResourceList.IRON, IronChestType.IRON), GOLD(184, 256, ResourceList.GOLD, IronChestType.GOLD), DIAMOND(238, 256, ResourceList.DIAMOND, //@formatter:off
IronChestType.DIAMOND), COPPER(184, 184, ResourceList.COPPER, IronChestType.COPPER), SILVER(184, 238, ResourceList.SILVER, IRON(184, 202, ResourceList.IRON, IronChestType.IRON),
IronChestType.SILVER), CRYSTAL(238, 256, ResourceList.DIAMOND, IronChestType.CRYSTAL), OBSIDIAN(238, 256, ResourceList.DIAMOND, GOLD(184, 256, ResourceList.GOLD, IronChestType.GOLD),
IronChestType.OBSIDIAN), DIRTCHEST9000(184, 184, ResourceList.DIRT, IronChestType.DIRTCHEST9000); 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 xSize;
private int ySize; private int ySize;
private ResourceList guiResourceList; private ResourceList guiResourceList;
private IronChestType mainType; 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.xSize = xSize;
this.ySize = ySize; this.ySize = ySize;
this.guiResourceList = guiResourceList; this.guiResourceList = guiResourceList;
this.mainType = mainType; this.mainType = mainType;
} }
protected Container makeContainer(IInventory player, IInventory chest) 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 GUI type;
private GUIChest(GUI type, IInventory player, IInventory chest) private GUIChest(GUI type, IInventory player, IInventory chest)
@ -89,7 +90,7 @@ public class GUIChest extends GuiContainer
@Override @Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) 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" // new "bind tex"
this.mc.getTextureManager().bindTexture(this.type.guiResourceList.location); this.mc.getTextureManager().bindTexture(this.type.guiResourceList.location);
int x = (this.width - this.xSize) / 2; int x = (this.width - this.xSize) / 2;

View File

@ -1,11 +1,12 @@
package cpw.mods.ironchest.client; package cpw.mods.ironchest.client;
import cpw.mods.ironchest.IronChestType;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.fml.client.FMLClientHandler; import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class IronChestEventHandler public class IronChestEventHandler
{ {
@ -17,12 +18,10 @@ public class IronChestEventHandler
{ {
if (event.getMap() == FMLClientHandler.instance().getClient().getTextureMapBlocks()) if (event.getMap() == FMLClientHandler.instance().getClient().getTextureMapBlocks())
{ {
event.getMap().registerSprite(new ResourceLocation("ironchest:blocks/copperbreak")); for (IronChestType t : IronChestType.VALUES)
event.getMap().registerSprite(new ResourceLocation("ironchest:blocks/crystalbreak")); {
event.getMap().registerSprite(new ResourceLocation("ironchest:blocks/diamondbreak")); event.getMap().registerSprite(new ResourceLocation(t.getBreakTexture()));
event.getMap().registerSprite(new ResourceLocation("ironchest:blocks/goldbreak")); }
event.getMap().registerSprite(new ResourceLocation("ironchest:blocks/ironbreak"));
event.getMap().registerSprite(new ResourceLocation("ironchest:blocks/silverbreak"));
} }
} }
} }

View File

@ -1,11 +1,8 @@
package cpw.mods.ironchest.client; package cpw.mods.ironchest.client;
import java.util.Map;
import java.util.Random; import java.util.Random;
import com.google.common.collect.ImmutableMap; import cpw.mods.ironchest.BlockIronChest;
import com.google.common.collect.ImmutableMap.Builder;
import cpw.mods.ironchest.IronChestType; import cpw.mods.ironchest.IronChestType;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; 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.EnumBlockRenderType;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public class IronChestTextureHandler 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) public static void addHitEffects(World world, BlockPos pos, EnumFacing side)
{ {
IBlockState state = world.getBlockState(pos); IBlockState state = world.getBlockState(pos);
Block block = state.getBlock(); Block block = state.getBlock();
state = block.getActualState(state, world, pos); state = block.getActualState(state, world, pos);
Random rand = new Random(); 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(); ModelManager modelmanager = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager();
if (block.getRenderType(state) != EnumBlockRenderType.INVISIBLE) if (block.getRenderType(state) != EnumBlockRenderType.INVISIBLE)
@ -96,13 +75,7 @@ public class IronChestTextureHandler
fx.setBlockPos(pos); fx.setBlockPos(pos);
fx.multiplyVelocity(0.2F); fx.multiplyVelocity(0.2F);
fx.multipleParticleScaleBy(0.6F); fx.multipleParticleScaleBy(0.6F);
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite(type.getBreakTexture()));
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()));
} }
} }
@ -110,7 +83,7 @@ public class IronChestTextureHandler
{ {
state = state.getBlock().getActualState(state, world, pos); state = state.getBlock().getActualState(state, world, pos);
int i = 4; 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(); ModelManager modelmanager = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager();
for (int j = 0; j < i; ++j) 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, 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()))); Block.getIdFromBlock(state.getBlock())));
fx.setBlockPos(pos); fx.setBlockPos(pos);
if (type != IronChestType.DIRTCHEST9000 && type != IronChestType.OBSIDIAN) fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite(type.getBreakTexture()));
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()));
} }
} }
} }

View File

@ -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);
}
}

View File

@ -4,17 +4,14 @@
* are made available under the terms of the GNU Public License v3.0 * are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * <p>
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest.client; package cpw.mods.ironchest.client;
import java.util.Map;
import java.util.Random; import java.util.Random;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.primitives.SignedBytes; import com.google.common.primitives.SignedBytes;
import cpw.mods.ironchest.BlockIronChest; 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.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack; 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 Random random;
private RenderEntityItem itemRenderer; private RenderEntityItem itemRenderer;
private ModelChest model; 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 }, 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 }, }; { 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.model = new ModelChest();
this.random = new Random(); 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 @Override
public boolean shouldBob() public void renderTileEntityAt(TileEntityIronChest tile, double x, double y, double z, float partialTick, int breakStage)
{ {
return false; if (tile == null || tile.isInvalid())
}
@Override
public boolean shouldSpreadItems()
{
return false;
}
};
}
public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick, int breakStage)
{
if (tile == null)
{ {
return; return;
} }
int facing = 3;
EnumFacing facing = EnumFacing.SOUTH;
IronChestType type = tile.getType(); 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(); facing = tile.getFacing();
type = tile.getType();
IBlockState state = tile.getWorld().getBlockState(tile.getPos()); IBlockState state = tile.getWorld().getBlockState(tile.getPos());
type = state.getValue(BlockIronChest.VARIANT_PROP); type = state.getValue(BlockIronChest.VARIANT_PROP);
} }
@ -99,46 +68,59 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
this.bindTexture(DESTROY_STAGES[breakStage]); this.bindTexture(DESTROY_STAGES[breakStage]);
GlStateManager.matrixMode(5890); GlStateManager.matrixMode(5890);
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
GlStateManager.scale(4.0F, 4.0F, 1.0F); GlStateManager.scale(4F, 4F, 1F);
GlStateManager.translate(0.0625F, 0.0625F, 0.0625F); GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
GlStateManager.matrixMode(5888); GlStateManager.matrixMode(5888);
} }
else else
{ {
this.bindTexture(locations.get(type)); this.bindTexture(type.modelTexture);
} }
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
if (type == IronChestType.CRYSTAL) if (type == IronChestType.CRYSTAL)
{ {
GlStateManager.disableCull(); GlStateManager.disableCull();
} }
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.color(1F, 1F, 1F, 1F);
GlStateManager.translate((float) x, (float) y + 1.0F, (float) z + 1.0F); GlStateManager.translate((float) x, (float) y + 1F, (float) z + 1F);
GlStateManager.scale(1.0F, -1F, -1F); GlStateManager.scale(1F, -1F, -1F);
GlStateManager.translate(0.5F, 0.5F, 0.5F); GlStateManager.translate(0.5F, 0.5F, 0.5F);
int k = 0;
if (facing == 2) switch (facing)
{ {
k = 180; case NORTH:
}
if (facing == 3)
{ {
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); GlStateManager.translate(-0.5F, -0.5F, -0.5F);
float lidangle = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * partialTick; float lidangle = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * partialTick;
lidangle = 1.0F - lidangle; lidangle = 1F - lidangle;
lidangle = 1.0F - lidangle * lidangle * lidangle; lidangle = 1F - lidangle * lidangle * lidangle;
this.model.chestLid.rotateAngleX = -((lidangle * 3.141593F) / 2.0F);
if (type.isTransparent())
{
GlStateManager.scale(1F, 0.99F, 1F);
}
this.model.chestLid.rotateAngleX = -lidangle * halfPI;
// Render the chest itself // Render the chest itself
this.model.renderAll(); this.model.renderAll();
if (breakStage >= 0) if (breakStage >= 0)
@ -152,7 +134,7 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
GlStateManager.enableCull(); GlStateManager.enableCull();
} }
GlStateManager.popMatrix(); GlStateManager.popMatrix();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.color(1F, 1F, 1F, 1F);
if (type.isTransparent() if (type.isTransparent()
&& tile.getDistanceSq(this.rendererDispatcher.entityX, this.rendererDispatcher.entityY, this.rendererDispatcher.entityZ) < 128d) && 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; float shiftZ;
int shift = 0; int shift = 0;
float blockScale = 0.70F; 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) if (tile.getTopItemStacks()[1] == null)
{ {
shift = 8; shift = 8;
@ -171,8 +153,9 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
} }
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
GlStateManager.translate((float) x, (float) y, (float) z); 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()) for (ItemStack item : tile.getTopItemStacks())
{ {
if (shift > shifts.length) if (shift > shifts.length)
@ -190,19 +173,39 @@ public class TileEntityIronChestRenderer<T extends TileEntityIronChest> extends
shift++; shift++;
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
GlStateManager.translate(shiftX, shiftY, shiftZ); 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); GlStateManager.scale(blockScale, blockScale, blockScale);
customitem.setEntityItemStack(item); customitem.setEntityItemStack(item);
this.itemRenderer.doRender(customitem, 0, 0, 0, 0, 0);
GlStateManager.popMatrix(); if (this.itemRenderer == null)
} {
GlStateManager.popMatrix(); 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 @Override
public void renderTileEntityAt(TileEntityIronChest tileentity, double x, double y, double z, float partialTick, int breakStage) public boolean shouldBob()
{ {
this.render(tileentity, x, y, z, partialTick, breakStage); return false;
}
@Override
public boolean shouldSpreadItems()
{
return true;
}
};
}
this.itemRenderer.doRender(customitem, 0D, 0D, 0D, 0F, partialTick);
GlStateManager.popMatrix();
}
GlStateManager.popMatrix();
}
} }
} }