diff --git a/IronChests2/build.xml b/IronChests2/build.xml index 91c84b4..48c81b5 100644 --- a/IronChests2/build.xml +++ b/IronChests2/build.xml @@ -68,7 +68,7 @@ - + @@ -114,8 +114,9 @@ - - - + + + + diff --git a/IronChests2/client/net/minecraft/src/mod_IronChest.java b/IronChests2/client/net/minecraft/src/mod_IronChest.java index 5c9cf1b..8fee928 100644 --- a/IronChests2/client/net/minecraft/src/mod_IronChest.java +++ b/IronChests2/client/net/minecraft/src/mod_IronChest.java @@ -3,13 +3,16 @@ package net.minecraft.src; import java.io.File; import cpw.mods.ironchest.BlockIronChest; - +import cpw.mods.ironchest.IronChestType; +import cpw.mods.ironchest.ItemIronChest; import net.minecraft.client.Minecraft; import net.minecraft.src.forge.Configuration; +import net.minecraft.src.forge.MinecraftForgeClient; public class mod_IronChest extends BaseModMp { public static BlockIronChest ironChestBlock; + public static boolean compatibilityMode; @Override public String getVersion() { @@ -18,10 +21,17 @@ public class mod_IronChest extends BaseModMp { @Override public void load() { - Configuration cfg=new Configuration(new File(Minecraft.getMinecraftDir(),"config/IronChest.cfg")); + File cfgFile = new File(Minecraft.getMinecraftDir(), "config/IronChest.cfg"); + // If our config file exists + boolean defaultCompatibility = cfgFile.exists(); + Configuration cfg = new Configuration(cfgFile); try { cfg.load(); - ironChestBlock=new BlockIronChest(Integer.parseInt(cfg.getOrCreateBlockIdProperty("blockVeryLargeChest", 181).value)); + // But doesn't have the compatibilityMode flag, enable compatibility + // mode + compatibilityMode = Boolean.parseBoolean(cfg.getOrCreateBooleanProperty("compatibilityMode", Configuration.GENERAL_PROPERTY, + defaultCompatibility).value); + ironChestBlock = new BlockIronChest(Integer.parseInt(cfg.getOrCreateBlockIdProperty("blockVeryLargeChest", 181).value)); } catch (Exception e) { ModLoader.getLogger().severe("IronChest was unable to load it's configuration successfully"); e.printStackTrace(System.err); @@ -29,6 +39,12 @@ public class mod_IronChest extends BaseModMp { } finally { cfg.save(); } + + ModLoader.RegisterBlock(ironChestBlock, ItemIronChest.class); + IronChestType.registerTileEntities(); + IronChestType.registerRecipes(ironChestBlock); + + MinecraftForgeClient.preloadTexture("ic2/sprites/ironchest_block_tex.png"); } } diff --git a/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java b/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java index f01390c..6440bb7 100644 --- a/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java @@ -28,7 +28,7 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider { @Override public TileEntity getBlockEntity(int metadata) { - return TileEntityIronChest.makeEntity(metadata); + return IronChestType.makeEntity(metadata); } public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l) { @@ -36,34 +36,38 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider { if (te != null && te instanceof TileEntityIronChest) { TileEntityIronChest icte=(TileEntityIronChest) te; if (l==0 || l==1) { // Top and Bottom - return icte.getType().getTextureRow()*16; - } else if (l==getTextureFace(icte.getFacing())) { // Front return icte.getType().getTextureRow()*16+1; - } else { // Back and Sides + } else if (l==icte.getFacing()) { // Front return icte.getType().getTextureRow()*16+2; + } else { // Back and Sides + return icte.getType().getTextureRow()*16; } } return 0; } - public byte getTextureFace(byte facing) { - switch (facing) { + @Override + public int getBlockTextureFromSideAndMetadata(int i, int j) { + IronChestType typ=IronChestType.values()[j]; + switch (i) { case 0: - return 3; case 1: - return 4; + return typ.getTextureRow()*16+1; case 2: - return 2; - case 3: - return 5; + return typ.getTextureRow()*16+2; default: - return 0; + return typ.getTextureRow()*16; } } - + + @Override + public void onBlockAdded(World world, int i, int j, int k) { + super.onBlockAdded(world, i, j, k); + world.markBlockNeedsUpdate(i, j, k); + } + @Override public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving) { - super.onBlockPlacedBy(world, i, j, k, entityliving); byte chestFacing = 0; int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3; if (facing == 0) { @@ -78,9 +82,11 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider { if (facing == 3) { chestFacing = 4; } + System.out.printf("Facing %d %d\n", facing,chestFacing); TileEntity te = world.getBlockTileEntity(i, j, k); if (te != null && te instanceof TileEntityIronChest) { ((TileEntityIronChest) te).setFacing(chestFacing); + world.markBlockNeedsUpdate(i, j, k); } } } diff --git a/IronChests2/common/cpw/mods/ironchest/IronChestType.java b/IronChests2/common/cpw/mods/ironchest/IronChestType.java new file mode 100644 index 0000000..2dcbc6f --- /dev/null +++ b/IronChests2/common/cpw/mods/ironchest/IronChestType.java @@ -0,0 +1,87 @@ +package cpw.mods.ironchest; + +import java.util.Arrays; + +import net.minecraft.src.Block; +import net.minecraft.src.Item; +import net.minecraft.src.ItemStack; +import net.minecraft.src.ModLoader; +import net.minecraft.src.TileEntity; +import net.minecraft.src.mod_IronChest; + +public enum IronChestType { + IRON(54, "IronChest", "ironchest.png", 0, Item.ingotIron, TileEntityIronChest.class, "mmmmPmmmm"), + GOLD(81, "GoldChest", "goldchest.png", 1, Item.ingotGold, TileEntityGoldChest.class, "mmmmPmmmm"); + // DIAMOND(108,"DiamondChest","diamondchest.png",2); + int size; + String friendlyName; + private String modelTexture; + private int textureRow; + private Class clazz; + private Item mat; + private String[] recipes; + + IronChestType(int size, String friendlyName, String modelTexture, int textureRow, Item mat, Class clazz, String... recipes) { + this.size = size; + this.friendlyName = friendlyName; + this.modelTexture = modelTexture; + this.textureRow = textureRow; + this.clazz = clazz; + this.mat = mat; + this.recipes=recipes; + } + + public String getModelTexture() { + return modelTexture; + } + + public int getTextureRow() { + return textureRow; + } + + public static TileEntity makeEntity(int metadata) { + //Compatibility + int chesttype=metadata; + int facing=0; + + if (metadata>2) { + chesttype=metadata<<2; + facing=metadata&3; + } + try { + TileEntityIronChest te=values()[chesttype].clazz.newInstance(); + if (mod_IronChest.compatibilityMode) { + te.setFacing((byte)facing); + } + return te; + } catch (InstantiationException e) { + // unpossible + e.printStackTrace(); + } catch (IllegalAccessException e) { + // unpossible + e.printStackTrace(); + } + return null; + } + + public static void registerTileEntities() { + for (IronChestType typ : values()) { + System.out.printf("Registering %s\n",typ.friendlyName); + ModLoader.RegisterTileEntity(typ.clazz, typ.friendlyName); + } + } + + public static void registerRecipes(BlockIronChest blockResult) { + ItemStack previous=new ItemStack(Block.chest); + for (IronChestType typ : values()) { + for (String recipe : typ.recipes) { + addRecipe(new ItemStack(blockResult, typ.ordinal()), recipe, 'm', typ.mat, 'P', previous, 'G', Block.glass, 'C', Block.chest); + } + previous=new ItemStack(blockResult,typ.ordinal()); + } + } + private static void addRecipe(ItemStack is, Object... parts) { + System.out.printf("Recipe : %s\n",Arrays.asList(parts)); + ModLoader.AddRecipe(is, parts); + } +} \ No newline at end of file diff --git a/IronChests2/common/cpw/mods/ironchest/ItemIronChest.java b/IronChests2/common/cpw/mods/ironchest/ItemIronChest.java new file mode 100644 index 0000000..5e3059d --- /dev/null +++ b/IronChests2/common/cpw/mods/ironchest/ItemIronChest.java @@ -0,0 +1,26 @@ +package cpw.mods.ironchest; + +import net.minecraft.src.ItemBlock; +import net.minecraft.src.ItemStack; + +public class ItemIronChest extends ItemBlock { + + public ItemIronChest(int id) { + super(id); + setMaxDamage(0); + setHasSubtypes(true); + } + + @Override + public int getMetadata(int i) { + if (i<=IronChestType.values().length) { + return i; + } else { + return 0; + } + } + @Override + public String getItemNameIS(ItemStack itemstack) { + return IronChestType.values()[itemstack.getItemDamage()].friendlyName; + } +} diff --git a/IronChests2/common/cpw/mods/ironchest/TileEntityGoldChest.java b/IronChests2/common/cpw/mods/ironchest/TileEntityGoldChest.java new file mode 100644 index 0000000..2d195ef --- /dev/null +++ b/IronChests2/common/cpw/mods/ironchest/TileEntityGoldChest.java @@ -0,0 +1,8 @@ +package cpw.mods.ironchest; + +public class TileEntityGoldChest extends TileEntityIronChest { + + public TileEntityGoldChest() { + super(IronChestType.GOLD); + } +} diff --git a/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java b/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java index c860582..5c54023 100644 --- a/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java @@ -8,41 +8,21 @@ import net.minecraft.src.NBTTagList; import net.minecraft.src.TileEntity; public class TileEntityIronChest extends TileEntity implements IInventory { - public enum Type { - IRON(54,"IronChest","ironchest.png",0), - GOLD(81,"GoldChest","goldchest.png",1), - DIAMOND(108,"DiamondChest","diamondchest.png",2); - private int size; - private String friendlyName; - private String modelTexture; - private int textureRow; - - Type(int size, String friendlyName, String modelTexture, int textureRow) { - this.size=size; - this.friendlyName=friendlyName; - this.modelTexture=modelTexture; - this.textureRow=textureRow; - } - - public String getModelTexture() { - return modelTexture; - } - - public int getTextureRow() { - return textureRow; - } - } private int ticksSinceSync; public float prevLidAngle; public float lidAngle; private int numUsingPlayers; - private Type type; + private IronChestType type; public ItemStack[] chestContents; private byte facing; - public TileEntityIronChest(Type type, byte facing) { + public TileEntityIronChest() { + this(IronChestType.IRON); + } + + protected TileEntityIronChest(IronChestType type) { + super(); this.type=type; - this.facing=facing; this.chestContents=new ItemStack[getSizeInventory()]; } @Override @@ -58,25 +38,47 @@ public class TileEntityIronChest extends TileEntity implements IInventory { return type.friendlyName; } - public Type getType() { + public IronChestType getType() { return type; } @Override public ItemStack getStackInSlot(int i) { - // TODO Auto-generated method stub - return null; + return chestContents[i]; } @Override public ItemStack decrStackSize(int i, int j) { - // TODO Auto-generated method stub - return null; + if (chestContents[i] != null) + { + if (chestContents[i].stackSize <= j) + { + ItemStack itemstack = chestContents[i]; + chestContents[i] = null; + onInventoryChanged(); + return itemstack; + } + ItemStack itemstack1 = chestContents[i].splitStack(j); + if (chestContents[i].stackSize == 0) + { + chestContents[i] = null; + } + onInventoryChanged(); + return itemstack1; + } + else + { + return null; + } } @Override public void setInventorySlotContents(int i, ItemStack itemstack) { - // TODO Auto-generated method stub - + chestContents[i] = itemstack; + if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) + { + itemstack.stackSize = getInventoryStackLimit(); + } + onInventoryChanged(); } @Override @@ -94,6 +96,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory { chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } + facing=nbttagcompound.getByte("facing"); } @Override @@ -113,6 +116,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory { } nbttagcompound.setTag("Items", nbttaglist); + nbttagcompound.setByte("facing", facing); } @Override @@ -170,6 +174,8 @@ public class TileEntityIronChest extends TileEntity implements IInventory { if (i == 1) { numUsingPlayers = j; + } else if (i == 2) { + facing = (byte)j; } } @@ -185,19 +191,11 @@ public class TileEntityIronChest extends TileEntity implements IInventory { worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers); } - protected static TileEntity makeEntity(int metadata) { - //Compatibility - int chesttype=metadata; - int facing=0; - - if (metadata>2) { - chesttype=metadata<<2; - facing=metadata&3; - } - return new TileEntityIronChest(Type.values()[chesttype],(byte)facing); - } public void setFacing(byte chestFacing) { this.facing=chestFacing; + if (worldObj!=null) { + worldObj.playNoteAt(xCoord, yCoord, zCoord, 2, facing); + } } } diff --git a/IronChests2/resources/ic2/sprites/ironchest.png b/IronChests2/resources/ic2/sprites/ironchest.png new file mode 100644 index 0000000..df883ff Binary files /dev/null and b/IronChests2/resources/ic2/sprites/ironchest.png differ diff --git a/IronChests2/resources/ic2/sprites/ironchest_block_tex.png b/IronChests2/resources/ic2/sprites/ironchest_block_tex.png new file mode 100644 index 0000000..a16321b Binary files /dev/null and b/IronChests2/resources/ic2/sprites/ironchest_block_tex.png differ diff --git a/IronChests2/resources/texturesheet.xcf b/IronChests2/resources/texturesheet.xcf new file mode 100644 index 0000000..0bc166c Binary files /dev/null and b/IronChests2/resources/texturesheet.xcf differ