diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-10-11 18:27:54 +0100 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-10-11 18:27:54 +0100 |
commit | d4d38f40f4500c3dfa218b516fc7621d64bc1759 (patch) | |
tree | 599ff65b5b3a3033df43463519f0cbce712e52ea /src/Java/gtPlusPlus/core/inventories | |
parent | 4a2fa070a2ae91173cf15785c63b4090016323d4 (diff) | |
download | GT5-Unofficial-d4d38f40f4500c3dfa218b516fc7621d64bc1759.tar.gz GT5-Unofficial-d4d38f40f4500c3dfa218b516fc7621d64bc1759.tar.bz2 GT5-Unofficial-d4d38f40f4500c3dfa218b516fc7621d64bc1759.zip |
+ Added Round-Robinator.
Diffstat (limited to 'src/Java/gtPlusPlus/core/inventories')
-rw-r--r-- | src/Java/gtPlusPlus/core/inventories/Inventory_RoundRobinator.java | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/inventories/Inventory_RoundRobinator.java b/src/Java/gtPlusPlus/core/inventories/Inventory_RoundRobinator.java new file mode 100644 index 0000000000..58d60b595f --- /dev/null +++ b/src/Java/gtPlusPlus/core/inventories/Inventory_RoundRobinator.java @@ -0,0 +1,173 @@ +package gtPlusPlus.core.inventories; + +import gtPlusPlus.core.recipe.common.CI; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +public class Inventory_RoundRobinator implements IInventory{ + + private final String name = "Circuit Programmer"; + + /** Defining your inventory size this way is handy */ + public static final int INV_SIZE = 26; + + /** Inventory's size must be same as number of slots you add to the Container class */ + private ItemStack[] inventory = new ItemStack[INV_SIZE]; + + public void readFromNBT(final NBTTagCompound nbt){ + final NBTTagList list = nbt.getTagList("Items", 10); + this.inventory = new ItemStack[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 < INV_SIZE)){ + //Utils.LOG_INFO("Trying to read NBT data from inventory."); + this.inventory[slot] = ItemStack.loadItemStackFromNBT(data); + } + } + } + + public void writeToNBT(final NBTTagCompound nbt){ + final NBTTagList list = new NBTTagList(); + for(int i = 0;i<INV_SIZE;i++){ + final ItemStack stack = this.inventory[i]; + if(stack != null){ + //Utils.LOG_INFO("Trying to write NBT data to inventory."); + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } + } + nbt.setTag("Items", list); + } + + @Override + public int getSizeInventory() + { + return this.inventory.length; + } + + public ItemStack[] getInventory(){ + return this.inventory; + } + + @Override + public ItemStack getStackInSlot(final int slot) + { + return this.inventory[slot]; + } + + @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); + // Don't forget this line or your inventory will not be saved! + this.markDirty(); + } + else + { + // this method also calls markDirty, so we don't need to call it again + this.setInventorySlotContents(slot, null); + } + } + return stack; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int slot) + { + final ItemStack stack = this.getStackInSlot(slot); + this.setInventorySlotContents(slot, null); + return stack; + } + + @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(); + } + + // 1.7.2+ renamed to getInventoryName + @Override + public String getInventoryName() + { + return this.name; + } + + // 1.7.2+ renamed to hasCustomInventoryName + @Override + public boolean hasCustomInventoryName() + { + return this.name.length() > 0; + } + + @Override + 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. + */ + // 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); + } + + if ((temp != null) && (temp.stackSize == 0)) { + this.inventory[i] = null; + } + } + } + + @Override + public boolean isUseableByPlayer(final 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 + */ + @Override + public boolean isItemValidForSlot(final int slot, final ItemStack itemstack) { + return (itemstack.getItem() == CI.getNumberedCircuit(0).getItem()); + } + +}
\ No newline at end of file |