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 custom Slot to work + return true; } }
\ 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 9cfa57ec08..f4fe78d458 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java @@ -4,133 +4,161 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -public class InventoryWorkbenchHoloCrafting implements IInventory { +public class InventoryWorkbenchHoloCrafting implements IInventory{ + + private String name = "Inventory Crafting"; /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 9; + public static final int INV_SIZE = 9; - 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[INV_SIZE]; /** - * Inventory's size must be same as number of slots you add to the Container - * class + * @param itemstack - the ItemStack to which this inventory belongs */ - private final ItemStack[] inventory = new ItemStack[InventoryWorkbenchHoloCrafting.INV_SIZE]; - - /** - * @param itemstack - * - the ItemStack to which this inventory belongs - */ - public InventoryWorkbenchHoloCrafting() { + 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 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 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); + } + } } - @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); + 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); } } - return stack; - } + nbt.setTag("Items", list); + }*/ - public ItemStack[] getInventory() { - return this.inventory; + @Override + public int getSizeInventory() + { + return inventory.length; } - @Override - public String getInventoryName() { - return this.name; + public ItemStack[] getInventory(){ + return inventory; } @Override - public int getInventoryStackLimit() { - return 64; + public ItemStack getStackInSlot(int slot) + { + return inventory[slot]; } @Override - public int getSizeInventory() { - return this.inventory.length; + 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; } @Override - public ItemStack getStackInSlot(final int slot) { - return this.inventory[slot]; + public ItemStack getStackInSlotOnClosing(int slot) + { + ItemStack stack = getStackInSlot(slot); + setInventorySlotContents(slot, null); + return stack; } @Override - public ItemStack getStackInSlotOnClosing(final int slot) { - final ItemStack stack = this.getStackInSlot(slot); - this.setInventorySlotContents(slot, null); - return stack; + public void setInventorySlotContents(int slot, ItemStack stack) + { + inventory[slot] = stack; + if (stack != null && stack.stackSize > getInventoryStackLimit()) + { + stack.stackSize = getInventoryStackLimit(); + } + markDirty(); } @Override - public boolean hasCustomInventoryName() { - return this.name.length() > 0; + public String getInventoryName() + { + return name; } @Override - public boolean isItemValidForSlot(final int slot, final ItemStack itemstack) { - return true; + public boolean hasCustomInventoryName() + { + return name.length() > 0; } @Override - public boolean isUseableByPlayer(final EntityPlayer entityplayer) { - return true; + public int getInventoryStackLimit() + { + return 64; } @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; } } } @Override - public void openInventory() { + public boolean isUseableByPlayer(EntityPlayer entityplayer) + { + return true; } @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(); - } - this.markDirty(); + public void openInventory() {} + + @Override + public void closeInventory() {} + + + @Override + public boolean isItemValidForSlot(int slot, ItemStack itemstack) + { + return true; } }
\ 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 7c4482be7c..c5da273a11 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloSlots.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloSlots.java @@ -8,215 +8,261 @@ 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{ - /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 6; - - private final String name = "Inventory Holo"; + private String name = "Inventory Holo"; - // Output Slot - public IInventory craftResult = new InventoryCraftResult(); - - /** - * Inventory's size must be same as number of slots you add to the Container - * class - */ - private ItemStack[] inventory = new ItemStack[InventoryWorkbenchHoloSlots.INV_SIZE]; + //Output Slot + public IInventory craftResult = new InventoryCraftResult(); + + /** Defining your inventory size this way is handy */ + public static final int INV_SIZE = 6; - /** A list of one item containing the result of the crafting formula */ - private final ItemStack[] stackResult = new ItemStack[1]; + /** 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 InventoryWorkbenchHoloSlots() { + public InventoryWorkbenchHoloSlots() + { } - // 1.7.2+ renamed to closeInventory(EntityPlayer player) - @Override - public void closeInventory() { + 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); + } + } } - /** - * 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 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."); - } + 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); + } - 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; + @Override + public int getSizeInventory() + { + return inventory.length; } - public ItemStack[] getInventory() { - return this.inventory; + public ItemStack[] getInventory(){ + return inventory; } - // 1.7.2+ renamed to getInventoryName @Override - public String getInventoryName() { - return this.name; + public ItemStack getStackInSlot(int slot) + { + return inventory[slot]; } @Override - public int getInventoryStackLimit() { - return 1; + public void setInventorySlotContents(int slot, ItemStack stack) + { + inventory[slot] = stack; + + if (stack != null && stack.stackSize > getInventoryStackLimit()) + { + stack.stackSize = getInventoryStackLimit(); + } + + // Don't forget this line or your inventory will not be saved! + markDirty(); + } + + // 1.7.2+ renamed to getInventoryName + @Override + public String getInventoryName() + { + return name; } + // 1.7.2+ renamed to hasCustomInventoryName @Override - public int getSizeInventory() { - return this.inventory.length; + public boolean hasCustomInventoryName() + { + return name.length() > 0; } @Override - public ItemStack getStackInSlot(final int slot) { - return this.inventory[slot]; + public int getInventoryStackLimit() + { + return 1; } /** - * 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. + * 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 ItemStack getStackInSlotOnClosing(final int p_70304_1_) { - if (this.stackResult[0] != null) { - final ItemStack itemstack = this.stackResult[0]; - this.stackResult[0] = null; - return itemstack; + public void markDirty() + { + for (int i = 0; i < getSizeInventory(); ++i) + { + if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) { + inventory[i] = null; + } } - return null; } - // 1.7.2+ renamed to hasCustomInventoryName @Override - public boolean hasCustomInventoryName() { - return this.name.length() > 0; + public boolean isUseableByPlayer(EntityPlayer entityplayer) + { + return true; } + // 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(final int slot, final ItemStack itemstack) { + public boolean isItemValidForSlot(int slot, ItemStack itemstack) + { return false; } - @Override - public boolean isUseableByPlayer(final EntityPlayer entityplayer) { - return true; - } + /** A list of one item containing the result of the crafting formula */ + private ItemStack[] stackResult = new ItemStack[1]; /** - * 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. + * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a + * new stack. */ - // 1.7.2+ renamed to markDirty + /*@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 markDirty() { - for (int i = 0; i < this.getSizeInventory(); ++i) { - if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0) { - this.inventory[i] = null; + 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."); + } } } - } + + 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; + } - // 1.7.2+ renamed to openInventory(EntityPlayer player) + /** + * 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. + */ @Override - 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); - } + public ItemStack getStackInSlotOnClosing(int p_70304_1_) + { + if (this.stackResult[0] != null) + { + ItemStack itemstack = this.stackResult[0]; + this.stackResult[0] = null; + return itemstack; } + 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(); - } - 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); - } +//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); } - 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 114776dc49..7e3e7c3aef 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchTools.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchTools.java @@ -7,165 +7,181 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -public class InventoryWorkbenchTools implements IInventory { +public class InventoryWorkbenchTools implements IInventory{ - /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 5; + private String name = "Inventory Tools"; - private final String name = "Inventory Tools"; + /** Defining your inventory size this way is handy */ + 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[InventoryWorkbenchTools.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 InventoryWorkbenchTools() { - + 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; } - // 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 1; - } + 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 - if (itemstack.getItem() instanceof GT_MetaGenerated_Tool) { - return true; - } - return false; + public boolean hasCustomInventoryName() + { + return name.length() > 0; } @Override - public boolean isUseableByPlayer(final EntityPlayer entityplayer) { - return true; + public int getInventoryStackLimit() + { + return 1; } /** - * 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; } } } - // 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); - } - } + 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; + 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 < 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); + /** + * 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; } - + }
\ 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 fbfb45a518..77f3351e59 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchToolsElectric.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchToolsElectric.java @@ -10,166 +10,182 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -public class InventoryWorkbenchToolsElectric implements IInventory { +public class InventoryWorkbenchToolsElectric implements IInventory{ - /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 5; + private String name = "Inventory Tools"; - private final String name = "Inventory Tools"; + /** Defining your inventory size this way is handy */ + 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[InventoryWorkbenchToolsElectric.INV_SIZE]; - private final Slot[] toolSlots = new SlotGtToolElectric[InventoryWorkbenchToolsElectric.INV_SIZE]; // TODO + /** 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 /** - * @param itemstack - * - the ItemStack to which this inventory belongs + * @param itemstack - the ItemStack to which this inventory belongs */ - public InventoryWorkbenchToolsElectric() { - + 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; } - // 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 1; - } + 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 - if (itemstack.getItem() instanceof GT_MetaGenerated_Tool || itemstack.getItem() instanceof IElectricItem) { - return true; - } - return false; + public boolean hasCustomInventoryName() + { + return name.length() > 0; } @Override - public boolean isUseableByPlayer(final EntityPlayer entityplayer) { - return true; + public int getInventoryStackLimit() + { + return 1; } /** - * 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; } } } - // 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); - } - } + 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; + 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 < 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); + /** + * 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; } - + }
\ No newline at end of file |