diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEAltar.java b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEAltar.java index ff2755eb..13a18fbf 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEAltar.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEAltar.java @@ -36,10 +36,10 @@ import WayofTime.alchemicalWizardry.common.bloodAltarUpgrade.AltarUpgradeCompone import WayofTime.alchemicalWizardry.common.bloodAltarUpgrade.UpgradedAltars; import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper; -public class TEAltar extends TileEntity implements IInventory, IFluidTank, IFluidHandler, IBloodAltar +public class TEAltar extends TEInventory implements IFluidTank, IFluidHandler, IBloodAltar { public static final int sizeInv = 1; - private ItemStack[] inv; + private int resultID; private int resultDamage; private int upgradeLevel; @@ -73,7 +73,7 @@ public class TEAltar extends TileEntity implements IInventory, IFluidTank, IFlui public TEAltar() { - this.inv = new ItemStack[1]; + super(sizeInv); resultID = 0; resultDamage = 0; this.capacity = FluidContainerRegistry.BUCKET_VOLUME * 10; @@ -131,18 +131,6 @@ public class TEAltar extends TileEntity implements IInventory, IFluidTank, IFlui public void readFromNBT(NBTTagCompound par1NBTTagCompound) { super.readFromNBT(par1NBTTagCompound); - NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND); - - for (int i = 0; i < tagList.tagCount(); i++) - { - NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); - int slot = tag.getByte("Slot"); - - if (slot >= 0 && slot < inv.length) - { - inv[slot] = ItemStack.loadItemStackFromNBT(tag); - } - } resultID = par1NBTTagCompound.getInteger("resultID"); resultDamage = par1NBTTagCompound.getInteger("resultDamage"); @@ -214,24 +202,9 @@ public class TEAltar extends TileEntity implements IInventory, IFluidTank, IFlui public void writeToNBT(NBTTagCompound par1NBTTagCompound) { super.writeToNBT(par1NBTTagCompound); - NBTTagList itemList = new NBTTagList(); - - for (int i = 0; i < inv.length; i++) - { - ItemStack stack = inv[i]; - - if (inv[i] != null) - { - NBTTagCompound tag = new NBTTagCompound(); - tag.setByte("Slot", (byte) i); - inv[i].writeToNBT(tag); - itemList.appendTag(tag); - } - } par1NBTTagCompound.setInteger("resultID", resultID); par1NBTTagCompound.setInteger("resultDamage", resultDamage); - par1NBTTagCompound.setTag("Inventory", itemList); if (fluid != null) { @@ -275,101 +248,12 @@ public class TEAltar extends TileEntity implements IInventory, IFluidTank, IFlui par1NBTTagCompound.setInteger("cooldownAfterCrafting", cooldownAfterCrafting); } - @Override - public int getSizeInventory() - { - return inv.length; - } - - @Override - public ItemStack getStackInSlot(int slot) - { - return inv[slot]; - } - - @Override - public ItemStack decrStackSize(int slot, int amt) - { - ItemStack stack = getStackInSlot(slot); - - if (stack != null) - { - if (stack.stackSize <= amt) - { - setInventorySlotContents(slot, null); - } else - { - stack = stack.splitStack(amt); - - if (stack.stackSize == 0) - { - setInventorySlotContents(slot, null); - } - } - } - - return stack; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) - { - ItemStack stack = getStackInSlot(slot); - - if (stack != null) - { - setInventorySlotContents(slot, null); - } - - return stack; - } - - @Override - public void setInventorySlotContents(int slot, ItemStack itemStack) - { - inv[slot] = itemStack; - this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - - if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) - { - itemStack.stackSize = getInventoryStackLimit(); - } - } - @Override public String getInventoryName() { return "TEAltar"; } - @Override - public boolean hasCustomInventoryName() - { - return false; - } - - @Override - public int getInventoryStackLimit() - { - return 64; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityPlayer) - { - return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && entityPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; - } - - @Override - public void openInventory() - { - } - - @Override - public void closeInventory() - { - } - //IFluidTank methods @Override public FluidStack getFluid() @@ -679,97 +563,94 @@ public class TEAltar extends TileEntity implements IInventory, IFluidTank, IFlui return; } - if (worldTime % 1 == 0) + if (!canBeFilled) { - if (!canBeFilled) + if (fluid != null && fluid.amount >= 1) { - if (fluid != null && fluid.amount >= 1) + int stackSize = getStackInSlot(0).stackSize; + int liquidDrained = Math.min((int) (upgradeLevel >= 2 ? consumptionRate * (1 + consumptionMultiplier) : consumptionRate), fluid.amount); + + if (liquidDrained > (liquidRequired * stackSize - progress)) { - int stackSize = getStackInSlot(0).stackSize; - int liquidDrained = Math.min((int) (upgradeLevel >= 2 ? consumptionRate * (1 + consumptionMultiplier) : consumptionRate), fluid.amount); - - if (liquidDrained > (liquidRequired * stackSize - progress)) - { - liquidDrained = liquidRequired * stackSize - progress; - } - - fluid.amount = fluid.amount - liquidDrained; - progress += liquidDrained; - - if (worldTime % 4 == 0) - { - SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord); - } - - if (progress >= liquidRequired * stackSize) - { - ItemStack result = null; - result = AltarRecipeRegistry.getItemForItemAndTier(this.getStackInSlot(0), this.upgradeLevel); - if (result != null) - { - result.stackSize *= stackSize; - } - - setInventorySlotContents(0, result); - progress = 0; - - for (int i = 0; i < 8; i++) - { - SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 4, xCoord + 0.5f, yCoord + 1.0f, zCoord + 0.5f); - } - this.isActive = false; - } - } else if (progress > 0) - { - progress -= (int) (efficiencyMultiplier * drainRate); - - if (worldTime % 2 == 0) - { - SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 2, xCoord, yCoord, zCoord); - } + liquidDrained = liquidRequired * stackSize - progress; } - } else + + fluid.amount = fluid.amount - liquidDrained; + progress += liquidDrained; + + if (worldTime % 4 == 0) + { + SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord); + } + + if (progress >= liquidRequired * stackSize) + { + ItemStack result = null; + result = AltarRecipeRegistry.getItemForItemAndTier(this.getStackInSlot(0), this.upgradeLevel); + if (result != null) + { + result.stackSize *= stackSize; + } + + setInventorySlotContents(0, result); + progress = 0; + + for (int i = 0; i < 8; i++) + { + SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 4, xCoord + 0.5f, yCoord + 1.0f, zCoord + 0.5f); + } + this.isActive = false; + } + } else if (progress > 0) { - ItemStack returnedItem = getStackInSlot(0); + progress -= (int) (efficiencyMultiplier * drainRate); - if (!(returnedItem.getItem() instanceof IBloodOrb)) + if (worldTime % 2 == 0) { - return; - } - - IBloodOrb item = (IBloodOrb) (returnedItem.getItem()); - NBTTagCompound itemTag = returnedItem.getTagCompound(); - - if (itemTag == null) - { - return; - } - - String ownerName = itemTag.getString("ownerName"); - - if (ownerName.equals("")) - { - return; - } - - if (fluid != null && fluid.amount >= 1) - { - int liquidDrained = Math.min((int) (upgradeLevel >= 2 ? consumptionRate * (1 + consumptionMultiplier) : consumptionRate), fluid.amount); - - int drain = SoulNetworkHandler.addCurrentEssenceToMaximum(ownerName, liquidDrained, (int) (item.getMaxEssence() * this.orbCapacityMultiplier)); - - fluid.amount = fluid.amount - drain; - - if (worldTime % 4 == 0) - { - SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 3, xCoord, yCoord, zCoord); - } + SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 2, xCoord, yCoord, zCoord); } } - if (worldObj != null) + } else + { + ItemStack returnedItem = getStackInSlot(0); + + if (!(returnedItem.getItem() instanceof IBloodOrb)) { - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + return; } + + IBloodOrb item = (IBloodOrb) (returnedItem.getItem()); + NBTTagCompound itemTag = returnedItem.getTagCompound(); + + if (itemTag == null) + { + return; + } + + String ownerName = itemTag.getString("ownerName"); + + if (ownerName.equals("")) + { + return; + } + + if (fluid != null && fluid.amount >= 1) + { + int liquidDrained = Math.min((int) (upgradeLevel >= 2 ? consumptionRate * (1 + consumptionMultiplier) : consumptionRate), fluid.amount); + + int drain = SoulNetworkHandler.addCurrentEssenceToMaximum(ownerName, liquidDrained, (int) (item.getMaxEssence() * this.orbCapacityMultiplier)); + + fluid.amount = fluid.amount - drain; + + if (worldTime % 4 == 0) + { + SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 3, xCoord, yCoord, zCoord); + } + } + } + if (worldObj != null) + { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEInventory.java b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEInventory.java new file mode 100644 index 00000000..27a9bbb3 --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEInventory.java @@ -0,0 +1,153 @@ +package WayofTime.alchemicalWizardry.common.tileEntity; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.Constants; + +/** + * Base class for tile entities with inventory + * @author ljfa-ag + */ +public abstract class TEInventory extends TileEntity implements IInventory +{ + protected ItemStack[] inv; + + public TEInventory(int size) + { + inv = new ItemStack[size]; + } + + @Override + public int getSizeInventory() + { + return inv.length; + } + + public ItemStack[] getSlots() + { + return inv; + } + + @Override + public ItemStack getStackInSlot(int slot) + { + return inv[slot]; + } + + @Override + public ItemStack decrStackSize(int slot, int amt) + { + ItemStack stack = getStackInSlot(slot); + if (stack != null) + { + if (stack.stackSize <= amt) + setInventorySlotContents(slot, null); + else + { + stack = stack.splitStack(amt); + if (stack.stackSize == 0) + setInventorySlotContents(slot, null); + } + } + return stack; + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) + { + ItemStack stack = getStackInSlot(slot); + if (stack != null) + setInventorySlotContents(slot, null); + return stack; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack stack) + { + inv[slot] = stack; + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + if (stack != null && stack.stackSize > getInventoryStackLimit()) + stack.stackSize = getInventoryStackLimit(); + } + + @Override + public abstract String getInventoryName(); + + @Override + public boolean hasCustomInventoryName() + { + return false; + } + + @Override + public int getInventoryStackLimit() + { + return 64; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer player) + { + return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this + && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; + } + + @Override + public void openInventory() + { + } + + @Override + public void closeInventory() + { + } + + @Override + public boolean isItemValidForSlot(int slot, ItemStack stack) + { + return true; + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT(tag); + NBTTagList invList = new NBTTagList(); + for (int i = 0; i < inv.length; i++) + { + if (inv[i] != null) + { + NBTTagCompound stackTag = new NBTTagCompound(); + stackTag.setByte("Slot", (byte) i); + inv[i].writeToNBT(stackTag); + invList.appendTag(stackTag); + } + } + + tag.setTag("Inventory", invList); + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT(tag); + NBTTagList invList = tag.getTagList("Inventory", Constants.NBT.TAG_COMPOUND); + for(int i = 0; i < invList.tagCount(); i++) + { + NBTTagCompound stackTag = invList.getCompoundTagAt(i); + int slot = stackTag.getByte("Slot"); + + if(slot >= 0 && slot < inv.length) + inv[slot] = ItemStack.loadItemStackFromNBT(stackTag); + } + } + + public void clear() + { + inv = new ItemStack[inv.length]; + } +} diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEPedestal.java b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEPedestal.java index a6ce9b1f..dcb522f3 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEPedestal.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEPedestal.java @@ -13,18 +13,18 @@ import net.minecraft.network.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.Constants; -public class TEPedestal extends TileEntity implements IInventory +public class TEPedestal extends TEInventory { - private ItemStack[] inv; + public static final int sizeInv = 1; + private int resultID; private int resultDamage; - public static final int sizeInv = 1; private boolean isActive; public TEPedestal() { - this.inv = new ItemStack[1]; + super(sizeInv); resultID = 0; resultDamage = 0; isActive = false; @@ -34,18 +34,6 @@ public class TEPedestal extends TileEntity implements IInventory public void readFromNBT(NBTTagCompound par1NBTTagCompound) { super.readFromNBT(par1NBTTagCompound); - NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND); - - for (int i = 0; i < tagList.tagCount(); i++) - { - NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); - int slot = tag.getByte("Slot"); - - if (slot >= 0 && slot < inv.length) - { - inv[slot] = ItemStack.loadItemStackFromNBT(tag); - } - } resultID = par1NBTTagCompound.getInteger("resultID"); resultDamage = par1NBTTagCompound.getInteger("resultDamage"); @@ -56,121 +44,24 @@ public class TEPedestal extends TileEntity implements IInventory public void writeToNBT(NBTTagCompound par1NBTTagCompound) { super.writeToNBT(par1NBTTagCompound); - NBTTagList itemList = new NBTTagList(); - - for (int i = 0; i < inv.length; i++) - { - ItemStack stack = inv[i]; - - if (inv[i] != null) - { - NBTTagCompound tag = new NBTTagCompound(); - tag.setByte("Slot", (byte) i); - inv[i].writeToNBT(tag); - itemList.appendTag(tag); - } - } par1NBTTagCompound.setInteger("resultID", resultID); par1NBTTagCompound.setInteger("resultDamage", resultDamage); - par1NBTTagCompound.setTag("Inventory", itemList); par1NBTTagCompound.setBoolean("isActive", isActive); } - @Override - public int getSizeInventory() - { - return 1; - } - - @Override - public ItemStack getStackInSlot(int slot) - { - return inv[slot]; - } - - @Override - public ItemStack decrStackSize(int slot, int amt) - { - ItemStack stack = getStackInSlot(slot); - - if (stack != null) - { - if (stack.stackSize <= amt) - { - setInventorySlotContents(slot, null); - } else - { - stack = stack.splitStack(amt); - - if (stack.stackSize == 0) - { - setInventorySlotContents(slot, null); - } - } - } - - return stack; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) - { - ItemStack stack = getStackInSlot(slot); - - if (stack != null) - { - setInventorySlotContents(slot, null); - } - - return stack; - } - - @Override - public void setInventorySlotContents(int slot, ItemStack itemStack) - { - inv[slot] = itemStack; - - if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) - { - itemStack.stackSize = getInventoryStackLimit(); - } - } - @Override public String getInventoryName() { return "TEPedestal"; } - @Override - public boolean hasCustomInventoryName() - { - return false; - } - @Override public int getInventoryStackLimit() { return 1; } - @Override - public boolean isUseableByPlayer(EntityPlayer entityPlayer) - { - return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && entityPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; - } - - @Override - public void openInventory() - { - } - - @Override - public void closeInventory() - { - } - //Logic for the actual block is under here @Override public void updateEntity() @@ -243,12 +134,7 @@ public class TEPedestal extends TileEntity implements IInventory @Override public boolean isItemValidForSlot(int slot, ItemStack itemstack) { - if (slot == 0) - { - return true; - } - - return false; + return slot == 0; } public void onItemDeletion() diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEPlinth.java b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEPlinth.java index 9ec79ee4..138e12db 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEPlinth.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEPlinth.java @@ -22,9 +22,9 @@ import net.minecraftforge.oredict.OreDictionary; import java.util.ArrayList; import java.util.List; -public class TEPlinth extends TileEntity implements IInventory +public class TEPlinth extends TEInventory { - private ItemStack[] inv; + public static final int sizeInv = 1; private boolean isActive; private boolean paradigm; @@ -33,8 +33,6 @@ public class TEPlinth extends TileEntity implements IInventory private ItemStack[] ring2Inv; private ItemStack[] ring3Inv; - public static final int sizeInv = 1; - private int progressInterval; private int progress; @@ -42,7 +40,7 @@ public class TEPlinth extends TileEntity implements IInventory public TEPlinth() { - this.inv = new ItemStack[1]; + super(sizeInv); this.ring1Inv = new ItemStack[6]; this.ring2Inv = new ItemStack[6]; this.ring3Inv = new ItemStack[6]; @@ -55,18 +53,6 @@ public class TEPlinth extends TileEntity implements IInventory public void readFromNBT(NBTTagCompound par1NBTTagCompound) { super.readFromNBT(par1NBTTagCompound); - NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND); - - for (int i = 0; i < tagList.tagCount(); i++) - { - NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); - int slot = tag.getByte("Slot"); - - if (slot >= 0 && slot < inv.length) - { - inv[slot] = ItemStack.loadItemStackFromNBT(tag); - } - } NBTTagList ring1TagList = par1NBTTagCompound.getTagList("ring1Inv", Constants.NBT.TAG_COMPOUND); @@ -116,22 +102,7 @@ public class TEPlinth extends TileEntity implements IInventory public void writeToNBT(NBTTagCompound par1NBTTagCompound) { super.writeToNBT(par1NBTTagCompound); - NBTTagList itemList = new NBTTagList(); - for (int i = 0; i < inv.length; i++) - { - ItemStack stack = inv[i]; - - if (inv[i] != null) - { - NBTTagCompound tag = new NBTTagCompound(); - tag.setByte("Slot", (byte) i); - inv[i].writeToNBT(tag); - itemList.appendTag(tag); - } - } - - par1NBTTagCompound.setTag("Inventory", itemList); NBTTagList ring1ItemList = new NBTTagList(); for (int i = 0; i < ring1Inv.length; i++) @@ -185,100 +156,18 @@ public class TEPlinth extends TileEntity implements IInventory par1NBTTagCompound.setBoolean("isActive", isActive); } - @Override - public int getSizeInventory() - { - return 1; - } - - @Override - public ItemStack getStackInSlot(int slot) - { - return inv[slot]; - } - - @Override - public ItemStack decrStackSize(int slot, int amt) - { - ItemStack stack = getStackInSlot(slot); - - if (stack != null) - { - if (stack.stackSize <= amt) - { - setInventorySlotContents(slot, null); - } else - { - stack = stack.splitStack(amt); - - if (stack.stackSize == 0) - { - setInventorySlotContents(slot, null); - } - } - } - - return stack; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) - { - ItemStack stack = getStackInSlot(slot); - - if (stack != null) - { - setInventorySlotContents(slot, null); - } - - return stack; - } - - @Override - public void setInventorySlotContents(int slot, ItemStack itemStack) - { - inv[slot] = itemStack; - - if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) - { - itemStack.stackSize = getInventoryStackLimit(); - } - } - @Override public String getInventoryName() { return "TEPlinth"; } - @Override - public boolean hasCustomInventoryName() - { - return false; - } - @Override public int getInventoryStackLimit() { return 1; } - @Override - public boolean isUseableByPlayer(EntityPlayer entityPlayer) - { - return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && entityPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; - } - - @Override - public void openInventory() - { - } - - @Override - public void closeInventory() - { - } - //Logic for the actual block is under here @Override public void updateEntity() @@ -654,12 +543,7 @@ public class TEPlinth extends TileEntity implements IInventory @Override public boolean isItemValidForSlot(int slot, ItemStack itemstack) { - if (slot == 0) - { - return true; - } - - return false; + return slot == 0; } public static void initialize() diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TESocket.java b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TESocket.java index ca107fcd..b4047d94 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TESocket.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TESocket.java @@ -1,5 +1,6 @@ package WayofTime.alchemicalWizardry.common.tileEntity; +import WayofTime.alchemicalWizardry.api.items.interfaces.ArmourUpgrade; import WayofTime.alchemicalWizardry.common.NewPacketHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -11,19 +12,18 @@ import net.minecraft.network.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.Constants; -public class TESocket extends TileEntity implements IInventory +public class TESocket extends TEInventory { - private ItemStack[] inv; + public static final int sizeInv = 1; + private int resultID; private int resultDamage; - public static final int sizeInv = 1; - private boolean isActive; public TESocket() { - this.inv = new ItemStack[1]; + super(sizeInv); resultID = 0; resultDamage = 0; isActive = false; @@ -33,18 +33,6 @@ public class TESocket extends TileEntity implements IInventory public void readFromNBT(NBTTagCompound par1NBTTagCompound) { super.readFromNBT(par1NBTTagCompound); - NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND); - - for (int i = 0; i < tagList.tagCount(); i++) - { - NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); - int slot = tag.getByte("Slot"); - - if (slot >= 0 && slot < inv.length) - { - inv[slot] = ItemStack.loadItemStackFromNBT(tag); - } - } resultID = par1NBTTagCompound.getInteger("resultID"); resultDamage = par1NBTTagCompound.getInteger("resultDamage"); @@ -55,121 +43,24 @@ public class TESocket extends TileEntity implements IInventory public void writeToNBT(NBTTagCompound par1NBTTagCompound) { super.writeToNBT(par1NBTTagCompound); - NBTTagList itemList = new NBTTagList(); - - for (int i = 0; i < inv.length; i++) - { - ItemStack stack = inv[i]; - - if (inv[i] != null) - { - NBTTagCompound tag = new NBTTagCompound(); - tag.setByte("Slot", (byte) i); - inv[i].writeToNBT(tag); - itemList.appendTag(tag); - } - } par1NBTTagCompound.setInteger("resultID", resultID); par1NBTTagCompound.setInteger("resultDamage", resultDamage); - par1NBTTagCompound.setTag("Inventory", itemList); par1NBTTagCompound.setBoolean("isActive", isActive); } - @Override - public int getSizeInventory() - { - return 1; - } - - @Override - public ItemStack getStackInSlot(int slot) - { - return inv[slot]; - } - - @Override - public ItemStack decrStackSize(int slot, int amt) - { - ItemStack stack = getStackInSlot(slot); - - if (stack != null) - { - if (stack.stackSize <= amt) - { - setInventorySlotContents(slot, null); - } else - { - stack = stack.splitStack(amt); - - if (stack.stackSize == 0) - { - setInventorySlotContents(slot, null); - } - } - } - - return stack; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) - { - ItemStack stack = getStackInSlot(slot); - - if (stack != null) - { - setInventorySlotContents(slot, null); - } - - return stack; - } - - @Override - public void setInventorySlotContents(int slot, ItemStack itemStack) - { - inv[slot] = itemStack; - - if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) - { - itemStack.stackSize = getInventoryStackLimit(); - } - } - @Override public String getInventoryName() { return "TESocket"; } - @Override - public boolean hasCustomInventoryName() - { - return false; - } - @Override public int getInventoryStackLimit() { return 1; } - @Override - public boolean isUseableByPlayer(EntityPlayer entityPlayer) - { - return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && entityPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; - } - - @Override - public void openInventory() - { - } - - @Override - public void closeInventory() - { - } - //Logic for the actual block is under here @Override public void updateEntity() @@ -242,11 +133,6 @@ public class TESocket extends TileEntity implements IInventory @Override public boolean isItemValidForSlot(int slot, ItemStack itemstack) { - if (slot == 0) - { - return true; - } - - return false; + return itemstack.getItem() instanceof ArmourUpgrade; } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TETeleposer.java b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TETeleposer.java index f72a24e8..7be849ae 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TETeleposer.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TETeleposer.java @@ -20,20 +20,19 @@ import net.minecraftforge.common.util.Constants; import java.util.Iterator; import java.util.List; -public class TETeleposer extends TileEntity implements IInventory +public class TETeleposer extends TEInventory { - private ItemStack[] inv; + public static final int sizeInv = 1; + private int resultID; private int resultDamage; private int previousInput; - public static final int sizeInv = 1; - private boolean isActive; public TETeleposer() { - this.inv = new ItemStack[1]; + super(sizeInv); resultID = 0; resultDamage = 0; isActive = false; @@ -44,18 +43,6 @@ public class TETeleposer extends TileEntity implements IInventory public void readFromNBT(NBTTagCompound par1NBTTagCompound) { super.readFromNBT(par1NBTTagCompound); - NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND); - - for (int i = 0; i < tagList.tagCount(); i++) - { - NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); - int slot = tag.getByte("Slot"); - - if (slot >= 0 && slot < inv.length) - { - inv[slot] = ItemStack.loadItemStackFromNBT(tag); - } - } resultID = par1NBTTagCompound.getInteger("resultID"); resultDamage = par1NBTTagCompound.getInteger("resultDamage"); @@ -67,122 +54,25 @@ public class TETeleposer extends TileEntity implements IInventory public void writeToNBT(NBTTagCompound par1NBTTagCompound) { super.writeToNBT(par1NBTTagCompound); - NBTTagList itemList = new NBTTagList(); - - for (int i = 0; i < inv.length; i++) - { - ItemStack stack = inv[i]; - - if (inv[i] != null) - { - NBTTagCompound tag = new NBTTagCompound(); - tag.setByte("Slot", (byte) i); - inv[i].writeToNBT(tag); - itemList.appendTag(tag); - } - } par1NBTTagCompound.setInteger("resultID", resultID); par1NBTTagCompound.setInteger("resultDamage", resultDamage); - par1NBTTagCompound.setTag("Inventory", itemList); par1NBTTagCompound.setBoolean("isActive", isActive); par1NBTTagCompound.setInteger("previousInput", previousInput); } - @Override - public int getSizeInventory() - { - return 1; - } - - @Override - public ItemStack getStackInSlot(int slot) - { - return inv[slot]; - } - - @Override - public ItemStack decrStackSize(int slot, int amt) - { - ItemStack stack = getStackInSlot(slot); - - if (stack != null) - { - if (stack.stackSize <= amt) - { - setInventorySlotContents(slot, null); - } else - { - stack = stack.splitStack(amt); - - if (stack.stackSize == 0) - { - setInventorySlotContents(slot, null); - } - } - } - - return stack; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) - { - ItemStack stack = getStackInSlot(slot); - - if (stack != null) - { - setInventorySlotContents(slot, null); - } - - return stack; - } - - @Override - public void setInventorySlotContents(int slot, ItemStack itemStack) - { - inv[slot] = itemStack; - - if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) - { - itemStack.stackSize = getInventoryStackLimit(); - } - } - @Override public String getInventoryName() { return "TETeleposer"; } - @Override - public boolean hasCustomInventoryName() - { - return false; - } - @Override public int getInventoryStackLimit() { return 1; } - @Override - public boolean isUseableByPlayer(EntityPlayer entityPlayer) - { - return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && entityPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; - } - - @Override - public void openInventory() - { - } - - @Override - public void closeInventory() - { - } - //Logic for the actual block is under here @Override public void updateEntity() @@ -355,12 +245,7 @@ public class TETeleposer extends TileEntity implements IInventory @Override public boolean isItemValidForSlot(int slot, ItemStack itemstack) { - if (slot == 0) - { - return true; - } - - return false; + return itemstack.getItem() instanceof TelepositionFocus; } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEWritingTable.java b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEWritingTable.java index bfed9fa4..628d8171 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEWritingTable.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEWritingTable.java @@ -27,120 +27,25 @@ import WayofTime.alchemicalWizardry.common.alchemy.ICombinationalCatalyst; import WayofTime.alchemicalWizardry.common.items.potion.AlchemyFlask; import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper; -public class TEWritingTable extends TileEntity implements IInventory, ISidedInventory +public class TEWritingTable extends TEInventory implements ISidedInventory { - private ItemStack[] inv; + public static final int sizeInv = 7; + private int progress; private int progressNeeded = 100; private int amountUsed; private int accelerationTime; - public static final int sizeInv = 7; - public TEWritingTable() { - inv = new ItemStack[7]; - } - - @Override - public int getSizeInventory() - { - return inv.length; - } - - @Override - public ItemStack getStackInSlot(int slot) - { - return inv[slot]; - } - - @Override - public void setInventorySlotContents(int slot, ItemStack stack) - { - inv[slot] = stack; - - if (stack != null && stack.stackSize > getInventoryStackLimit()) - { - stack.stackSize = getInventoryStackLimit(); - } - } - - @Override - public ItemStack decrStackSize(int slot, int amt) - { - ItemStack stack = getStackInSlot(slot); - - if (stack != null) - { - if (stack.stackSize <= amt) - { - setInventorySlotContents(slot, null); - } else - { - stack = stack.splitStack(amt); - - if (stack.stackSize == 0) - { - setInventorySlotContents(slot, null); - } - } - } - - return stack; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) - { - ItemStack stack = getStackInSlot(slot); - - if (stack != null) - { - setInventorySlotContents(slot, null); - } - - return stack; - } - - @Override - public int getInventoryStackLimit() - { - return 64; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer player) - { - return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; - } - - @Override - public void openInventory() - { - } - - @Override - public void closeInventory() - { + super(sizeInv); } @Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); - NBTTagList tagList = tagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND); - - for (int i = 0; i < tagList.tagCount(); i++) - { - NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); - byte slot = tag.getByte("Slot"); - - if (slot >= 0 && slot < inv.length) - { - inv[slot] = ItemStack.loadItemStackFromNBT(tag); - } - } progress = tagCompound.getInteger("progress"); amountUsed = tagCompound.getInteger("amountUsed"); @@ -152,22 +57,7 @@ public class TEWritingTable extends TileEntity implements IInventory, ISidedInve public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); - NBTTagList itemList = new NBTTagList(); - - for (int i = 0; i < inv.length; i++) - { - ItemStack stack = inv[i]; - - if (stack != null) - { - NBTTagCompound tag = new NBTTagCompound(); - tag.setByte("Slot", (byte) i); - stack.writeToNBT(tag); - itemList.appendTag(tag); - } - } - - tagCompound.setTag("Inventory", itemList); + tagCompound.setInteger("progress", progress); tagCompound.setInteger("amountUsed", amountUsed); @@ -180,12 +70,6 @@ public class TEWritingTable extends TileEntity implements IInventory, ISidedInve return "aw.TEWritingTable"; } - @Override - public boolean hasCustomInventoryName() - { - return false; - } - @Override public boolean isItemValidForSlot(int i, ItemStack itemstack) {