Created
November 27, 2016 19:31
-
-
Save Keridos/a710f2431a33bb4609431439352067d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package omtteam.omlib.tileentity; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.inventory.ISidedInventory; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.nbt.NBTTagList; | |
import net.minecraft.util.text.ITextComponent; | |
/** | |
* Created by Keridos on 05/12/2015. | |
* This Class | |
*/ | |
public abstract class TileEntityContainer extends TileEntityOwnedBlock implements ISidedInventory { | |
protected ItemStack[] inventory; | |
@Override | |
public NBTTagCompound writeToNBT(NBTTagCompound nbtTagCompound) { | |
super.writeToNBT(nbtTagCompound); | |
NBTTagList itemList = new NBTTagList(); | |
for (int i = 0; i < this.inventory.length; i++) { | |
ItemStack stack = this.getStackInSlot(i); | |
if (stack != null) { | |
NBTTagCompound tag = new NBTTagCompound(); | |
tag.setByte("Slot", (byte) i); | |
stack.writeToNBT(tag); | |
itemList.appendTag(tag); | |
} | |
} | |
nbtTagCompound.setTag("Inventory", itemList); | |
return nbtTagCompound; | |
} | |
@Override | |
public void readFromNBT(NBTTagCompound par1) { | |
super.readFromNBT(par1); | |
NBTTagList tagList = par1.getTagList("Inventory", 10); | |
for (int i = 0; i < tagList.tagCount(); i++) { | |
NBTTagCompound tag = tagList.getCompoundTagAt(i); | |
byte slot = tag.getByte("Slot"); | |
if (slot >= 0 && slot < inventory.length) { | |
inventory[slot] = ItemStack.loadItemStackFromNBT(tag); | |
} | |
} | |
} | |
@Override | |
public ItemStack decrStackSize(int slot, int amt) { | |
ItemStack stack = getStackInSlot(slot); | |
if (stack != null) { | |
if (stack.stackSize <= amt) { | |
setInventorySlotContents(slot, null); | |
} else { | |
stack = stack.splitStack(amt); | |
if (stack.stackSize == 0) { | |
setInventorySlotContents(slot, null); | |
} | |
} | |
} | |
return stack; | |
} | |
@Override | |
public void setInventorySlotContents(int slot, ItemStack stack) { | |
inventory[slot] = stack; | |
if (stack != null && stack.stackSize > getInventoryStackLimit()) { | |
stack.stackSize = getInventoryStackLimit(); | |
} | |
} | |
@Override | |
public int getSizeInventory() { | |
return inventory.length; | |
} | |
@Override | |
public ItemStack getStackInSlot(int slot) { | |
return inventory[slot]; | |
} | |
@Override | |
public int getInventoryStackLimit() { | |
return 64; | |
} | |
@Override | |
public boolean isUseableByPlayer(EntityPlayer player) { | |
return worldObj.getTileEntity(pos) == this && player.getDistanceSq(this.pos.getX() + 0.5, | |
this.pos.getY() + 0.5, | |
this.pos.getZ() + 0.5) < 64; | |
} | |
@Override | |
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) { | |
return false; | |
} | |
@Override | |
public int getField(int id) { | |
return 0; | |
} | |
@Override | |
public void setField(int id, int value) { | |
} | |
@Override | |
public int getFieldCount() { | |
return 0; | |
} | |
@Override | |
public ItemStack removeStackFromSlot(int slot) { | |
ItemStack itemstack = getStackInSlot(slot); | |
setInventorySlotContents(slot, null); | |
return itemstack; | |
} | |
@Override | |
public String getName() { | |
return null; | |
} | |
@Override | |
public ITextComponent getDisplayName() { | |
return null; | |
} | |
@Override | |
public void openInventory(EntityPlayer player) { | |
} | |
@Override | |
public void closeInventory(EntityPlayer player) { | |
} | |
@Override | |
public boolean hasCustomName() { | |
return false; | |
} | |
@Override | |
public void clear() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment