-
-
Save anonymous/2beb2b00b9f053ffb5fe4d0e143f173d to your computer and use it in GitHub Desktop.
This file contains 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 com.chocolatemod.specialblocks.tileentity; | |
import net.minecraft.block.Block; | |
import net.minecraft.block.BlockFurnace; | |
import net.minecraft.block.material.Material; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.entity.player.InventoryPlayer; | |
import net.minecraft.init.Blocks; | |
import net.minecraft.init.Items; | |
import net.minecraft.inventory.Container; | |
import net.minecraft.inventory.ContainerFurnace; | |
import net.minecraft.inventory.IInventory; | |
import net.minecraft.inventory.ISidedInventory; | |
import net.minecraft.inventory.SlotFurnaceFuel; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemBlock; | |
import net.minecraft.item.ItemHoe; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.item.ItemSword; | |
import net.minecraft.item.ItemTool; | |
import net.minecraft.item.crafting.FurnaceRecipes; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.nbt.NBTTagList; | |
import net.minecraft.server.gui.IUpdatePlayerListBox; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.tileentity.TileEntityLockable; | |
import net.minecraft.util.ChatComponentText; | |
import net.minecraft.util.ChatComponentTranslation; | |
import net.minecraft.util.EnumFacing; | |
import net.minecraft.util.IChatComponent; | |
import net.minecraft.util.MathHelper; | |
import net.minecraftforge.fml.relauncher.Side; | |
import net.minecraftforge.fml.relauncher.SideOnly; | |
public class TileEntityPress extends TileEntity implements IInventory { | |
private ItemStack[] pressItemStacks = new ItemStack[3]; | |
private ItemStack[] inventory; | |
private String customName; | |
public TileEntityPress() { | |
this.inventory = new ItemStack[this.getSizeInventory()]; | |
} | |
public String getCustomName() { | |
return this.customName; | |
} | |
public void setCustomName(String customName) { | |
this.customName = customName; | |
} | |
@Override | |
public String getName() { | |
return this.hasCustomName() ? this.customName : "container.hydraulicPress_tileEntity"; | |
} | |
@Override | |
public boolean hasCustomName() { | |
return this.customName != null && !this.customName.equals(""); | |
} | |
@Override | |
public IChatComponent getDisplayName() { | |
return this.hasCustomName() ? new ChatComponentText(this.getName()) : new ChatComponentTranslation(this.getName()); | |
} | |
@Override | |
public int getSizeInventory() { | |
return this.pressItemStacks.length; | |
} | |
@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).stackSize <= count) { | |
itemstack = this.getStackInSlot(index); | |
this.setInventorySlotContents(index, null); | |
this.markDirty(); | |
return itemstack; | |
} else { | |
itemstack = this.getStackInSlot(index).splitStack(count); | |
if (this.getStackInSlot(index).stackSize <= 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 ItemStack getStackInSlotOnClosing(int index) { | |
ItemStack stack = this.getStackInSlot(index); | |
this.setInventorySlotContents(index, null); | |
return stack; | |
} | |
@Override | |
public void setInventorySlotContents(int index, ItemStack stack) { | |
if (index < 0 || index >= this.getSizeInventory()) | |
return; | |
if (stack != null && stack.stackSize > this.getInventoryStackLimit()) | |
stack.stackSize = this.getInventoryStackLimit(); | |
if (stack != null && stack.stackSize == 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 void writeToNBT(NBTTagCompound nbt) { | |
super.writeToNBT(nbt); | |
NBTTagList list = new NBTTagList(); | |
for (int i = 0; i < this.getSizeInventory(); ++i) { | |
if (this.getStackInSlot(i) != null) { | |
NBTTagCompound stackTag = new NBTTagCompound(); | |
stackTag.setByte("Slot", (byte) i); | |
this.getStackInSlot(i).writeToNBT(stackTag); | |
list.appendTag(stackTag); | |
} | |
} | |
nbt.setTag("Items", list); | |
if (this.hasCustomName()) { | |
nbt.setString("HydraulicPress", this.getCustomName()); | |
} | |
} | |
@Override | |
public void readFromNBT(NBTTagCompound nbt) { | |
super.readFromNBT(nbt); | |
NBTTagList list = nbt.getTagList("Items", 10); | |
for (int i = 0; i < list.tagCount(); ++i) { | |
NBTTagCompound stackTag = list.getCompoundTagAt(i); | |
int slot = stackTag.getByte("Slot") & 255; | |
this.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(stackTag)); | |
} | |
if (nbt.hasKey("HydraulicPress", 8)) { | |
this.setCustomName(nbt.getString("HydraulicPress")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment