Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package simcraft.machines;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.nbt.NBTTagList;
- import net.minecraft.tileentity.TileEntity;
- import simcraft.core.sound.SoundSource;
- public class TileEntityCommonWorkbench extends TileEntity
- {
- public ItemStack[] inventory;
- private String Localizedname;
- /**
- * Sound Sources Used at Most by Machines.
- */
- public SoundSource audioSource;
- public SoundSource audioSource1;
- public SoundSource audioSource2;
- public TileEntityCommonWorkbench(int var1)
- {
- this.inventory = new ItemStack[var1];
- }
- /**
- * Returns the number of slots in the inventory.
- */
- public int getSizeInventory()
- {
- return this.inventory.length;
- }
- /**
- * Returns the stack in slot i
- */
- public ItemStack getStackInSlot(int var1)
- {
- return this.inventory[var1];
- }
- /**
- * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
- * stack.
- */
- public ItemStack decrStackSize(int var1, int var2)
- {
- if (this.inventory[var1] != null)
- {
- ItemStack var3;
- if (this.inventory[var1].stackSize <= var2)
- {
- var3 = this.inventory[var1];
- this.inventory[var1] = null;
- this.onInventoryChanged();
- return var3;
- }
- else
- {
- var3 = this.inventory[var1].splitStack(var2);
- if (this.inventory[var1].stackSize == 0)
- {
- this.inventory[var1] = null;
- }
- this.onInventoryChanged();
- return var3;
- }
- }
- else
- {
- return null;
- }
- }
- /**
- * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
- * like when you close a workbench GUI.
- */
- public ItemStack getStackInSlotOnClosing(int var1)
- {
- if (this.inventory[var1] == null)
- {
- return null;
- }
- else
- {
- ItemStack var2 = this.inventory[var1];
- this.inventory[var1] = null;
- return var2;
- }
- }
- /**
- * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
- */
- public void setInventorySlotContents(int var1, ItemStack var2)
- {
- this.inventory[var1] = var2;
- if (var2 != null && var2.stackSize > this.getInventoryStackLimit())
- {
- var2.stackSize = this.getInventoryStackLimit();
- }
- this.onInventoryChanged();
- }
- /**
- * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
- * this more of a set than a get?*
- */
- public int getInventoryStackLimit()
- {
- return 64;
- }
- /**
- * Reads a tile entity from NBT.
- */
- public void readFromNBT(NBTTagCompound par1NBTTagCompound)
- {
- super.readFromNBT(par1NBTTagCompound);
- NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items");
- this.inventory = new ItemStack[this.getSizeInventory()];
- if (par1NBTTagCompound.hasKey("CustomName"))
- {
- this.Localizedname = par1NBTTagCompound.getString("CustomName");
- }
- for (int var3 = 0; var3 < nbttaglist.tagCount(); ++var3)
- {
- NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(var3);
- byte var5 = nbttagcompound1.getByte("Slot");
- if (var5 >= 0 && var5 < this.inventory.length)
- {
- this.inventory[var5] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
- }
- }
- }
- /**
- * Writes a tile entity to NBT.
- */
- public void writeToNBT(NBTTagCompound par1NBTTagCompound)
- {
- super.writeToNBT(par1NBTTagCompound);
- NBTTagList nbttaglist = new NBTTagList();
- for (int var3 = 0; var3 < this.inventory.length; ++var3)
- {
- if (this.inventory[var3] != null)
- {
- NBTTagCompound nbttagcompound1 = new NBTTagCompound();
- nbttagcompound1.setByte("Slot", (byte)var3);
- this.inventory[var3].writeToNBT(nbttagcompound1);
- nbttaglist.appendTag(nbttagcompound1);
- }
- }
- par1NBTTagCompound.setTag("Items", nbttaglist);
- if (this.isInvNameLocalized())
- {
- par1NBTTagCompound.setString("CustomName", this.Localizedname);
- }
- }
- public boolean isInvNameLocalized()
- {
- return this.Localizedname != null && this.Localizedname.length() > 0;
- }
- /**
- * Do not make give this method the name canInteractWith because it clashes with Container
- */
- public boolean isUseableByPlayer(EntityPlayer var1)
- {
- return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : var1.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
- }
- public void openChest() {}
- public void closeChest() {}
- }
Advertisement
Add Comment
Please, Sign In to add comment