Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.limplungs.invcalc.inventories;
- import net.minecraft.client.Minecraft;
- 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 InventoryCalculatorBasic implements IInventory
- {
- private ItemStack[] itemslots = new ItemStack[5];
- public boolean isOn = false;
- public int battery = 0;
- public int batMax = 200;
- public boolean hasBattery = false;
- public boolean hasMirror = false;
- public boolean hasSolar = false;
- public boolean hasClock = false;
- /**
- * @param itemstack
- * - the ItemStack to which this inventory belongs
- */
- public InventoryCalculatorBasic(ItemStack stack)
- {
- if (!stack.hasTagCompound())
- {
- stack.setTagCompound(new NBTTagCompound());
- }
- readFromNBT(stack.getTagCompound());
- }
- @Override
- public int getSizeInventory()
- {
- return itemslots.length;
- }
- @Override
- public ItemStack getStackInSlot(int slot)
- {
- return itemslots[slot];
- }
- @Override
- public ItemStack decrStackSize(int slot, int count)
- {
- ItemStack itemstack = getStackInSlot(slot);
- if (itemstack != null)
- {
- if (itemstack.stackSize <= count)
- {
- setInventorySlotContents(slot, null);
- }
- else
- {
- itemstack = itemstack.splitStack(count);
- markDirty();
- }
- }
- return itemstack;
- }
- @Override
- public ItemStack getStackInSlotOnClosing(int i)
- {
- ItemStack itemstack = getStackInSlot(i);
- setInventorySlotContents(i, null);
- return itemstack;
- }
- @Override
- public void setInventorySlotContents(int i, ItemStack itemstack)
- {
- itemslots[i] = itemstack;
- if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
- {
- itemstack.stackSize = getInventoryStackLimit();
- }
- markDirty();
- }
- @Override
- public String getInventoryName()
- {
- return "iC-Basic";
- }
- @Override
- public boolean hasCustomInventoryName()
- {
- return true;
- }
- @Override
- public int getInventoryStackLimit()
- {
- return 64;
- }
- @Override
- public boolean isUseableByPlayer(EntityPlayer p_70300_1_)
- {
- return true;
- }
- @Override
- public void markDirty()
- {
- for (int i = 0; i < getSizeInventory(); ++i)
- {
- if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0)
- {
- itemslots[i] = null;
- }
- }
- writeToNBT(Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem().getTagCompound());
- }
- @Override
- public boolean isItemValidForSlot(int slot, ItemStack itemstack)
- {
- return true;
- }
- public void writeToNBT(NBTTagCompound compound)
- {
- NBTTagList items = new NBTTagList();
- for (int i = 0; i < getSizeInventory(); i++)
- {
- ItemStack stack = this.getStackInSlot(i);
- if (stack != null)
- {
- NBTTagCompound item = new NBTTagCompound();
- item.setByte("Slot", (byte) i);
- stack.writeToNBT(item);
- items.appendTag(item);
- }
- }
- compound.setTag("Items", items);
- compound.setBoolean("status", this.isOn);
- compound.setInteger("battery", this.battery);
- compound.setInteger("batMax", this.batMax);
- compound.setBoolean("hasBattery", this.hasBattery);
- compound.setBoolean("hasMirror", this.hasMirror);
- compound.setBoolean("hasSolar", this.hasSolar);
- compound.setBoolean("hasClock", this.hasClock);
- }
- public void readFromNBT(NBTTagCompound compound)
- {
- NBTTagList items = compound.getTagList("Items", compound.getId());
- for (int i = 0; i < items.tagCount(); i++)
- {
- NBTTagCompound item = (NBTTagCompound) items.getCompoundTagAt(i);
- byte slot = item.getByte("Slot");
- if (slot >= 0 && slot < this.getSizeInventory())
- {
- this.itemslots[slot] = ItemStack.loadItemStackFromNBT(item);
- }
- }
- this.isOn = compound.getBoolean("status");
- this.battery = compound.getInteger("battery");
- this.batMax = compound.getInteger("batMax");
- this.hasBattery = compound.getBoolean("hasBattery");
- this.hasMirror = compound.getBoolean("hasMirror");
- this.hasSolar = compound.getBoolean("hasSolar");
- this.hasClock = compound.getBoolean("hasClock");
- }
- @Override
- public void openInventory(){}
- @Override
- public void closeInventory(){}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement