diff options
| author | Draknyte1 <Draknyte1@hotmail.com> | 2016-11-06 19:32:27 +1000 |
|---|---|---|
| committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-11-06 19:32:27 +1000 |
| commit | cbe0e497be8e466c380a5b4fa781b314ede9ada3 (patch) | |
| tree | b85848b432adf458e3abda466ee46d9dfc3e454b /src/Java/gtPlusPlus/core/inventories | |
| parent | c40416b036c0e89451e1558253ccf07bbee028d0 (diff) | |
| download | GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.tar.gz GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.tar.bz2 GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.zip | |
Revert "$ Cleaned up the entire project."
This reverts commit 0669f5eb9d5029a8b94ec552171b0837605f7747.
# Conflicts:
# src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMTE_NuclearReactor.java
# src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_MassFabricator.java
Revert "% Cleaned up Imports."
This reverts commit 3654052fb63a571c5eaca7f20714b87c17f7e966.
Diffstat (limited to 'src/Java/gtPlusPlus/core/inventories')
7 files changed, 943 insertions, 793 deletions
diff --git a/src/Java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java b/src/Java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java index 64e7c9cef5..59fe8aa4fa 100644 --- a/src/Java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java +++ b/src/Java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java @@ -1,8 +1,9 @@ package gtPlusPlus.core.inventories; +import gtPlusPlus.core.item.base.BaseItemBackpack; + import java.util.UUID; -import gtPlusPlus.core.item.base.BaseItemBackpack; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -10,44 +11,40 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraftforge.common.util.Constants; -public class BaseInventoryBackpack implements IInventory { - - /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 8; +public class BaseInventoryBackpack implements IInventory{ - private final String name = "Inventory Item"; + private String name = "Inventory Item"; /** Provides NBT Tag Compound to reference */ - private final ItemStack invItem; + private final ItemStack invItem; - /** - * 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]; + /** Defining your inventory size this way is handy */ + public static final int INV_SIZE = 8; + + /** Inventory's size must be same as number of slots you add to the Container class */ + private ItemStack[] inventory = new ItemStack[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(final ItemStack stack) { - this.invItem = stack; + public BaseInventoryBackpack(ItemStack stack) + { + invItem = stack; /** initialize variable within the constructor: */ - this.uniqueID = ""; + 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: - this.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: + 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()); } @@ -56,175 +53,189 @@ public class BaseInventoryBackpack implements IInventory { // either reference will change in the other // Read the inventory contents from NBT - this.readFromNBT(stack.getTagCompound()); + readFromNBT(stack.getTagCompound()); + } + @Override + public int getSizeInventory() + { + return inventory.length; } - // 1.7.2+ renamed to closeInventory(EntityPlayer player) @Override - public void closeInventory() { + public ItemStack getStackInSlot(int slot) + { + return inventory[slot]; } @Override - public ItemStack decrStackSize(final int slot, final int amount) { - ItemStack stack = this.getStackInSlot(slot); - if (stack != null) { - if (stack.stackSize > amount) { + public ItemStack decrStackSize(int slot, int amount) + { + ItemStack stack = 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! - this.markDirty(); + markDirty(); } - else { - // this method also calls markDirty, so we don't need to call it - // again - this.setInventorySlotContents(slot, null); + else + { + // this method also calls markDirty, so we don't need to call it again + setInventorySlotContents(slot, null); } } return stack; } - // 1.7.2+ renamed to getInventoryName @Override - public String getInventoryName() { - return this.name; + public ItemStack getStackInSlotOnClosing(int slot) + { + ItemStack stack = getStackInSlot(slot); + setInventorySlotContents(slot, null); + return stack; } @Override - public int getInventoryStackLimit() { - return 64; - } + public void setInventorySlotContents(int slot, ItemStack stack) + { + inventory[slot] = stack; - @Override - public int getSizeInventory() { - return this.inventory.length; - } + if (stack != null && stack.stackSize > getInventoryStackLimit()) + { + stack.stackSize = getInventoryStackLimit(); + } - @Override - public ItemStack getStackInSlot(final int slot) { - return this.inventory[slot]; + // Don't forget this line or your inventory will not be saved! + markDirty(); } + // 1.7.2+ renamed to getInventoryName @Override - public ItemStack getStackInSlotOnClosing(final int slot) { - final ItemStack stack = this.getStackInSlot(slot); - this.setInventorySlotContents(slot, null); - return stack; + public String getInventoryName() + { + return name; } // 1.7.2+ renamed to hasCustomInventoryName @Override - 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 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); + public boolean hasCustomInventoryName() + { + return name.length() > 0; } @Override - public boolean isUseableByPlayer(final EntityPlayer entityplayer) { - return true; + public int getInventoryStackLimit() + { + return 64; } /** - * 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 < this.getSizeInventory(); ++i) { - if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0) { - this.inventory[i] = null; + 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: - this.writeToNBT(this.invItem.getTagCompound()); + // This line here does the work: + writeToNBT(invItem.getTagCompound()); + } + + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer) + { + return true; } // 1.7.2+ renamed to openInventory(EntityPlayer player) @Override - public void openInventory() { + 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 + */ + @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); } /** * A custom method to read our inventory from an ItemStack's NBT compound */ - public void readFromNBT(final NBTTagCompound compound) { + public void readFromNBT(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); - final NBTTagList items = compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND); - - if ("".equals(this.uniqueID)) { + // 1.7.2+ change to compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND); + NBTTagList items = compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND); + + if ("".equals(uniqueID)) + { // try to read unique ID from NBT - this.uniqueID = compound.getString("uniqueID"); + uniqueID = compound.getString("uniqueID"); // if it's still "", assign a new one: - if ("".equals(this.uniqueID)) { - this.uniqueID = UUID.randomUUID().toString(); + if ("".equals(uniqueID)) + { + 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) - final NBTTagCompound item = items.getCompoundTagAt(i); - final int slot = item.getInteger("Slot"); + NBTTagCompound item = (NBTTagCompound) items.getCompoundTagAt(i); + int slot = item.getInteger("Slot"); - // 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); + // Just double-checking that the saved slot index is within our inventory array bounds + if (slot >= 0 && slot < getSizeInventory()) { + 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(final NBTTagCompound tagcompound) { + public void writeToNBT(NBTTagCompound tagcompound) + { // Create a new NBT Tag List to store itemstacks as NBT Tags - final NBTTagList items = new NBTTagList(); + NBTTagList items = new NBTTagList(); - for (int i = 0; i < this.getSizeInventory(); ++i) { + for (int i = 0; i < getSizeInventory(); ++i) + { // Only write stacks that contain items - if (this.getStackInSlot(i) != null) { - // Make a new NBT Tag Compound to write the itemstack and slot - // index to - final NBTTagCompound item = new NBTTagCompound(); + if (getStackInSlot(i) != null) + { + // Make a new NBT Tag Compound to write the itemstack and slot index to + NBTTagCompound item = new NBTTagCompound(); item.setInteger("Slot", i); - // Writes the itemstack in slot(i) to the Tag Compound we just - // made - this.getStackInSlot(i).writeToNBT(item); + // Writes the itemstack in slot(i) to the Tag Compound we just made + 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 7a3507ec55..8d147ad21c 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchChest.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchChest.java @@ -6,168 +6,183 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -public class InventoryWorkbenchChest implements IInventory { +public class InventoryWorkbenchChest implements IInventory{ - /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 16; + private String name = "Inventory Chest"; - private final String name = "Inventory Chest"; + /** Defining your inventory size this way is handy */ + 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[InventoryWorkbenchChest.INV_SIZE]; + /** Inventory's size must be same as number of slots you add to the Container class */ + private ItemStack[] inventory = new ItemStack[INV_SIZE]; /** - * @param itemstack - * - the ItemStack to which this inventory belongs + * @param itemstack - the ItemStack to which this inventory belongs */ - public InventoryWorkbenchChest() { - + 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; } - // 1.7.2+ renamed to closeInventory(EntityPlayer player) @Override - public void closeInventory() { + public ItemStack getStackInSlot(int slot) + { + return inventory[slot]; } @Override - public ItemStack decrStackSize(final int slot, final int amount) { - ItemStack stack = this.getStackInSlot(slot); - if (stack != null) { - if (stack.stackSize > amount) { + public ItemStack decrStackSize(int slot, int amount) + { + ItemStack stack = 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! - this.markDirty(); + markDirty(); } - else { - // this method also calls markDirty, so we don't need to call it - // again - this.setInventorySlotContents(slot, null); + else + { + // this method also calls markDirty, so we don't need to call it again + setInventorySlotContents(slot, null); } } return stack; } - public ItemStack[] getInventory() { - return this.inventory; - } - - // 1.7.2+ renamed to getInventoryName @Override - public String getInventoryName() { - return this.name; + public ItemStack getStackInSlotOnClosing(int slot) + { + ItemStack stack = getStackInSlot(slot); + setInventorySlotContents(slot, null); + return stack; } @Override - public int getInventoryStackLimit() { - return 64; - } + public void setInventorySlotContents(int slot, ItemStack stack) + { + inventory[slot] = stack; - @Override - public int getSizeInventory() { - return this.inventory.length; - } + if (stack != null && stack.stackSize > getInventoryStackLimit()) + { + stack.stackSize = getInventoryStackLimit(); + } - @Override - public ItemStack getStackInSlot(final int slot) { - return this.inventory[slot]; + // Don't forget this line or your inventory will not be saved! + markDirty(); } + // 1.7.2+ renamed to getInventoryName @Override - public ItemStack getStackInSlotOnClosing(final int slot) { - final ItemStack stack = this.getStackInSlot(slot); - this.setInventorySlotContents(slot, null); - return stack; + public String getInventoryName() + { + return name; } // 1.7.2+ renamed to hasCustomInventoryName @Override - public boolean hasCustomInventoryName() { - return this.name.length() > 0; + public boolean hasCustomInventoryName() + { + return 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 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; + public int getInventoryStackLimit() + { + return 64; } /** - * 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 < this.getSizeInventory(); ++i) { - final ItemStack temp = this.getStackInSlot(i); - if (temp != null) { - // Utils.LOG_INFO("Slot "+i+" contains "+temp.getDisplayName()+" - // x"+temp.stackSize); + 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); } - + if (temp != null && temp.stackSize == 0) { - this.inventory[i] = null; + inventory[i] = null; } } } - // 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); - } - } + public boolean isUseableByPlayer(EntityPlayer entityplayer) + { + return true; } + // 1.7.2+ renamed to openInventory(EntityPlayer player) @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(); - } + public void openInventory() {} - // Don't forget this line or your inventory will not be saved! - this.markDirty(); - } + // 1.7.2+ renamed to closeInventory(EntityPlayer player) + @Override + public void closeInventory() {} - 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); + /** + * 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; } }
\ 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 ff39d3a241..333bb5c847 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchCrafting.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchCrafting.java @@ -1,183 +1,201 @@ package gtPlusPlus.core.inventories; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.*; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -public class InventoryWorkbenchCrafting implements IInventory { +public class InventoryWorkbenchCrafting implements IInventory{ - /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 9; + private String name = "Inventory Crafting"; - private final String name = "Inventory Crafting"; + /** Defining your inventory size this way is handy */ + 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[InventoryWorkbenchCrafting.INV_SIZE]; - public final InventoryCrafting craftMatrix; - public final Container parentContainer; + /** 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; + } /** - * @param itemstack - * - the ItemStack to which this inventory belongs + * @param itemstack - the ItemStack to which this inventory belongs */ - public InventoryWorkbenchCrafting(final Container containerR) { + public InventoryWorkbenchCrafting(Container containerR) + { this.parentContainer = containerR; - this.craftMatrix = new InventoryCrafting(this.parentContainer, 3, 3); + 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(); } - // 1.7.2+ renamed to closeInventory(EntityPlayer player) @Override - public void closeInventory() { + public ItemStack getStackInSlot(int slot) + { + return getInventory()[slot]; } @Override - public ItemStack decrStackSize(final int slot, final int amount) { - ItemStack stack = this.getStackInSlot(slot); - if (stack != null) { - if (stack.stackSize > amount) { + public ItemStack decrStackSize(int slot, int amount) + { + ItemStack stack = 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! - this.markDirty(); + markDirty(); } - else { - // this method also calls markDirty, so we don't need to call it - // again - this.setInventorySlotContents(slot, null); + else + { + // this method also calls markDirty, so we don't need to call it again + 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 String getInventoryName() { - return this.name; + public ItemStack getStackInSlotOnClosing(int slot) + { + ItemStack stack = getStackInSlot(slot); + setInventorySlotContents(slot, null); + return stack; } @Override - public int getInventoryStackLimit() { - return 64; - } + public void setInventorySlotContents(int slot, ItemStack stack) + { + getInventory()[slot] = stack; - @Override - public int getSizeInventory() { - return this.getInventory().length; - } + if (stack != null && stack.stackSize > getInventoryStackLimit()) + { + stack.stackSize = getInventoryStackLimit(); + } - @Override - public ItemStack getStackInSlot(final int slot) { - return this.getInventory()[slot]; + // Don't forget this line or your inventory will not be saved! + markDirty(); } + // 1.7.2+ renamed to getInventoryName @Override - public ItemStack getStackInSlotOnClosing(final int slot) { - final ItemStack stack = this.getStackInSlot(slot); - this.setInventorySlotContents(slot, null); - return stack; + public String getInventoryName() + { + return name; } // 1.7.2+ renamed to hasCustomInventoryName @Override - public boolean hasCustomInventoryName() { - return this.name.length() > 0; + public boolean hasCustomInventoryName() + { + return 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 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; + public int getInventoryStackLimit() + { + return 64; } /** - * 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 < this.getSizeInventory(); ++i) { - if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0) { - this.getInventory()[i] = null; + public void markDirty() + { + for (int i = 0; i < getSizeInventory(); ++i) + { + if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) { + getInventory()[i] = null; } } } - // 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); - } - } + public boolean isUseableByPlayer(EntityPlayer entityplayer) + { + return true; } + // 1.7.2+ renamed to openInventory(EntityPlayer player) @Override - public void setInventorySlotContents(final int slot, final ItemStack stack) { - this.getInventory()[slot] = stack; + public void openInventory() {} - 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(); - } + // 1.7.2+ renamed to closeInventory(EntityPlayer player) + @Override + public void closeInventory() {} - 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); + /** + * 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 |
