2012-12-17 21:21:53 +01:00
|
|
|
package com.pahimar.ee3.tileentity;
|
|
|
|
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
|
|
|
|
2012-12-19 19:09:56 +01:00
|
|
|
import com.pahimar.ee3.lib.Strings;
|
|
|
|
|
2012-12-17 21:21:53 +01:00
|
|
|
/**
|
|
|
|
* TileCalcinator
|
|
|
|
*
|
|
|
|
* Calcinator tile entity, and all the logic associated with it
|
|
|
|
*
|
|
|
|
* @author pahimar
|
|
|
|
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class TileCalcinator extends TileEE implements IInventory {
|
2012-12-19 19:09:56 +01:00
|
|
|
|
|
|
|
/**
|
2012-12-17 21:21:53 +01:00
|
|
|
* The ItemStacks that hold the items currently being used in the Calcinator
|
|
|
|
*/
|
2013-02-12 22:02:40 +01:00
|
|
|
private ItemStack[] inventory;
|
2012-12-17 21:21:53 +01:00
|
|
|
|
2013-02-12 22:02:40 +01:00
|
|
|
public TileCalcinator() {
|
2013-02-18 03:30:11 +01:00
|
|
|
|
2013-02-12 22:02:40 +01:00
|
|
|
inventory = new ItemStack[3];
|
2012-12-19 19:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-12-17 21:21:53 +01:00
|
|
|
* Returns the number of slots in the inventory.
|
|
|
|
*/
|
2012-12-19 19:09:56 +01:00
|
|
|
public int getSizeInventory() {
|
2012-12-17 21:21:53 +01:00
|
|
|
|
2013-02-12 22:02:40 +01:00
|
|
|
return this.inventory.length;
|
2012-12-19 19:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-12-17 21:21:53 +01:00
|
|
|
* Returns the stack in slot i
|
|
|
|
*/
|
2013-02-12 22:02:40 +01:00
|
|
|
public ItemStack getStackInSlot(int slot) {
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2013-02-12 22:02:40 +01:00
|
|
|
return this.inventory[slot];
|
2012-12-19 19:09:56 +01:00
|
|
|
}
|
|
|
|
|
2013-02-12 22:02:40 +01:00
|
|
|
public ItemStack decrStackSize(int slot, int amount) {
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2013-02-12 22:02:40 +01:00
|
|
|
ItemStack itemStack = getStackInSlot(slot);
|
|
|
|
if (itemStack != null) {
|
|
|
|
if (itemStack.stackSize <= amount) {
|
|
|
|
setInventorySlotContents(slot, null);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
itemStack = itemStack.splitStack(amount);
|
|
|
|
if (itemStack.stackSize == 0) {
|
|
|
|
setInventorySlotContents(slot, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemStack;
|
2012-12-19 19:09:56 +01:00
|
|
|
}
|
|
|
|
|
2013-02-12 22:02:40 +01:00
|
|
|
public ItemStack getStackInSlotOnClosing(int slot) {
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2013-02-12 22:02:40 +01:00
|
|
|
ItemStack itemStack = getStackInSlot(slot);
|
|
|
|
if (itemStack != null) {
|
2013-02-18 03:30:11 +01:00
|
|
|
setInventorySlotContents(slot, null);
|
2013-02-12 22:02:40 +01:00
|
|
|
}
|
|
|
|
return itemStack;
|
2012-12-19 19:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-02-12 22:02:40 +01:00
|
|
|
public void setInventorySlotContents(int slot, ItemStack itemStack) {
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2013-02-12 22:02:40 +01:00
|
|
|
inventory[slot] = itemStack;
|
|
|
|
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
|
2013-02-18 03:30:11 +01:00
|
|
|
itemStack.stackSize = getInventoryStackLimit();
|
2013-02-12 22:02:40 +01:00
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getInvName() {
|
|
|
|
|
|
|
|
return "container." + Strings.CALCINATOR_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getInventoryStackLimit() {
|
|
|
|
|
|
|
|
return 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void openChest() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void closeChest() {
|
|
|
|
|
|
|
|
}
|
2013-02-12 22:02:40 +01:00
|
|
|
|
|
|
|
public void readFromNBT(NBTTagCompound nbtTagCompound) {
|
|
|
|
|
|
|
|
super.readFromNBT(nbtTagCompound);
|
|
|
|
|
|
|
|
// Read in the ItemStacks in the inventory from NBT
|
|
|
|
NBTTagList tagList = nbtTagCompound.getTagList("Items");
|
|
|
|
this.inventory = new ItemStack[this.getSizeInventory()];
|
|
|
|
for (int i = 0; i < tagList.tagCount(); ++i) {
|
|
|
|
NBTTagCompound tagCompound = (NBTTagCompound) tagList.tagAt(i);
|
|
|
|
byte slot = tagCompound.getByte("Slot");
|
|
|
|
if (slot >= 0 && slot < this.inventory.length) {
|
|
|
|
this.inventory[slot] = ItemStack.loadItemStackFromNBT(tagCompound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void writeToNBT(NBTTagCompound nbtTagCompound) {
|
|
|
|
|
|
|
|
super.writeToNBT(nbtTagCompound);
|
|
|
|
|
|
|
|
// Write the ItemStacks in the inventory to NBT
|
|
|
|
NBTTagList tagList = new NBTTagList();
|
|
|
|
for (int currentIndex = 0; currentIndex < this.inventory.length; ++currentIndex) {
|
|
|
|
if (this.inventory[currentIndex] != null) {
|
|
|
|
NBTTagCompound tagCompound = new NBTTagCompound();
|
|
|
|
tagCompound.setByte("Slot", (byte) currentIndex);
|
|
|
|
this.inventory[currentIndex].writeToNBT(tagCompound);
|
|
|
|
tagList.appendTag(tagCompound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nbtTagCompound.setTag("Items", tagList);
|
|
|
|
}
|
2013-03-05 04:18:15 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
// public boolean hasCustomName()
|
|
|
|
public boolean func_94042_c() {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
// public boolean canInsertSide(int i, ItemStack itemStack)
|
|
|
|
public boolean func_94041_b(int i, ItemStack itemstack) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-12-17 21:21:53 +01:00
|
|
|
}
|