From 378481b3160e675ce911d35801f233a9e4a9d0d4 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 14 Feb 2014 15:46:08 -0500 Subject: [PATCH 1/2] Fix some Logic Classes --- .../blocks/abstracts/InventoryLogic.java | 44 ++++++------------- .../blocks/abstracts/MultiServantLogic.java | 28 +++++++----- 2 files changed, 30 insertions(+), 42 deletions(-) diff --git a/src/mantle/blocks/abstracts/InventoryLogic.java b/src/mantle/blocks/abstracts/InventoryLogic.java index 02b3fae..96b4cfe 100644 --- a/src/mantle/blocks/abstracts/InventoryLogic.java +++ b/src/mantle/blocks/abstracts/InventoryLogic.java @@ -1,7 +1,5 @@ package mantle.blocks.abstracts; -import mantle.debug.DebugData; -import mantle.debug.IDebuggable; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -13,12 +11,12 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -/** - * Abstract logic for inventory Tile Entities. - * - * @author mDiyo +/* + * A simple logic class for storing items + * Abstract to avoid instantiation */ -public abstract class InventoryLogic extends TileEntity implements IInventory, IDebuggable + +public abstract class InventoryLogic extends TileEntity implements IInventory { protected ItemStack[] inventory; protected String invName; @@ -103,8 +101,7 @@ public abstract class InventoryLogic extends TileEntity implements IInventory, I @Override public boolean isUseableByPlayer (EntityPlayer entityplayer) { - //getBlockTileEntity - if (getWorld().getTileEntity(xCoord, yCoord, zCoord) != this) + if (worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) return false; else @@ -116,21 +113,21 @@ public abstract class InventoryLogic extends TileEntity implements IInventory, I /* NBT */ @Override - public void writeToNBT (NBTTagCompound tags) + public void readFromNBT (NBTTagCompound tags) { - super.writeToNBT(tags); + super.readFromNBT(tags); readInventoryFromNBT(tags); } public void readInventoryFromNBT (NBTTagCompound tags) { - super.writeToNBT(tags); + super.readFromNBT(tags); this.invName = tags.getString("InvName"); NBTTagList nbttaglist = tags.getTagList("Items", 9); inventory = new ItemStack[getSizeInventory()]; for (int iter = 0; iter < nbttaglist.tagCount(); iter++) { - NBTTagCompound tagList = (NBTTagCompound) nbttaglist.getCompoundTagAt(iter); //TODO tagAt? + NBTTagCompound tagList = (NBTTagCompound) nbttaglist.getCompoundTagAt(iter); byte slotID = tagList.getByte("Slot"); if (slotID >= 0 && slotID < inventory.length) { @@ -140,9 +137,9 @@ public abstract class InventoryLogic extends TileEntity implements IInventory, I } @Override - public void readFromNBT (NBTTagCompound tags) + public void writeToNBT (NBTTagCompound tags) { - super.readFromNBT(tags); + super.writeToNBT(tags); writeInventoryToNBT(tags); } @@ -227,19 +224,4 @@ public abstract class InventoryLogic extends TileEntity implements IInventory, I { } - - public World getWorld () - { - return this.getWorldObj(); - } - - /* IDebuggable */ - @Override - public DebugData getDebugInfo (EntityPlayer player) - { - String[] strs = new String[1]; - strs[0] = "invName: " + invName + ", inventory.length: " + inventory.length + ", stackSizeLimit: " + stackSizeLimit; - return new DebugData(player, getClass(), strs); - } - -} +} \ No newline at end of file diff --git a/src/mantle/blocks/abstracts/MultiServantLogic.java b/src/mantle/blocks/abstracts/MultiServantLogic.java index d41e72b..9083d6b 100644 --- a/src/mantle/blocks/abstracts/MultiServantLogic.java +++ b/src/mantle/blocks/abstracts/MultiServantLogic.java @@ -36,8 +36,8 @@ public class MultiServantLogic extends TileEntity implements IServantLogic, IDeb { if (!hasMaster) return false; - //Minecraft.getMinecraft().getMinecraft().thegetWorld()??? - if (getWorld().getBlock(master.x, master.y, master.z) == masterBlock && getWorld().getBlockMetadata(master.x, master.y, master.z) == masterMeat) + + if (worldObj.getBlock(master.x, master.y, master.z) == masterBlock && worldObj.getBlockMetadata(master.x, master.y, master.z) == masterMeat) return true; else @@ -57,8 +57,8 @@ public class MultiServantLogic extends TileEntity implements IServantLogic, IDeb { hasMaster = true; master = new CoordTuple(x, y, z); - masterBlock = getWorld().getBlock(x, y, z); - masterMeat = (byte) getWorld().getBlockMetadata(x, y, z); + masterBlock = worldObj.getBlock(x, y, z); + masterMeat = (byte) worldObj.getBlockMetadata(x, y, z); } public void removeMaster () @@ -75,8 +75,17 @@ public class MultiServantLogic extends TileEntity implements IServantLogic, IDeb return !hasMaster; } + @Deprecated + public boolean verifyMaster (IMasterLogic logic, int x, int y, int z) + { + if (master.equalCoords(x, y, z) && worldObj.getBlock(x, y, z) == masterBlock && worldObj.getBlockMetadata(x, y, z) == masterMeat) + return true; + else + return false; + } + @Override - public boolean verifyMaster (IMasterLogic logic, World w, int x, int y, int z) + public boolean verifyMaster (IMasterLogic logic, World world, int x, int y, int z) { if (hasMaster) { @@ -100,7 +109,7 @@ public class MultiServantLogic extends TileEntity implements IServantLogic, IDeb { if (hasValidMaster()) { - IMasterLogic logic = (IMasterLogic) getWorld().getTileEntity(master.x, master.y, master.z); + IMasterLogic logic = (IMasterLogic) worldObj.getTileEntity(master.x, master.y, master.z); logic.notifyChange(this, xCoord, yCoord, zCoord); } } @@ -137,7 +146,6 @@ public class MultiServantLogic extends TileEntity implements IServantLogic, IDeb public void readFromNBT (NBTTagCompound tags) { super.readFromNBT(tags); - writeToNBT(tags); readCustomNBT(tags); } @@ -149,13 +157,11 @@ public class MultiServantLogic extends TileEntity implements IServantLogic, IDeb } /* Packets */ - //TODO getDescriptionPacket()?? @Override public Packet getDescriptionPacket () { NBTTagCompound tag = new NBTTagCompound(); writeCustomNBT(tag); - //TODO xCoord, yCoord, zCoord return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag); } @@ -163,8 +169,8 @@ public class MultiServantLogic extends TileEntity implements IServantLogic, IDeb public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet) { readCustomNBT(packet.func_148857_g()); - worldObj.func_147479_m(this.xCoord, this.yCoord, this.zCoord); - getWorld().markBlockForUpdate(xCoord, yCoord, zCoord); + worldObj.func_147479_m(xCoord, yCoord, zCoord); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } /* IDebuggable */ From 69e9e87a33483b59d086d110aa40a5ddfb3305e6 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 14 Feb 2014 15:48:35 -0500 Subject: [PATCH 2/2] Fix me removing stuff. --- src/mantle/blocks/abstracts/InventoryLogic.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/mantle/blocks/abstracts/InventoryLogic.java b/src/mantle/blocks/abstracts/InventoryLogic.java index 96b4cfe..e82ec33 100644 --- a/src/mantle/blocks/abstracts/InventoryLogic.java +++ b/src/mantle/blocks/abstracts/InventoryLogic.java @@ -1,5 +1,7 @@ package mantle.blocks.abstracts; +import mantle.debug.DebugData; +import mantle.debug.IDebuggable; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -16,7 +18,7 @@ import net.minecraft.world.World; * Abstract to avoid instantiation */ -public abstract class InventoryLogic extends TileEntity implements IInventory +public abstract class InventoryLogic extends TileEntity implements IInventory, IDebuggable { protected ItemStack[] inventory; protected String invName; @@ -224,4 +226,13 @@ public abstract class InventoryLogic extends TileEntity implements IInventory { } + + /* IDebuggable */ + @Override + public DebugData getDebugInfo (EntityPlayer player) + { + String[] strs = new String[1]; + strs[0] = "invName: " + invName + ", inventory.length: " + inventory.length + ", stackSizeLimit: " + stackSizeLimit; + return new DebugData(player, getClass(), strs); + } } \ No newline at end of file