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

@ -4,7 +4,7 @@
* 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
******************************************************************************/
@ -18,6 +18,7 @@ import net.minecraft.src.EntityItem;
import net.minecraft.src.EntityLiving;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IBlockAccess;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Material;
import net.minecraft.src.MathHelper;
@ -163,12 +164,12 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getBlockTileEntity(i, j, k);
if (tileentitychest != null)
{
dropContent(0, tileentitychest, world);
dropContent(0, tileentitychest, world, tileentitychest.xCoord, tileentitychest.yCoord, tileentitychest.zCoord);
}
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++)
{
ItemStack itemstack = chest.getStackInSlot(l);
@ -187,7 +188,7 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
i1 = itemstack.stackSize;
}
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()));
float f3 = 0.05F;
entityitem.motionX = (float) random.nextGaussian() * f3;
@ -206,7 +207,9 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
@Override
public void addCreativeItems(ArrayList itemList) {
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.SILVER;
import static cpw.mods.ironchest.IronChestType.CRYSTAL;
import static cpw.mods.ironchest.IronChestType.WOOD;
import net.minecraft.src.Block;
import net.minecraft.src.ItemStack;
@ -23,7 +24,9 @@ public enum ChestChangerType {
COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "Copper to Silver Chest Upgrade", "mmm", "msm", "mmm"),
SILVERGOLD(SILVER, GOLD, "silverGoldUpgrade", "Silver to Gold Chest Upgrade", "mGm", "GsG", "mGm"),
COPPERIRON(COPPER, IRON, "copperIronUpgrade", "Copper to Iron Chest Upgrade", "mGm", "GsG", "mGm"),
DIAMONDCRYSTAL(DIAMOND, CRYSTAL, "diamondCrystalUpgrade", "Diamond to Crystal Chest Upgrade", "GGG", "GOG", "GGG");
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 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"),
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"),
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;
private int rowLength;
public String friendlyName;
@ -61,16 +62,18 @@ public enum IronChestType {
public static TileEntityIronChest makeEntity(int metadata) {
// Compatibility
int chesttype = metadata;
try {
TileEntityIronChest te = values()[chesttype].clazz.newInstance();
return te;
} catch (InstantiationException e) {
// unpossible
e.printStackTrace();
} catch (IllegalAccessException e) {
// unpossible
e.printStackTrace();
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;
}
@ -117,6 +120,8 @@ public enum IronChestType {
return Item.diamond;
} else if (mat == "blockGlass") {
return Block.glass;
} else if (mat == "blockPlanks") {
return Block.planks;
}
return mat;
}
@ -143,4 +148,16 @@ public enum IronChestType {
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

@ -4,16 +4,18 @@
* 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 cpw.mods.fml.common.ReflectionHelper;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.TileEntity;
import net.minecraft.src.TileEntityChest;
import net.minecraft.src.World;
import net.minecraft.src.forge.ITextureProvider;
@ -32,21 +34,43 @@ public class ItemChestChanger extends Item implements ITextureProvider {
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int X, int Y, int Z, int side) {
TileEntity te=world.getBlockTileEntity(X,Y,Z);
TileEntityIronChest newchest;
if (te!=null && te instanceof TileEntityIronChest) {
TileEntityIronChest ironchest=(TileEntityIronChest)te;
TileEntityIronChest newchest=ironchest.applyUpgradeItem(this);
newchest=ironchest.applyUpgradeItem(this);
if (newchest==null) {
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;
} else if (te!=null && te instanceof TileEntityChest) {
TileEntityChest tec = (TileEntityChest) te;
if (tec.numUsingPlayers > 0) {
return false;
}
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 {
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

View File

@ -4,7 +4,7 @@
* 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
******************************************************************************/
@ -25,17 +25,13 @@ public class ItemIronChest extends ItemBlock {
@Override
public int getMetadata(int i) {
if (i<IronChestType.values().length) {
return i;
} else {
return 0;
}
return IronChestType.validateMeta(i);
}
@Override
public String getItemNameIS(ItemStack itemstack) {
return IronChestType.values()[itemstack.getItemDamage()].name();
}
@Override
public void addCreativeItems(@SuppressWarnings("rawtypes") ArrayList itemList) {
}

View File

@ -4,7 +4,7 @@
* 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
******************************************************************************/
@ -267,7 +267,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
}
}
@Override
public void receiveClientEvent(int i, int j)
{
@ -313,7 +313,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
int newSize = newEntity.chestContents.length;
System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length));
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.sortTopStacks();
return newEntity;
@ -393,6 +393,6 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
}
}
public void setMaxStackSize(int size) {
}
}

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB