Here it is:
TileEntity
public class CrusherTileEntity extends TileEntity implements IInventory {
private ItemStack[] inventory;
private String customName;
public CrusherTileEntity() {
this.inventory = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < inventory.length; i++) {
inventory[i] = new ItemStack(Blocks.AIR);
}
}
public String getCustomName() {
return this.customName;
}
public void setCustomName(String customName) {
this.customName = customName;
}
@Override
public String getName() {
return this.hasCustomName() ? this.customName : "container:crusher_tile_entity";
}
@Override
public boolean hasCustomName() {
return this.customName != null && !this.customName.equals("");
}
@Nullable
@Override
public ITextComponent getDisplayName() {
return this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName());
}
@Override
public int getSizeInventory() {
return 27;
}
@Override
public ItemStack getStackInSlot(int index) {
if (index < 0 || index >= this.getSizeInventory()) {
return null;
}
return this.inventory[index];
}
@Override
public ItemStack decrStackSize(int index, int count) {
if (this.getStackInSlot(index) != null) {
ItemStack itemstack;
if (this.getStackInSlot(index).func_190916_E() <= count) {
itemstack = this.getStackInSlot(index);
this.setInventorySlotContents(index, null);
this.markDirty();
return itemstack;
} else {
itemstack = this.getStackInSlot(index).splitStack(count);
if (this.getStackInSlot(index).func_190916_E() <= 0) {
this.setInventorySlotContents(index, null);
} else {
//Just to show that changes happened
this.setInventorySlotContents(index, this.getStackInSlot(index));
}
this.markDirty();
return itemstack;
}
} else {
return null;
}
}
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
if (index < 0 || index >= this.getSizeInventory())
return;
if (stack != null && stack.func_190916_E() > this.getInventoryStackLimit())
stack.func_190920_e(this.getInventoryStackLimit());
if (stack != null && stack.func_190916_E() == 0)
stack = null;
this.inventory[index] = stack;
this.markDirty();
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return this.worldObj.getTileEntity(this.getPos()) == this && player.getDistanceSq(this.pos.add(0.5, 0.5, 0.5)) <= 64;
}
@Override
public void openInventory(EntityPlayer player) {
}
@Override
public void closeInventory(EntityPlayer player) {
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
return true;
}
@Override
public int getField(int id) {
return 0;
}
@Override
public void setField(int id, int value) {
}
@Override
public int getFieldCount() {
return 0;
}
@Override
public void clear() {
for (int i = 0; i < this.getSizeInventory(); i++)
this.setInventorySlotContents(i, null);
}
@Override
public boolean func_191420_l() {
return false;
}
@Override
public ItemStack removeStackFromSlot(int index) {
return null;
}
}
Container of the TileEntity
public class ContainerCrusher extends Container {
private CrusherTileEntity crusherTileEntity;
public ContainerCrusher(IInventory iInventory, CrusherTileEntity crusherTileEntity) {
this.crusherTileEntity = crusherTileEntity;
int numRows = crusherTileEntity.getSizeInventory() / 9;
int i = (numRows - 4) * 18;
for (int j = 0; j < numRows; ++j)
{
for (int k = 0; k < 9; ++k)
{
this.addSlotToContainer(new Slot(crusherTileEntity, k + j * 9, 8 + k * 18, 18 + j * 18));
}
}
for (int y = 0; y < 3; ++y) {
for (int x = 0; x < 9; ++x) {
this.addSlotToContainer(new Slot(iInventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
}
}
for (int x = 0; x < 9; ++x) {
this.addSlotToContainer(new Slot(iInventory, x, 8 + x * 18, 142));
}
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return crusherTileEntity.isUseableByPlayer(playerIn);
}
}
Gui of the TileEntity
public class GuiCrusher extends GuiContainer {
private IInventory playerInv;
private CrusherTileEntity crusherTileEntity;
public GuiCrusher(IInventory playerInv, CrusherTileEntity crusherTileEntity) {
super(new ContainerCrusher(playerInv, crusherTileEntity));
this.playerInv = playerInv;
this.crusherTileEntity = crusherTileEntity;
this.xSize = 176;
this.ySize = 166;
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
this.mc.getTextureManager().bindTexture(new ResourceLocation("pureadditions:textures/gui/container/crusher.png"));
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
String s = this.crusherTileEntity.getDisplayName().getUnformattedText();
this.fontRendererObj.drawString(s, 88 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752); //#404040
this.fontRendererObj.drawString(this.playerInv.getDisplayName().getUnformattedText(), 8, 72, 4210752); //#404040
}
}