diff options
author | draknyte1 <draknyte1@hotmail.com> | 2016-11-04 15:23:26 +1000 |
---|---|---|
committer | draknyte1 <draknyte1@hotmail.com> | 2016-11-04 15:23:26 +1000 |
commit | 0669f5eb9d5029a8b94ec552171b0837605f7747 (patch) | |
tree | 6b40e64c04d51b7a33cf2f0b35f7232cf37c4247 /src/Java/gtPlusPlus/core/inventories | |
parent | 3654052fb63a571c5eaca7f20714b87c17f7e966 (diff) | |
download | GT5-Unofficial-0669f5eb9d5029a8b94ec552171b0837605f7747.tar.gz GT5-Unofficial-0669f5eb9d5029a8b94ec552171b0837605f7747.tar.bz2 GT5-Unofficial-0669f5eb9d5029a8b94ec552171b0837605f7747.zip |
$ Cleaned up the entire project.
> Much neat, very nices.
Diffstat (limited to 'src/Java/gtPlusPlus/core/inventories')
7 files changed, 791 insertions, 938 deletions
diff --git a/src/Java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java b/src/Java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java index 3513e34a63..64e7c9cef5 100644 --- a/src/Java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java +++ b/src/Java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java @@ -10,40 +10,44 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraftforge.common.util.Constants; -public class BaseInventoryBackpack implements IInventory{ +public class BaseInventoryBackpack implements IInventory { - private String name = "Inventory Item"; + /** Defining your inventory size this way is handy */ + public static final int INV_SIZE = 8; - /** Provides NBT Tag Compound to reference */ - private final ItemStack invItem; + private final String name = "Inventory Item"; - /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 8; + /** Provides NBT Tag Compound to reference */ + private final ItemStack invItem; - /** Inventory's size must be same as number of slots you add to the Container class */ - private ItemStack[] inventory = new ItemStack[INV_SIZE]; + /** + * Inventory's size must be same as number of slots you add to the Container + * class + */ + private final ItemStack[] inventory = new ItemStack[BaseInventoryBackpack.INV_SIZE]; // declaration of variable: - protected String uniqueID; + protected String uniqueID; /** - * @param itemstack - the ItemStack to which this inventory belongs + * @param itemstack + * - the ItemStack to which this inventory belongs */ - public BaseInventoryBackpack(ItemStack stack) - { - invItem = stack; + public BaseInventoryBackpack(final ItemStack stack) { + this.invItem = stack; /** initialize variable within the constructor: */ - uniqueID = ""; + this.uniqueID = ""; - if (!stack.hasTagCompound()) - { + if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); - // no tag compound means the itemstack does not yet have a UUID, so assign one: - uniqueID = UUID.randomUUID().toString(); - } - - // Create a new NBT Tag Compound if one doesn't already exist, or you will crash + // no tag compound means the itemstack does not yet have a UUID, so + // assign one: + this.uniqueID = UUID.randomUUID().toString(); + } + + // Create a new NBT Tag Compound if one doesn't already exist, or you + // will crash if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } @@ -52,189 +56,175 @@ public class BaseInventoryBackpack implements IInventory{ // either reference will change in the other // Read the inventory contents from NBT - readFromNBT(stack.getTagCompound()); - } - @Override - public int getSizeInventory() - { - return inventory.length; + this.readFromNBT(stack.getTagCompound()); } + // 1.7.2+ renamed to closeInventory(EntityPlayer player) @Override - public ItemStack getStackInSlot(int slot) - { - return inventory[slot]; + public void closeInventory() { } @Override - public ItemStack decrStackSize(int slot, int amount) - { - ItemStack stack = getStackInSlot(slot); - if(stack != null) - { - if(stack.stackSize > amount) - { + public ItemStack decrStackSize(final int slot, final int amount) { + ItemStack stack = this.getStackInSlot(slot); + if (stack != null) { + if (stack.stackSize > amount) { stack = stack.splitStack(amount); // Don't forget this line or your inventory will not be saved! - markDirty(); + this.markDirty(); } - else - { - // this method also calls markDirty, so we don't need to call it again - setInventorySlotContents(slot, null); + else { + // this method also calls markDirty, so we don't need to call it + // again + this.setInventorySlotContents(slot, null); } } return stack; } + // 1.7.2+ renamed to getInventoryName @Override - public ItemStack getStackInSlotOnClosing(int slot) - { - ItemStack stack = getStackInSlot(slot); - setInventorySlotContents(slot, null); - return stack; + public String getInventoryName() { + return this.name; } @Override - public void setInventorySlotContents(int slot, ItemStack stack) - { - inventory[slot] = stack; - - if (stack != null && stack.stackSize > getInventoryStackLimit()) - { - stack.stackSize = getInventoryStackLimit(); - } + public int getInventoryStackLimit() { + return 64; + } - // Don't forget this line or your inventory will not be saved! - markDirty(); + @Override + public int getSizeInventory() { + return this.inventory.length; } - // 1.7.2+ renamed to getInventoryName @Override - public String getInventoryName() - { - return name; + public ItemStack getStackInSlot(final int slot) { + return this.inventory[slot]; } - // 1.7.2+ renamed to hasCustomInventoryName @Override - public boolean hasCustomInventoryName() - { - return name.length() > 0; + public ItemStack getStackInSlotOnClosing(final int slot) { + final ItemStack stack = this.getStackInSlot(slot); + this.setInventorySlotContents(slot, null); + return stack; } + // 1.7.2+ renamed to hasCustomInventoryName @Override - public int getInventoryStackLimit() - { - return 64; + public boolean hasCustomInventoryName() { + return this.name.length() > 0; } /** - * This is the method that will handle saving the inventory contents, as it is called (or should be called!) - * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also - * let you change things in your inventory without ever opening a Gui, if you want. + * This method doesn't seem to do what it claims to do, as items can still + * be left-clicked and placed in the inventory even when this returns false */ - // 1.7.2+ renamed to markDirty @Override - public void markDirty() - { - for (int i = 0; i < getSizeInventory(); ++i) - { - if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) { - inventory[i] = null; - } - } - - // This line here does the work: - writeToNBT(invItem.getTagCompound()); + public boolean isItemValidForSlot(final int slot, final ItemStack itemstack) { + // Don't want to be able to store the inventory item within itself + // Bad things will happen, like losing your inventory + // Actually, this needs a custom Slot to work + return !(itemstack.getItem() instanceof BaseItemBackpack); } @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) - { + public boolean isUseableByPlayer(final EntityPlayer entityplayer) { return true; } - // 1.7.2+ renamed to openInventory(EntityPlayer player) + /** + * This is the method that will handle saving the inventory contents, as it + * is called (or should be called!) anytime the inventory changes. Perfect. + * Much better than using onUpdate in an Item, as this will also let you + * change things in your inventory without ever opening a Gui, if you want. + */ + // 1.7.2+ renamed to markDirty @Override - public void openInventory() {} + public void markDirty() { + for (int i = 0; i < this.getSizeInventory(); ++i) { + if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0) { + this.inventory[i] = null; + } + } - // 1.7.2+ renamed to closeInventory(EntityPlayer player) - @Override - public void closeInventory() {} + // This line here does the work: + this.writeToNBT(this.invItem.getTagCompound()); + } - /** - * This method doesn't seem to do what it claims to do, as - * items can still be left-clicked and placed in the inventory - * even when this returns false - */ + // 1.7.2+ renamed to openInventory(EntityPlayer player) @Override - public boolean isItemValidForSlot(int slot, ItemStack itemstack) - { - // Don't want to be able to store the inventory item within itself - // Bad things will happen, like losing your inventory - // Actually, this needs a custom Slot to work - return !(itemstack.getItem() instanceof BaseItemBackpack); + public void openInventory() { } /** * A custom method to read our inventory from an ItemStack's NBT compound */ - public void readFromNBT(NBTTagCompound compound) - { + public void readFromNBT(final NBTTagCompound compound) { // Gets the custom taglist we wrote to this compound, if any - // 1.7.2+ change to compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND); - NBTTagList items = compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND); - - if ("".equals(uniqueID)) - { + // 1.7.2+ change to compound.getTagList("ItemInventory", + // Constants.NBT.TAG_COMPOUND); + final NBTTagList items = compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND); + + if ("".equals(this.uniqueID)) { // try to read unique ID from NBT - uniqueID = compound.getString("uniqueID"); + this.uniqueID = compound.getString("uniqueID"); // if it's still "", assign a new one: - if ("".equals(uniqueID)) - { - uniqueID = UUID.randomUUID().toString(); + if ("".equals(this.uniqueID)) { + this.uniqueID = UUID.randomUUID().toString(); } } - for (int i = 0; i < items.tagCount(); ++i) - { + for (int i = 0; i < items.tagCount(); ++i) { // 1.7.2+ change to items.getCompoundTagAt(i) - NBTTagCompound item = (NBTTagCompound) items.getCompoundTagAt(i); - int slot = item.getInteger("Slot"); + final NBTTagCompound item = items.getCompoundTagAt(i); + final int slot = item.getInteger("Slot"); - // Just double-checking that the saved slot index is within our inventory array bounds - if (slot >= 0 && slot < getSizeInventory()) { - inventory[slot] = ItemStack.loadItemStackFromNBT(item); + // Just double-checking that the saved slot index is within our + // inventory array bounds + if (slot >= 0 && slot < this.getSizeInventory()) { + this.inventory[slot] = ItemStack.loadItemStackFromNBT(item); } } } + @Override + public void setInventorySlotContents(final int slot, final ItemStack stack) { + this.inventory[slot] = stack; + + if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { + stack.stackSize = this.getInventoryStackLimit(); + } + + // Don't forget this line or your inventory will not be saved! + this.markDirty(); + } + /** * A custom method to write our inventory to an ItemStack's NBT compound */ - public void writeToNBT(NBTTagCompound tagcompound) - { + public void writeToNBT(final NBTTagCompound tagcompound) { // Create a new NBT Tag List to store itemstacks as NBT Tags - NBTTagList items = new NBTTagList(); + final NBTTagList items = new NBTTagList(); - for (int i = 0; i < getSizeInventory(); ++i) - { + for (int i = 0; i < this.getSizeInventory(); ++i) { // Only write stacks that contain items - if (getStackInSlot(i) != null) - { - // Make a new NBT Tag Compound to write the itemstack and slot index to - NBTTagCompound item = new NBTTagCompound(); + if (this.getStackInSlot(i) != null) { + // Make a new NBT Tag Compound to write the itemstack and slot + // index to + final NBTTagCompound item = new NBTTagCompound(); item.setInteger("Slot", i); - // Writes the itemstack in slot(i) to the Tag Compound we just made - getStackInSlot(i).writeToNBT(item); + // Writes the itemstack in slot(i) to the Tag Compound we just + // made + this.getStackInSlot(i).writeToNBT(item); // add the tag compound to our tag list items.appendTag(item); } } tagcompound.setString("uniqueID", this.uniqueID); - // Add the TagList to the ItemStack's Tag Compound with the name "ItemInventory" + // Add the TagList to the ItemStack's Tag Compound with the name + // "ItemInventory" tagcompound.setTag("ItemInventory", items); } }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchChest.java b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchChest.java index 8d147ad21c..7a3507ec55 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchChest.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchChest.java @@ -6,183 +6,168 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -public class InventoryWorkbenchChest implements IInventory{ - - private String name = "Inventory Chest"; +public class InventoryWorkbenchChest implements IInventory { /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 16; + public static final int INV_SIZE = 16; - /** Inventory's size must be same as number of slots you add to the Container class */ - private ItemStack[] inventory = new ItemStack[INV_SIZE]; + private final String name = "Inventory Chest"; /** - * @param itemstack - the ItemStack to which this inventory belongs + * Inventory's size must be same as number of slots you add to the Container + * class */ - public InventoryWorkbenchChest() - { - - } - - public void readFromNBT(NBTTagCompound nbt) - { - NBTTagList list = nbt.getTagList("Items", 10); - inventory = new ItemStack[INV_SIZE]; - for(int i = 0;i<list.tagCount();i++) - { - NBTTagCompound data = list.getCompoundTagAt(i); - int slot = data.getInteger("Slot"); - if(slot >= 0 && slot < INV_SIZE) - { - inventory[slot] = ItemStack.loadItemStackFromNBT(data); - } - } - } - - public void writeToNBT(NBTTagCompound nbt) - { - NBTTagList list = new NBTTagList(); - for(int i = 0;i<INV_SIZE;i++) - { - ItemStack stack = inventory[i]; - if(stack != null) - { - NBTTagCompound data = new NBTTagCompound(); - stack.writeToNBT(data); - data.setInteger("Slot", i); - list.appendTag(data); - } - } - nbt.setTag("Items", list); - } - - @Override - public int getSizeInventory() - { - return inventory.length; - } - - public ItemStack[] getInventory(){ - return inventory; + private ItemStack[] inventory = new ItemStack[InventoryWorkbenchChest.INV_SIZE]; + + /** + * @param itemstack + * - the ItemStack to which this inventory belongs + */ + public InventoryWorkbenchChest() { + } + // 1.7.2+ renamed to closeInventory(EntityPlayer player) @Override - public ItemStack getStackInSlot(int slot) - { - return inventory[slot]; + public void closeInventory() { } @Override - public ItemStack decrStackSize(int slot, int amount) - { - ItemStack stack = getStackInSlot(slot); - if(stack != null) - { - if(stack.stackSize > amount) - { + public ItemStack decrStackSize(final int slot, final int amount) { + ItemStack stack = this.getStackInSlot(slot); + if (stack != null) { + if (stack.stackSize > amount) { stack = stack.splitStack(amount); // Don't forget this line or your inventory will not be saved! - markDirty(); + this.markDirty(); } - else - { - // this method also calls markDirty, so we don't need to call it again - setInventorySlotContents(slot, null); + else { + // this method also calls markDirty, so we don't need to call it + // again + this.setInventorySlotContents(slot, null); } } return stack; } + public ItemStack[] getInventory() { + return this.inventory; + } + + // 1.7.2+ renamed to getInventoryName @Override - public ItemStack getStackInSlotOnClosing(int slot) - { - ItemStack stack = getStackInSlot(slot); - setInventorySlotContents(slot, null); - return stack; + public String getInventoryName() { + return this.name; } @Override - public void setInventorySlotContents(int slot, ItemStack stack) - { - inventory[slot] = stack; + public int getInventoryStackLimit() { + return 64; + } - if (stack != null && stack.stackSize > getInventoryStackLimit()) - { - stack.stackSize = getInventoryStackLimit(); - } + @Override + public int getSizeInventory() { + return this.inventory.length; + } - // Don't forget this line or your inventory will not be saved! - markDirty(); + @Override + public ItemStack getStackInSlot(final int slot) { + return this.inventory[slot]; } - // 1.7.2+ renamed to getInventoryName @Override - public String getInventoryName() - { - return name; + public ItemStack getStackInSlotOnClosing(final int slot) { + final ItemStack stack = this.getStackInSlot(slot); + this.setInventorySlotContents(slot, null); + return stack; } // 1.7.2+ renamed to hasCustomInventoryName @Override - public boolean hasCustomInventoryName() - { - return name.length() > 0; + public boolean hasCustomInventoryName() { + return this.name.length() > 0; } + /** + * This method doesn't seem to do what it claims to do, as items can still + * be left-clicked and placed in the inventory even when this returns false + */ @Override - public int getInventoryStackLimit() - { - return 64; + public boolean isItemValidForSlot(final int slot, final ItemStack itemstack) { + // Don't want to be able to store the inventory item within itself + // Bad things will happen, like losing your inventory + // Actually, this needs a custom Slot to work + return true; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer entityplayer) { + return true; } /** - * This is the method that will handle saving the inventory contents, as it is called (or should be called!) - * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also - * let you change things in your inventory without ever opening a Gui, if you want. + * This is the method that will handle saving the inventory contents, as it + * is called (or should be called!) anytime the inventory changes. Perfect. + * Much better than using onUpdate in an Item, as this will also let you + * change things in your inventory without ever opening a Gui, if you want. */ // 1.7.2+ renamed to markDirty @Override - public void markDirty() - { - for (int i = 0; i < getSizeInventory(); ++i) - { - ItemStack temp = getStackInSlot(i); - if (temp != null){ - //Utils.LOG_INFO("Slot "+i+" contains "+temp.getDisplayName()+" x"+temp.stackSize); + public void markDirty() { + for (int i = 0; i < this.getSizeInventory(); ++i) { + final ItemStack temp = this.getStackInSlot(i); + if (temp != null) { + // Utils.LOG_INFO("Slot "+i+" contains "+temp.getDisplayName()+" + // x"+temp.stackSize); } - + if (temp != null && temp.stackSize == 0) { - inventory[i] = null; + this.inventory[i] = null; } } } + // 1.7.2+ renamed to openInventory(EntityPlayer player) @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) - { - return true; + public void openInventory() { } - // 1.7.2+ renamed to openInventory(EntityPlayer player) - @Override - public void openInventory() {} + public void readFromNBT(final NBTTagCompound nbt) { + final NBTTagList list = nbt.getTagList("Items", 10); + this.inventory = new ItemStack[InventoryWorkbenchChest.INV_SIZE]; + for (int i = 0; i < list.tagCount(); i++) { + final NBTTagCompound data = list.getCompoundTagAt(i); + final int slot = data.getInteger("Slot"); + if (slot >= 0 && slot < InventoryWorkbenchChest.INV_SIZE) { + this.inventory[slot] = ItemStack.loadItemStackFromNBT(data); + } + } + } - // 1.7.2+ renamed to closeInventory(EntityPlayer player) @Override - public void closeInventory() {} + public void setInventorySlotContents(final int slot, final ItemStack stack) { + this.inventory[slot] = stack; - /** - * This method doesn't seem to do what it claims to do, as - * items can still be left-clicked and placed in the inventory - * even when this returns false - */ - @Override - public boolean isItemValidForSlot(int slot, ItemStack itemstack) - { - // Don't want to be able to store the inventory item within itself - // Bad things will happen, like losing your inventory - // Actually, this needs a custom Slot to work - return true; + if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { + stack.stackSize = this.getInventoryStackLimit(); + } + + // Don't forget this line or your inventory will not be saved! + this.markDirty(); + } + + public void writeToNBT(final NBTTagCompound nbt) { + final NBTTagList list = new NBTTagList(); + for (int i = 0; i < InventoryWorkbenchChest.INV_SIZE; i++) { + final ItemStack stack = this.inventory[i]; + if (stack != null) { + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } + } + nbt.setTag("Items", list); } }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchCrafting.java b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchCrafting.java index 8c0738cab9..ff39d3a241 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchCrafting.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchCrafting.java @@ -6,194 +6,178 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -public class InventoryWorkbenchCrafting implements IInventory{ - - private String name = "Inventory Crafting"; +public class InventoryWorkbenchCrafting implements IInventory { /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 9; + public static final int INV_SIZE = 9; - /** Inventory's size must be same as number of slots you add to the Container class */ - private ItemStack[] inventory = new ItemStack[INV_SIZE]; - public final InventoryCrafting craftMatrix; - public final Container parentContainer; - - public InventoryCrafting getCrafting(){ - return craftMatrix; - } + private final String name = "Inventory Crafting"; + + /** + * Inventory's size must be same as number of slots you add to the Container + * class + */ + private ItemStack[] inventory = new ItemStack[InventoryWorkbenchCrafting.INV_SIZE]; + public final InventoryCrafting craftMatrix; + public final Container parentContainer; /** - * @param itemstack - the ItemStack to which this inventory belongs + * @param itemstack + * - the ItemStack to which this inventory belongs */ - public InventoryWorkbenchCrafting(Container containerR) - { + public InventoryWorkbenchCrafting(final Container containerR) { this.parentContainer = containerR; - this.craftMatrix = new InventoryCrafting(parentContainer, 3, 3); - } - - private ItemStack[] getArrayOfCraftingItems(){ - ItemStack[] array = new ItemStack[9]; - for (int i=0; i<craftMatrix.getSizeInventory();i++){ - if(craftMatrix.getStackInSlot(i) != null){ - array[i] = craftMatrix.getStackInSlot(i); - } - } - return array; - } - - public void readFromNBT(NBTTagCompound nbt) - { - NBTTagList list = nbt.getTagList("Items", 10); - inventory = new ItemStack[INV_SIZE]; - for(int i = 0;i<list.tagCount();i++) - { - NBTTagCompound data = list.getCompoundTagAt(i); - int slot = data.getInteger("Slot"); - if(slot >= 0 && slot < INV_SIZE) - { - getInventory()[slot] = ItemStack.loadItemStackFromNBT(data); - } - } - } - - public void writeToNBT(NBTTagCompound nbt) - { - NBTTagList list = new NBTTagList(); - for(int i = 0;i<INV_SIZE;i++) - { - ItemStack stack = getInventory()[i]; - if(stack != null) - { - NBTTagCompound data = new NBTTagCompound(); - stack.writeToNBT(data); - data.setInteger("Slot", i); - list.appendTag(data); - } - } - nbt.setTag("Items", list); - } - - @Override - public int getSizeInventory() - { - return getInventory().length; - } - - public ItemStack[] getInventory(){ - return getArrayOfCraftingItems(); + this.craftMatrix = new InventoryCrafting(this.parentContainer, 3, 3); } + // 1.7.2+ renamed to closeInventory(EntityPlayer player) @Override - public ItemStack getStackInSlot(int slot) - { - return getInventory()[slot]; + public void closeInventory() { } @Override - public ItemStack decrStackSize(int slot, int amount) - { - ItemStack stack = getStackInSlot(slot); - if(stack != null) - { - if(stack.stackSize > amount) - { + public ItemStack decrStackSize(final int slot, final int amount) { + ItemStack stack = this.getStackInSlot(slot); + if (stack != null) { + if (stack.stackSize > amount) { stack = stack.splitStack(amount); // Don't forget this line or your inventory will not be saved! - markDirty(); + this.markDirty(); } - else - { - // this method also calls markDirty, so we don't need to call it again - setInventorySlotContents(slot, null); + else { + // this method also calls markDirty, so we don't need to call it + // again + this.setInventorySlotContents(slot, null); } } return stack; } + private ItemStack[] getArrayOfCraftingItems() { + final ItemStack[] array = new ItemStack[9]; + for (int i = 0; i < this.craftMatrix.getSizeInventory(); i++) { + if (this.craftMatrix.getStackInSlot(i) != null) { + array[i] = this.craftMatrix.getStackInSlot(i); + } + } + return array; + } + + public InventoryCrafting getCrafting() { + return this.craftMatrix; + } + + public ItemStack[] getInventory() { + return this.getArrayOfCraftingItems(); + } + + // 1.7.2+ renamed to getInventoryName @Override - public ItemStack getStackInSlotOnClosing(int slot) - { - ItemStack stack = getStackInSlot(slot); - setInventorySlotContents(slot, null); - return stack; + public String getInventoryName() { + return this.name; } @Override - public void setInventorySlotContents(int slot, ItemStack stack) - { - getInventory()[slot] = stack; + public int getInventoryStackLimit() { + return 64; + } - if (stack != null && stack.stackSize > getInventoryStackLimit()) - { - stack.stackSize = getInventoryStackLimit(); - } + @Override + public int getSizeInventory() { + return this.getInventory().length; + } - // Don't forget this line or your inventory will not be saved! - markDirty(); + @Override + public ItemStack getStackInSlot(final int slot) { + return this.getInventory()[slot]; } - // 1.7.2+ renamed to getInventoryName @Override - public String getInventoryName() - { - return name; + public ItemStack getStackInSlotOnClosing(final int slot) { + final ItemStack stack = this.getStackInSlot(slot); + this.setInventorySlotContents(slot, null); + return stack; } // 1.7.2+ renamed to hasCustomInventoryName @Override - public boolean hasCustomInventoryName() - { - return name.length() > 0; + public boolean hasCustomInventoryName() { + return this.name.length() > 0; } + /** + * This method doesn't seem to do what it claims to do, as items can still + * be left-clicked and placed in the inventory even when this returns false + */ @Override - public int getInventoryStackLimit() - { - return 64; + public boolean isItemValidForSlot(final int slot, final ItemStack itemstack) { + // Don't want to be able to store the inventory item within itself + // Bad things will happen, like losing your inventory + // Actually, this needs a custom Slot to work + return true; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer entityplayer) { + return true; } /** - * This is the method that will handle saving the inventory contents, as it is called (or should be called!) - * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also - * let you change things in your inventory without ever opening a Gui, if you want. + * This is the method that will handle saving the inventory contents, as it + * is called (or should be called!) anytime the inventory changes. Perfect. + * Much better than using onUpdate in an Item, as this will also let you + * change things in your inventory without ever opening a Gui, if you want. */ // 1.7.2+ renamed to markDirty @Override - public void markDirty() - { - for (int i = 0; i < getSizeInventory(); ++i) - { - if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) { - getInventory()[i] = null; + public void markDirty() { + for (int i = 0; i < this.getSizeInventory(); ++i) { + if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0) { + this.getInventory()[i] = null; } } } + // 1.7.2+ renamed to openInventory(EntityPlayer player) @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) - { - return true; + public void openInventory() { } - // 1.7.2+ renamed to openInventory(EntityPlayer player) - @Override - public void openInventory() {} + public void readFromNBT(final NBTTagCompound nbt) { + final NBTTagList list = nbt.getTagList("Items", 10); + this.inventory = new ItemStack[InventoryWorkbenchCrafting.INV_SIZE]; + for (int i = 0; i < list.tagCount(); i++) { + final NBTTagCompound data = list.getCompoundTagAt(i); + final int slot = data.getInteger("Slot"); + if (slot >= 0 && slot < InventoryWorkbenchCrafting.INV_SIZE) { + this.getInventory()[slot] = ItemStack.loadItemStackFromNBT(data); + } + } + } - // 1.7.2+ renamed to closeInventory(EntityPlayer player) @Override - public void closeInventory() {} + public void setInventorySlotContents(final int slot, final ItemStack stack) { + this.getInventory()[slot] = stack; - /** - * This method doesn't seem to do what it claims to do, as - * items can still be left-clicked and placed in the inventory - * even when this returns false - */ - @Override - public boolean isItemValidForSlot(int slot, ItemStack itemstack) - { - // Don't want to be able to store the inventory item within itself - // Bad things will happen, like losing your inventory - // Actually, this needs a custom Slot to work - return true; + if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { + stack.stackSize = this.getInventoryStackLimit(); + } + + // Don't forget this line or your inventory will not be saved! + this.markDirty(); + } + + public void writeToNBT(final NBTTagCompound nbt) { + final NBTTagList list = new NBTTagList(); + for (int i = 0; i < InventoryWorkbenchCrafting.INV_SIZE; i++) { + final ItemStack stack = this.getInventory()[i]; + if (stack != null) { + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } + } + nbt.setTag("Items", list); } }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java index f4fe78d458..9cfa57ec08 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java @@ -4,161 +4,133 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -public class InventoryWorkbenchHoloCrafting implements IInventory{ - - private String name = "Inventory Crafting"; +public class InventoryWorkbenchHoloCrafting implements IInventory { /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 9; + public static final int INV_SIZE = 9; - /** Inventory's size must be same as number of slots you add to the Container class */ - private ItemStack[] inventory = new ItemStack[INV_SIZE]; + private final String name = "Inventory Crafting"; /** - * @param itemstack - the ItemStack to which this inventory belongs + * Inventory's size must be same as number of slots you add to the Container + * class */ - public InventoryWorkbenchHoloCrafting() - { + private final ItemStack[] inventory = new ItemStack[InventoryWorkbenchHoloCrafting.INV_SIZE]; + + /** + * @param itemstack + * - the ItemStack to which this inventory belongs + */ + public InventoryWorkbenchHoloCrafting() { } - /*public void readFromNBT(NBTTagCompound nbt) - { - NBTTagList list = nbt.getTagList("Items", 10); - inventory = new ItemStack[INV_SIZE]; - for(int i = 0;i<list.tagCount();i++) - { - NBTTagCompound data = list.getCompoundTagAt(i); - int slot = data.getInteger("Slot"); - if(slot >= 0 && slot < INV_SIZE) - { - inventory[slot] = ItemStack.loadItemStackFromNBT(data); - } - } + /* + * public void readFromNBT(NBTTagCompound nbt) { NBTTagList list = + * nbt.getTagList("Items", 10); inventory = new ItemStack[INV_SIZE]; for(int + * i = 0;i<list.tagCount();i++) { NBTTagCompound data = + * list.getCompoundTagAt(i); int slot = data.getInteger("Slot"); if(slot >= + * 0 && slot < INV_SIZE) { inventory[slot] = + * ItemStack.loadItemStackFromNBT(data); } } } + * + * public void writeToNBT(NBTTagCompound nbt) { NBTTagList list = new + * NBTTagList(); for(int i = 0;i<INV_SIZE;i++) { ItemStack stack = + * inventory[i]; if(stack != null) { NBTTagCompound data = new + * NBTTagCompound(); stack.writeToNBT(data); data.setInteger("Slot", i); + * list.appendTag(data); } } nbt.setTag("Items", list); } + */ + + @Override + public void closeInventory() { } - public void writeToNBT(NBTTagCompound nbt) - { - NBTTagList list = new NBTTagList(); - for(int i = 0;i<INV_SIZE;i++) - { - ItemStack stack = inventory[i]; - if(stack != null) - { - NBTTagCompound data = new NBTTagCompound(); - stack.writeToNBT(data); - data.setInteger("Slot", i); - list.appendTag(data); + @Override + public ItemStack decrStackSize(final int slot, final int amount) { + ItemStack stack = this.getStackInSlot(slot); + if (stack != null) { + if (stack.stackSize > amount) { + stack = stack.splitStack(amount); + this.markDirty(); + } + else { + this.setInventorySlotContents(slot, null); } } - nbt.setTag("Items", list); - }*/ + return stack; + } - @Override - public int getSizeInventory() - { - return inventory.length; + public ItemStack[] getInventory() { + return this.inventory; } - public ItemStack[] getInventory(){ - return inventory; + @Override + public String getInventoryName() { + return this.name; } @Override - public ItemStack getStackInSlot(int slot) - { - return inventory[slot]; + public int getInventoryStackLimit() { + return 64; } @Override - public ItemStack decrStackSize(int slot, int amount) - { - ItemStack stack = getStackInSlot(slot); - if(stack != null) - { - if(stack.stackSize > amount) - { - stack = stack.splitStack(amount); - markDirty(); - } - else - { - setInventorySlotContents(slot, null); - } - } - return stack; + public int getSizeInventory() { + return this.inventory.length; } @Override - public ItemStack getStackInSlotOnClosing(int slot) - { - ItemStack stack = getStackInSlot(slot); - setInventorySlotContents(slot, null); - return stack; + public ItemStack getStackInSlot(final int slot) { + return this.inventory[slot]; } @Override - public void setInventorySlotContents(int slot, ItemStack stack) - { - inventory[slot] = stack; - if (stack != null && stack.stackSize > getInventoryStackLimit()) - { - stack.stackSize = getInventoryStackLimit(); - } - markDirty(); + public ItemStack getStackInSlotOnClosing(final int slot) { + final ItemStack stack = this.getStackInSlot(slot); + this.setInventorySlotContents(slot, null); + return stack; } @Override - public String getInventoryName() - { - return name; + public boolean hasCustomInventoryName() { + return this.name.length() > 0; } @Override - public boolean hasCustomInventoryName() - { - return name.length() > 0; + public boolean isItemValidForSlot(final int slot, final ItemStack itemstack) { + return true; } @Override - public int getInventoryStackLimit() - { - return 64; + public boolean isUseableByPlayer(final EntityPlayer entityplayer) { + return true; } @Override - public void markDirty() - { - for (int i = 0; i < getSizeInventory(); ++i) - { - ItemStack temp = getStackInSlot(i); - if (temp != null){ - //Utils.LOG_INFO("Slot "+i+" contains "+temp.getDisplayName()+" x"+temp.stackSize); + public void markDirty() { + for (int i = 0; i < this.getSizeInventory(); ++i) { + final ItemStack temp = this.getStackInSlot(i); + if (temp != null) { + // Utils.LOG_INFO("Slot "+i+" contains "+temp.getDisplayName()+" + // x"+temp.stackSize); } if (temp != null && temp.stackSize == 0) { - inventory[i] = null; + this.inventory[i] = null; } } } @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) - { - return true; + public void openInventory() { } @Override - public void openInventory() {} - - @Override - public void closeInventory() {} - - - @Override - public boolean isItemValidForSlot(int slot, ItemStack itemstack) - { - return true; + public void setInventorySlotContents(final int slot, final ItemStack stack) { + this.inventory[slot] = stack; + if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { + stack.stackSize = this.getInventoryStackLimit(); + } + this.markDirty(); } }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloSlots.java b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloSlots.java index c5da273a11..7c4482be7c 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloSlots.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloSlots.java @@ -8,261 +8,215 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -public class InventoryWorkbenchHoloSlots implements IInventory{ +public class InventoryWorkbenchHoloSlots implements IInventory { - private String name = "Inventory Holo"; - - //Output Slot - public IInventory craftResult = new InventoryCraftResult(); - /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 6; + public static final int INV_SIZE = 6; + + private final String name = "Inventory Holo"; - /** Inventory's size must be same as number of slots you add to the Container class */ - private ItemStack[] inventory = new ItemStack[INV_SIZE]; + // Output Slot + public IInventory craftResult = new InventoryCraftResult(); /** - * @param itemstack - the ItemStack to which this inventory belongs + * Inventory's size must be same as number of slots you add to the Container + * class */ - public InventoryWorkbenchHoloSlots() - { - - } + private ItemStack[] inventory = new ItemStack[InventoryWorkbenchHoloSlots.INV_SIZE]; - public void readFromNBT(NBTTagCompound nbt) - { - NBTTagList list = nbt.getTagList("Items", 10); - inventory = new ItemStack[INV_SIZE]; - for(int i = 0;i<list.tagCount();i++) - { - NBTTagCompound data = list.getCompoundTagAt(i); - int slot = data.getInteger("Slot"); - if(slot >= 1 && slot < INV_SIZE) - { - inventory[slot] = ItemStack.loadItemStackFromNBT(data); - } - } - } - - public void writeToNBT(NBTTagCompound nbt) - { - NBTTagList list = new NBTTagList(); - for(int i = 0;i<INV_SIZE;i++) - { - ItemStack stack = inventory[i]; - if(stack != null && i != 0) - { - NBTTagCompound data = new NBTTagCompound(); - stack.writeToNBT(data); - data.setInteger("Slot", i); - list.appendTag(data); - } - } - nbt.setTag("Items", list); - } + /** A list of one item containing the result of the crafting formula */ + private final ItemStack[] stackResult = new ItemStack[1]; - @Override - public int getSizeInventory() - { - return inventory.length; - } + /** + * @param itemstack + * - the ItemStack to which this inventory belongs + */ + public InventoryWorkbenchHoloSlots() { - public ItemStack[] getInventory(){ - return inventory; } + // 1.7.2+ renamed to closeInventory(EntityPlayer player) @Override - public ItemStack getStackInSlot(int slot) - { - return inventory[slot]; + public void closeInventory() { } + /** + * Removes from an inventory slot (first arg) up to a specified number + * (second arg) of items and returns them in a new stack. + */ + /* + * @Override public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) + * { ItemStack stack = getStackInSlot(0); if (this.stackResult[0] != null) { + * ItemStack itemstack = this.stackResult[0]; this.stackResult[0] = null; + * return itemstack; } if(stack != null) { if(stack.stackSize > p_70298_2_) + * { stack = stack.splitStack(p_70298_2_); // Don't forget this line or your + * inventory will not be saved! markDirty(); } else { // this method also + * calls markDirty, so we don't need to call it again + * setInventorySlotContents(p_70298_1_, null); } } return stack; } + */ @Override - public void setInventorySlotContents(int slot, ItemStack stack) - { - inventory[slot] = stack; + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + if (this.getStackInSlot(0) != null) { + Utils.LOG_INFO("getStackInSlot(0) contains " + this.getStackInSlot(0).getDisplayName()); + if (this.stackResult[0] == null) { + Utils.LOG_INFO("this.stackResult[0] == null"); + this.stackResult[0] = this.getStackInSlot(0); + } + else if (this.stackResult[0] != null) { + Utils.LOG_INFO("this.stackResult[0] != null"); + if (this.stackResult[0].getDisplayName().toLowerCase() + .equals(this.getStackInSlot(0).getDisplayName().toLowerCase())) { + Utils.LOG_INFO("Items are the same?"); + } + else { + Utils.LOG_INFO("Items are not the same."); + } + } + } - if (stack != null && stack.stackSize > getInventoryStackLimit()) - { - stack.stackSize = getInventoryStackLimit(); + if (this.stackResult[0] != null) { + Utils.LOG_INFO("this.stackResult[0] != null - Really never should be though. - Returning " + + this.stackResult[0].getDisplayName()); + final ItemStack itemstack = this.stackResult[0]; + this.stackResult[0] = null; + return itemstack; } + return null; + } - // Don't forget this line or your inventory will not be saved! - markDirty(); + public ItemStack[] getInventory() { + return this.inventory; } // 1.7.2+ renamed to getInventoryName @Override - public String getInventoryName() - { - return name; + public String getInventoryName() { + return this.name; } - // 1.7.2+ renamed to hasCustomInventoryName @Override - public boolean hasCustomInventoryName() - { - return name.length() > 0; + public int getInventoryStackLimit() { + return 1; } @Override - public int getInventoryStackLimit() - { - return 1; + public int getSizeInventory() { + return this.inventory.length; + } + + @Override + public ItemStack getStackInSlot(final int slot) { + return this.inventory[slot]; } /** - * This is the method that will handle saving the inventory contents, as it is called (or should be called!) - * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also - * let you change things in your inventory without ever opening a Gui, if you want. + * When some containers are closed they call this on each slot, then drop + * whatever it returns as an EntityItem - like when you close a workbench + * GUI. */ - // 1.7.2+ renamed to markDirty @Override - public void markDirty() - { - for (int i = 0; i < getSizeInventory(); ++i) - { - if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) { - inventory[i] = null; - } + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + if (this.stackResult[0] != null) { + final ItemStack itemstack = this.stackResult[0]; + this.stackResult[0] = null; + return itemstack; } + return null; } + // 1.7.2+ renamed to hasCustomInventoryName @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) - { - return true; + public boolean hasCustomInventoryName() { + return this.name.length() > 0; } - // 1.7.2+ renamed to openInventory(EntityPlayer player) - @Override - public void openInventory() {} - - // 1.7.2+ renamed to closeInventory(EntityPlayer player) - @Override - public void closeInventory() {} - /** - * This method doesn't seem to do what it claims to do, as - * items can still be left-clicked and placed in the inventory - * even when this returns false + * This method doesn't seem to do what it claims to do, as items can still + * be left-clicked and placed in the inventory even when this returns false */ @Override - public boolean isItemValidForSlot(int slot, ItemStack itemstack) - { + public boolean isItemValidForSlot(final int slot, final ItemStack itemstack) { return false; } - /** A list of one item containing the result of the crafting formula */ - private ItemStack[] stackResult = new ItemStack[1]; + @Override + public boolean isUseableByPlayer(final EntityPlayer entityplayer) { + return true; + } /** - * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a - * new stack. + * This is the method that will handle saving the inventory contents, as it + * is called (or should be called!) anytime the inventory changes. Perfect. + * Much better than using onUpdate in an Item, as this will also let you + * change things in your inventory without ever opening a Gui, if you want. */ - /*@Override - public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) - { - ItemStack stack = getStackInSlot(0); - if (this.stackResult[0] != null) - { - ItemStack itemstack = this.stackResult[0]; - this.stackResult[0] = null; - return itemstack; - } - if(stack != null) - { - if(stack.stackSize > p_70298_2_) - { - stack = stack.splitStack(p_70298_2_); - // Don't forget this line or your inventory will not be saved! - markDirty(); - } - else - { - // this method also calls markDirty, so we don't need to call it again - setInventorySlotContents(p_70298_1_, null); - } - } - return stack; - }*/ + // 1.7.2+ renamed to markDirty @Override - public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) - { - if (getStackInSlot(0) != null){ - Utils.LOG_INFO("getStackInSlot(0) contains "+getStackInSlot(0).getDisplayName()); - if (this.stackResult[0] == null){ - Utils.LOG_INFO("this.stackResult[0] == null"); - this.stackResult[0] = getStackInSlot(0); - } - else if (this.stackResult[0] != null){ - Utils.LOG_INFO("this.stackResult[0] != null"); - if (this.stackResult[0].getDisplayName().toLowerCase().equals(getStackInSlot(0).getDisplayName().toLowerCase())){ - Utils.LOG_INFO("Items are the same?"); - } - else { - Utils.LOG_INFO("Items are not the same."); - } + public void markDirty() { + for (int i = 0; i < this.getSizeInventory(); ++i) { + if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0) { + this.inventory[i] = null; } } - - if (this.stackResult[0] != null) - { - Utils.LOG_INFO("this.stackResult[0] != null - Really never should be though. - Returning "+this.stackResult[0].getDisplayName()); - ItemStack itemstack = this.stackResult[0]; - this.stackResult[0] = null; - return itemstack; - } - return null; - } + } - /** - * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem - - * like when you close a workbench GUI. - */ + // 1.7.2+ renamed to openInventory(EntityPlayer player) @Override - public ItemStack getStackInSlotOnClosing(int p_70304_1_) - { - if (this.stackResult[0] != null) - { - ItemStack itemstack = this.stackResult[0]; - this.stackResult[0] = null; - return itemstack; + public void openInventory() { + } + + public void readFromNBT(final NBTTagCompound nbt) { + final NBTTagList list = nbt.getTagList("Items", 10); + this.inventory = new ItemStack[InventoryWorkbenchHoloSlots.INV_SIZE]; + for (int i = 0; i < list.tagCount(); i++) { + final NBTTagCompound data = list.getCompoundTagAt(i); + final int slot = data.getInteger("Slot"); + if (slot >= 1 && slot < InventoryWorkbenchHoloSlots.INV_SIZE) { + this.inventory[slot] = ItemStack.loadItemStackFromNBT(data); + } } - return null; } -} + @Override + public void setInventorySlotContents(final int slot, final ItemStack stack) { + this.inventory[slot] = stack; + if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { + stack.stackSize = this.getInventoryStackLimit(); + } + // Don't forget this line or your inventory will not be saved! + this.markDirty(); + } -//Default Behaviour -/*@Override -public ItemStack decrStackSize(int slot, int amount) -{ - if(stack != null) - { - if(stack.stackSize > amount) - { - stack = stack.splitStack(amount); - // Don't forget this line or your inventory will not be saved! - markDirty(); - } - else - { - // this method also calls markDirty, so we don't need to call it again - setInventorySlotContents(slot, null); + public void writeToNBT(final NBTTagCompound nbt) { + final NBTTagList list = new NBTTagList(); + for (int i = 0; i < InventoryWorkbenchHoloSlots.INV_SIZE; i++) { + final ItemStack stack = this.inventory[i]; + if (stack != null && i != 0) { + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } } + nbt.setTag("Items", list); } - return stack; -}*/ -//Default Behaviour -/*@Override -public ItemStack getStackInSlotOnClosing(int slot) -{ - ItemStack stack = getStackInSlot(slot); - setInventorySlotContents(slot, null); - return stack; -}*/ +} +// Default Behaviour +/* + * @Override public ItemStack decrStackSize(int slot, int amount) { if(stack != + * null) { if(stack.stackSize > amount) { stack = stack.splitStack(amount); // + * Don't forget this line or your inventory will not be saved! markDirty(); } + * else { // this method also calls markDirty, so we don't need to call it again + * setInventorySlotContents(slot, null); } } return stack; } + */ + +// Default Behaviour +/* + * @Override public ItemStack getStackInSlotOnClosing(int slot) { ItemStack + * stack = getStackInSlot(slot); setInventorySlotContents(slot, null); return + * stack; } + */ diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchTools.java b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchTools.java index 7e3e7c3aef..114776dc49 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchTools.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchTools.java @@ -7,181 +7,165 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -public class InventoryWorkbenchTools implements IInventory{ - - private String name = "Inventory Tools"; +public class InventoryWorkbenchTools implements IInventory { /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 5; + public static final int INV_SIZE = 5; - /** Inventory's size must be same as number of slots you add to the Container class */ - private ItemStack[] inventory = new ItemStack[INV_SIZE]; + private final String name = "Inventory Tools"; /** - * @param itemstack - the ItemStack to which this inventory belongs + * Inventory's size must be same as number of slots you add to the Container + * class */ - public InventoryWorkbenchTools() - { - - } - - public void readFromNBT(NBTTagCompound nbt) - { - NBTTagList list = nbt.getTagList("Items", 10); - inventory = new ItemStack[INV_SIZE]; - for(int i = 0;i<list.tagCount();i++) - { - NBTTagCompound data = list.getCompoundTagAt(i); - int slot = data.getInteger("Slot"); - if(slot >= 0 && slot < INV_SIZE) - { - inventory[slot] = ItemStack.loadItemStackFromNBT(data); - } - } - } - - public void writeToNBT(NBTTagCompound nbt) - { - NBTTagList list = new NBTTagList(); - for(int i = 0;i<INV_SIZE;i++) - { - ItemStack stack = inventory[i]; - if(stack != null) - { - NBTTagCompound data = new NBTTagCompound(); - stack.writeToNBT(data); - data.setInteger("Slot", i); - list.appendTag(data); - } - } - nbt.setTag("Items", list); - } - - @Override - public int getSizeInventory() - { - return inventory.length; - } - - public ItemStack[] getInventory(){ - return inventory; + private ItemStack[] inventory = new ItemStack[InventoryWorkbenchTools.INV_SIZE]; + + /** + * @param itemstack + * - the ItemStack to which this inventory belongs + */ + public InventoryWorkbenchTools() { + } + // 1.7.2+ renamed to closeInventory(EntityPlayer player) @Override - public ItemStack getStackInSlot(int slot) - { - return inventory[slot]; + public void closeInventory() { } @Override - public ItemStack decrStackSize(int slot, int amount) - { - ItemStack stack = getStackInSlot(slot); - if(stack != null) - { - if(stack.stackSize > amount) - { + public ItemStack decrStackSize(final int slot, final int amount) { + ItemStack stack = this.getStackInSlot(slot); + if (stack != null) { + if (stack.stackSize > amount) { stack = stack.splitStack(amount); // Don't forget this line or your inventory will not be saved! - markDirty(); + this.markDirty(); } - else - { - // this method also calls markDirty, so we don't need to call it again - setInventorySlotContents(slot, null); + else { + // this method also calls markDirty, so we don't need to call it + // again + this.setInventorySlotContents(slot, null); } } return stack; } + public ItemStack[] getInventory() { + return this.inventory; + } + + // 1.7.2+ renamed to getInventoryName @Override - public ItemStack getStackInSlotOnClosing(int slot) - { - ItemStack stack = getStackInSlot(slot); - setInventorySlotContents(slot, null); - return stack; + public String getInventoryName() { + return this.name; } @Override - public void setInventorySlotContents(int slot, ItemStack stack) - { - inventory[slot] = stack; + public int getInventoryStackLimit() { + return 1; + } - if (stack != null && stack.stackSize > getInventoryStackLimit()) - { - stack.stackSize = getInventoryStackLimit(); - } + @Override + public int getSizeInventory() { + return this.inventory.length; + } - // Don't forget this line or your inventory will not be saved! - markDirty(); + @Override + public ItemStack getStackInSlot(final int slot) { + return this.inventory[slot]; } - // 1.7.2+ renamed to getInventoryName @Override - public String getInventoryName() - { - return name; + public ItemStack getStackInSlotOnClosing(final int slot) { + final ItemStack stack = this.getStackInSlot(slot); + this.setInventorySlotContents(slot, null); + return stack; } // 1.7.2+ renamed to hasCustomInventoryName @Override - public boolean hasCustomInventoryName() - { - return name.length() > 0; + public boolean hasCustomInventoryName() { + return this.name.length() > 0; } + /** + * This method doesn't seem to do what it claims to do, as items can still + * be left-clicked and placed in the inventory even when this returns false + */ @Override - public int getInventoryStackLimit() - { - return 1; + public boolean isItemValidForSlot(final int slot, final ItemStack itemstack) { + // Don't want to be able to store the inventory item within itself + // Bad things will happen, like losing your inventory + // Actually, this needs a custom Slot to work + if (itemstack.getItem() instanceof GT_MetaGenerated_Tool) { + return true; + } + return false; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer entityplayer) { + return true; } /** - * This is the method that will handle saving the inventory contents, as it is called (or should be called!) - * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also - * let you change things in your inventory without ever opening a Gui, if you want. + * This is the method that will handle saving the inventory contents, as it + * is called (or should be called!) anytime the inventory changes. Perfect. + * Much better than using onUpdate in an Item, as this will also let you + * change things in your inventory without ever opening a Gui, if you want. */ // 1.7.2+ renamed to markDirty @Override - public void markDirty() - { - for (int i = 0; i < getSizeInventory(); ++i) - { - if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) { - inventory[i] = null; + public void markDirty() { + for (int i = 0; i < this.getSizeInventory(); ++i) { + if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0) { + this.inventory[i] = null; } } } + // 1.7.2+ renamed to openInventory(EntityPlayer player) @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) - { - return true; + public void openInventory() { } - // 1.7.2+ renamed to openInventory(EntityPlayer player) - @Override - public void openInventory() {} + public void readFromNBT(final NBTTagCompound nbt) { + final NBTTagList list = nbt.getTagList("Items", 10); + this.inventory = new ItemStack[InventoryWorkbenchTools.INV_SIZE]; + for (int i = 0; i < list.tagCount(); i++) { + final NBTTagCompound data = list.getCompoundTagAt(i); + final int slot = data.getInteger("Slot"); + if (slot >= 0 && slot < InventoryWorkbenchTools.INV_SIZE) { + this.inventory[slot] = ItemStack.loadItemStackFromNBT(data); + } + } + } - // 1.7.2+ renamed to closeInventory(EntityPlayer player) @Override - public void closeInventory() {} + public void setInventorySlotContents(final int slot, final ItemStack stack) { + this.inventory[slot] = stack; - /** - * This method doesn't seem to do what it claims to do, as - * items can still be left-clicked and placed in the inventory - * even when this returns false - */ - @Override - public boolean isItemValidForSlot(int slot, ItemStack itemstack) - { - // Don't want to be able to store the inventory item within itself - // Bad things will happen, like losing your inventory - // Actually, this needs a custom Slot to work - if (itemstack.getItem() instanceof GT_MetaGenerated_Tool){ - return true; - } - return false; + if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { + stack.stackSize = this.getInventoryStackLimit(); + } + + // Don't forget this line or your inventory will not be saved! + this.markDirty(); } - + + public void writeToNBT(final NBTTagCompound nbt) { + final NBTTagList list = new NBTTagList(); + for (int i = 0; i < InventoryWorkbenchTools.INV_SIZE; i++) { + final ItemStack stack = this.inventory[i]; + if (stack != null) { + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } + } + nbt.setTag("Items", list); + } + }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchToolsElectric.java b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchToolsElectric.java index 77f3351e59..fbfb45a518 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchToolsElectric.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchToolsElectric.java @@ -10,182 +10,166 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -public class InventoryWorkbenchToolsElectric implements IInventory{ - - private String name = "Inventory Tools"; +public class InventoryWorkbenchToolsElectric implements IInventory { /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 5; + public static final int INV_SIZE = 5; - /** Inventory's size must be same as number of slots you add to the Container class */ - private ItemStack[] inventory = new ItemStack[INV_SIZE]; - private Slot[] toolSlots = new SlotGtToolElectric[INV_SIZE]; //TODO + private final String name = "Inventory Tools"; /** - * @param itemstack - the ItemStack to which this inventory belongs + * Inventory's size must be same as number of slots you add to the Container + * class */ - public InventoryWorkbenchToolsElectric() - { - - } - - public void readFromNBT(NBTTagCompound nbt) - { - NBTTagList list = nbt.getTagList("Items", 10); - inventory = new ItemStack[INV_SIZE]; - for(int i = 0;i<list.tagCount();i++) - { - NBTTagCompound data = list.getCompoundTagAt(i); - int slot = data.getInteger("Slot"); - if(slot >= 0 && slot < INV_SIZE) - { - inventory[slot] = ItemStack.loadItemStackFromNBT(data); - } - } - } - - public void writeToNBT(NBTTagCompound nbt) - { - NBTTagList list = new NBTTagList(); - for(int i = 0;i<INV_SIZE;i++) - { - ItemStack stack = inventory[i]; - if(stack != null) - { - NBTTagCompound data = new NBTTagCompound(); - stack.writeToNBT(data); - data.setInteger("Slot", i); - list.appendTag(data); - } - } - nbt.setTag("Items", list); - } - - @Override - public int getSizeInventory() - { - return inventory.length; - } - - public ItemStack[] getInventory(){ - return inventory; + private ItemStack[] inventory = new ItemStack[InventoryWorkbenchToolsElectric.INV_SIZE]; + private final Slot[] toolSlots = new SlotGtToolElectric[InventoryWorkbenchToolsElectric.INV_SIZE]; // TODO + + /** + * @param itemstack + * - the ItemStack to which this inventory belongs + */ + public InventoryWorkbenchToolsElectric() { + } + // 1.7.2+ renamed to closeInventory(EntityPlayer player) @Override - public ItemStack getStackInSlot(int slot) - { - return inventory[slot]; + public void closeInventory() { } @Override - public ItemStack decrStackSize(int slot, int amount) - { - ItemStack stack = getStackInSlot(slot); - if(stack != null) - { - if(stack.stackSize > amount) - { + public ItemStack decrStackSize(final int slot, final int amount) { + ItemStack stack = this.getStackInSlot(slot); + if (stack != null) { + if (stack.stackSize > amount) { stack = stack.splitStack(amount); // Don't forget this line or your inventory will not be saved! - markDirty(); + this.markDirty(); } - else - { - // this method also calls markDirty, so we don't need to call it again - setInventorySlotContents(slot, null); + else { + // this method also calls markDirty, so we don't need to call it + // again + this.setInventorySlotContents(slot, null); } } return stack; } + public ItemStack[] getInventory() { + return this.inventory; + } + + // 1.7.2+ renamed to getInventoryName @Override - public ItemStack getStackInSlotOnClosing(int slot) - { - ItemStack stack = getStackInSlot(slot); - setInventorySlotContents(slot, null); - return stack; + public String getInventoryName() { + return this.name; } @Override - public void setInventorySlotContents(int slot, ItemStack stack) - { - inventory[slot] = stack; + public int getInventoryStackLimit() { + return 1; + } - if (stack != null && stack.stackSize > getInventoryStackLimit()) - { - stack.stackSize = getInventoryStackLimit(); - } + @Override + public int getSizeInventory() { + return this.inventory.length; + } - // Don't forget this line or your inventory will not be saved! - markDirty(); + @Override + public ItemStack getStackInSlot(final int slot) { + return this.inventory[slot]; } - // 1.7.2+ renamed to getInventoryName @Override - public String getInventoryName() - { - return name; + public ItemStack getStackInSlotOnClosing(final int slot) { + final ItemStack stack = this.getStackInSlot(slot); + this.setInventorySlotContents(slot, null); + return stack; } // 1.7.2+ renamed to hasCustomInventoryName @Override - public boolean hasCustomInventoryName() - { - return name.length() > 0; + public boolean hasCustomInventoryName() { + return this.name.length() > 0; } + /** + * This method doesn't seem to do what it claims to do, as items can still + * be left-clicked and placed in the inventory even when this returns false + */ @Override - public int getInventoryStackLimit() - { - return 1; + public boolean isItemValidForSlot(final int slot, final ItemStack itemstack) { + // Don't want to be able to store the inventory item within itself + // Bad things will happen, like losing your inventory + // Actually, this needs a custom Slot to work + if (itemstack.getItem() instanceof GT_MetaGenerated_Tool || itemstack.getItem() instanceof IElectricItem) { + return true; + } + return false; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer entityplayer) { + return true; } /** - * This is the method that will handle saving the inventory contents, as it is called (or should be called!) - * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also - * let you change things in your inventory without ever opening a Gui, if you want. + * This is the method that will handle saving the inventory contents, as it + * is called (or should be called!) anytime the inventory changes. Perfect. + * Much better than using onUpdate in an Item, as this will also let you + * change things in your inventory without ever opening a Gui, if you want. */ // 1.7.2+ renamed to markDirty @Override - public void markDirty() - { - for (int i = 0; i < getSizeInventory(); ++i) - { - if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) { - inventory[i] = null; + public void markDirty() { + for (int i = 0; i < this.getSizeInventory(); ++i) { + if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0) { + this.inventory[i] = null; } } } + // 1.7.2+ renamed to openInventory(EntityPlayer player) @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) - { - return true; + public void openInventory() { } - // 1.7.2+ renamed to openInventory(EntityPlayer player) - @Override - public void openInventory() {} + public void readFromNBT(final NBTTagCompound nbt) { + final NBTTagList list = nbt.getTagList("Items", 10); + this.inventory = new ItemStack[InventoryWorkbenchToolsElectric.INV_SIZE]; + for (int i = 0; i < list.tagCount(); i++) { + final NBTTagCompound data = list.getCompoundTagAt(i); + final int slot = data.getInteger("Slot"); + if (slot >= 0 && slot < InventoryWorkbenchToolsElectric.INV_SIZE) { + this.inventory[slot] = ItemStack.loadItemStackFromNBT(data); + } + } + } - // 1.7.2+ renamed to closeInventory(EntityPlayer player) @Override - public void closeInventory() {} + public void setInventorySlotContents(final int slot, final ItemStack stack) { + this.inventory[slot] = stack; - /** - * This method doesn't seem to do what it claims to do, as - * items can still be left-clicked and placed in the inventory - * even when this returns false - */ - @Override - public boolean isItemValidForSlot(int slot, ItemStack itemstack) - { - // Don't want to be able to store the inventory item within itself - // Bad things will happen, like losing your inventory - // Actually, this needs a custom Slot to work - if (itemstack.getItem() instanceof GT_MetaGenerated_Tool || itemstack.getItem() instanceof IElectricItem){ - return true; - } - return false; + if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { + stack.stackSize = this.getInventoryStackLimit(); + } + + // Don't forget this line or your inventory will not be saved! + this.markDirty(); } - + + public void writeToNBT(final NBTTagCompound nbt) { + final NBTTagList list = new NBTTagList(); + for (int i = 0; i < InventoryWorkbenchToolsElectric.INV_SIZE; i++) { + final ItemStack stack = this.inventory[i]; + if (stack != null) { + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } + } + nbt.setTag("Items", list); + } + }
\ No newline at end of file |