Support vanilla to ironchest upgrades. Hi florastar and faunastar!

This commit is contained in:
Christian 2012-06-29 12:47:09 -04:00
parent 811443a1de
commit fcc7f72a6b
8 changed files with 80 additions and 37 deletions

View File

@ -18,6 +18,7 @@ import net.minecraft.src.EntityItem;
import net.minecraft.src.EntityLiving; import net.minecraft.src.EntityLiving;
import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IBlockAccess; import net.minecraft.src.IBlockAccess;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack; import net.minecraft.src.ItemStack;
import net.minecraft.src.Material; import net.minecraft.src.Material;
import net.minecraft.src.MathHelper; import net.minecraft.src.MathHelper;
@ -163,12 +164,12 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getBlockTileEntity(i, j, k); TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getBlockTileEntity(i, j, k);
if (tileentitychest != null) if (tileentitychest != null)
{ {
dropContent(0, tileentitychest, world); dropContent(0, tileentitychest, world, tileentitychest.xCoord, tileentitychest.yCoord, tileentitychest.zCoord);
} }
super.onBlockRemoval(world, i, j, k); super.onBlockRemoval(world, i, j, k);
} }
public void dropContent(int newSize, TileEntityIronChest chest, World world) { public void dropContent(int newSize, IInventory chest, World world, int xCoord, int yCoord, int zCoord) {
for (int l = newSize; l < chest.getSizeInventory(); l++) for (int l = newSize; l < chest.getSizeInventory(); l++)
{ {
ItemStack itemstack = chest.getStackInSlot(l); ItemStack itemstack = chest.getStackInSlot(l);
@ -187,7 +188,7 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
i1 = itemstack.stackSize; i1 = itemstack.stackSize;
} }
itemstack.stackSize -= i1; itemstack.stackSize -= i1;
EntityItem entityitem = new EntityItem(world, (float) chest.xCoord + f, (float) chest.yCoord + (newSize > 0 ? 1 : 0) + f1, (float) chest.zCoord + f2, EntityItem entityitem = new EntityItem(world, (float) xCoord + f, (float) yCoord + (newSize > 0 ? 1 : 0) + f1, (float) zCoord + f2,
new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage())); new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage()));
float f3 = 0.05F; float f3 = 0.05F;
entityitem.motionX = (float) random.nextGaussian() * f3; entityitem.motionX = (float) random.nextGaussian() * f3;
@ -206,7 +207,9 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
@Override @Override
public void addCreativeItems(ArrayList itemList) { public void addCreativeItems(ArrayList itemList) {
for (IronChestType type : IronChestType.values()) { for (IronChestType type : IronChestType.values()) {
itemList.add(new ItemStack(this, 1, type.ordinal())); if (type.isValidForCreativeMode()) {
itemList.add(new ItemStack(this, 1, type.ordinal()));
}
} }
} }
} }

View File

@ -12,6 +12,7 @@ import static cpw.mods.ironchest.IronChestType.GOLD;
import static cpw.mods.ironchest.IronChestType.IRON; import static cpw.mods.ironchest.IronChestType.IRON;
import static cpw.mods.ironchest.IronChestType.SILVER; import static cpw.mods.ironchest.IronChestType.SILVER;
import static cpw.mods.ironchest.IronChestType.CRYSTAL; import static cpw.mods.ironchest.IronChestType.CRYSTAL;
import static cpw.mods.ironchest.IronChestType.WOOD;
import net.minecraft.src.Block; import net.minecraft.src.Block;
import net.minecraft.src.ItemStack; import net.minecraft.src.ItemStack;
@ -23,7 +24,9 @@ public enum ChestChangerType {
COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "Copper to Silver Chest Upgrade", "mmm", "msm", "mmm"), COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "Copper to Silver Chest Upgrade", "mmm", "msm", "mmm"),
SILVERGOLD(SILVER, GOLD, "silverGoldUpgrade", "Silver to Gold Chest Upgrade", "mGm", "GsG", "mGm"), SILVERGOLD(SILVER, GOLD, "silverGoldUpgrade", "Silver to Gold Chest Upgrade", "mGm", "GsG", "mGm"),
COPPERIRON(COPPER, IRON, "copperIronUpgrade", "Copper to Iron Chest Upgrade", "mGm", "GsG", "mGm"), COPPERIRON(COPPER, IRON, "copperIronUpgrade", "Copper to Iron Chest Upgrade", "mGm", "GsG", "mGm"),
DIAMONDCRYSTAL(DIAMOND, CRYSTAL, "diamondCrystalUpgrade", "Diamond to Crystal Chest Upgrade", "GGG", "GOG", "GGG"); DIAMONDCRYSTAL(DIAMOND, CRYSTAL, "diamondCrystalUpgrade", "Diamond to Crystal Chest Upgrade", "GGG", "GOG", "GGG"),
WOODIRON(WOOD, IRON, "woodIronUpgrade", "Normal chest to Iron Chest Upgrade", "mmm", "msm", "mmm"),
WOODCOPPER(WOOD, COPPER, "woodCopperUpgrade", "Normal chest to Copper Chest Upgrade", "mmm", "msm", "mmm");
private IronChestType source; private IronChestType source;
private IronChestType target; private IronChestType target;

View File

@ -26,7 +26,8 @@ public enum IronChestType {
DIAMOND(108, 12, true, "Diamond Chest", "diamondchest.png", 2, Arrays.asList("gemDiamond"), TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"), DIAMOND(108, 12, true, "Diamond Chest", "diamondchest.png", 2, Arrays.asList("gemDiamond"), TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"),
COPPER(45, 9, false, "Copper Chest", "copperchest.png", 3, Arrays.asList("ingotCopper"), TileEntityCopperChest.class, "mmmmCmmmm"), COPPER(45, 9, false, "Copper Chest", "copperchest.png", 3, Arrays.asList("ingotCopper"), TileEntityCopperChest.class, "mmmmCmmmm"),
SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, Arrays.asList("ingotSilver"), TileEntitySilverChest.class, "mmmm0mmmm", "mGmG3GmGm"), SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, Arrays.asList("ingotSilver"), TileEntitySilverChest.class, "mmmm0mmmm", "mGmG3GmGm"),
CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"); CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"),
WOOD(0,0,false,"","",-1,Arrays.asList("blockPlanks"),null);
int size; int size;
private int rowLength; private int rowLength;
public String friendlyName; public String friendlyName;
@ -61,16 +62,18 @@ public enum IronChestType {
public static TileEntityIronChest makeEntity(int metadata) { public static TileEntityIronChest makeEntity(int metadata) {
// Compatibility // Compatibility
int chesttype = metadata; int chesttype = validateMeta(metadata);
try { if (chesttype == metadata) {
TileEntityIronChest te = values()[chesttype].clazz.newInstance(); try {
return te; TileEntityIronChest te = values()[chesttype].clazz.newInstance();
} catch (InstantiationException e) { return te;
// unpossible } catch (InstantiationException e) {
e.printStackTrace(); // unpossible
} catch (IllegalAccessException e) { e.printStackTrace();
// unpossible } catch (IllegalAccessException e) {
e.printStackTrace(); // unpossible
e.printStackTrace();
}
} }
return null; return null;
} }
@ -117,6 +120,8 @@ public enum IronChestType {
return Item.diamond; return Item.diamond;
} else if (mat == "blockGlass") { } else if (mat == "blockGlass") {
return Block.glass; return Block.glass;
} else if (mat == "blockPlanks") {
return Block.planks;
} }
return mat; return mat;
} }
@ -143,4 +148,16 @@ public enum IronChestType {
return matList; return matList;
} }
public static int validateMeta(int i) {
if (i < values().length && values()[i].size>0) {
return i;
} else {
return 0;
}
}
public boolean isValidForCreativeMode() {
return validateMeta(ordinal())==ordinal();
}
} }

View File

@ -10,10 +10,12 @@
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest; package cpw.mods.ironchest;
import cpw.mods.fml.common.ReflectionHelper;
import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityPlayer;
import net.minecraft.src.Item; import net.minecraft.src.Item;
import net.minecraft.src.ItemStack; import net.minecraft.src.ItemStack;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
import net.minecraft.src.TileEntityChest;
import net.minecraft.src.World; import net.minecraft.src.World;
import net.minecraft.src.forge.ITextureProvider; import net.minecraft.src.forge.ITextureProvider;
@ -32,21 +34,43 @@ public class ItemChestChanger extends Item implements ITextureProvider {
@Override @Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int X, int Y, int Z, int side) { public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int X, int Y, int Z, int side) {
TileEntity te=world.getBlockTileEntity(X,Y,Z); TileEntity te=world.getBlockTileEntity(X,Y,Z);
TileEntityIronChest newchest;
if (te!=null && te instanceof TileEntityIronChest) { if (te!=null && te instanceof TileEntityIronChest) {
TileEntityIronChest ironchest=(TileEntityIronChest)te; TileEntityIronChest ironchest=(TileEntityIronChest)te;
TileEntityIronChest newchest=ironchest.applyUpgradeItem(this); newchest=ironchest.applyUpgradeItem(this);
if (newchest==null) { if (newchest==null) {
return false; return false;
} }
world.setBlockTileEntity(X, Y, Z, newchest); } else if (te!=null && te instanceof TileEntityChest) {
world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal()); TileEntityChest tec = (TileEntityChest) te;
world.notifyBlocksOfNeighborChange(X, Y, Z, world.getBlockId(X, Y, Z)); if (tec.numUsingPlayers > 0) {
world.markBlockNeedsUpdate(X, Y, Z); return false;
stack.stackSize=0; }
return true; if (!getType().canUpgrade(IronChestType.WOOD)) {
return false;
}
newchest = IronChestType.makeEntity(getTargetChestOrdinal(IronChestType.WOOD.ordinal()));
int newSize = newchest.chestContents.length;
ItemStack[] chestContents = ReflectionHelper.getPrivateValue(TileEntityChest.class, tec, "chestContents");
System.arraycopy(chestContents, 0, newchest.chestContents, 0, Math.min(newSize, chestContents.length));
BlockIronChest block = mod_IronChest.ironChestBlock;
block.dropContent(newSize, tec, world, tec.xCoord, tec.yCoord, tec.zCoord);
newchest.setFacing((byte)tec.getBlockMetadata());
newchest.sortTopStacks();
for (int i = 0; i< Math.min(newSize, chestContents.length); i++)
{
chestContents[i]=null;
}
world.setBlock(X, Y, Z, block.blockID);
} else { } else {
return false; return false;
} }
world.setBlockTileEntity(X, Y, Z, newchest);
world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal());
world.notifyBlocksOfNeighborChange(X, Y, Z, world.getBlockId(X, Y, Z));
world.markBlockNeedsUpdate(X, Y, Z);
stack.stackSize=0;
return true;
} }
@Override @Override

View File

@ -25,11 +25,7 @@ public class ItemIronChest extends ItemBlock {
@Override @Override
public int getMetadata(int i) { public int getMetadata(int i) {
if (i<IronChestType.values().length) { return IronChestType.validateMeta(i);
return i;
} else {
return 0;
}
} }
@Override @Override
public String getItemNameIS(ItemStack itemstack) { public String getItemNameIS(ItemStack itemstack) {

View File

@ -313,7 +313,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
int newSize = newEntity.chestContents.length; int newSize = newEntity.chestContents.length;
System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length)); System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length));
BlockIronChest block = mod_IronChest.ironChestBlock; BlockIronChest block = mod_IronChest.ironChestBlock;
block.dropContent(newSize, this, this.worldObj); block.dropContent(newSize, this, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
newEntity.setFacing(facing); newEntity.setFacing(facing);
newEntity.sortTopStacks(); newEntity.sortTopStacks();
return newEntity; return newEntity;

View File

@ -47,7 +47,7 @@ public class mod_IronChest extends NetworkMod {
Configuration cfg = new Configuration(cfgFile); Configuration cfg = new Configuration(cfgFile);
try { try {
cfg.load(); cfg.load();
int bId = cfg.getOrCreateBlockIdProperty("ironChests", 181).getInt(181); int bId = cfg.getOrCreateBlockIdProperty("ironChests", 502).getInt(502);
ironChestBlock = new BlockIronChest(bId); ironChestBlock = new BlockIronChest(bId);
ChestChangerType.buildItems(cfg, 19501); ChestChangerType.buildItems(cfg, 19501);
} catch (Exception e) { } catch (Exception e) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB