Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package phnxflms.unidye;
- import ic2.api.energy.prefab.BasicSink;
- import ic2.api.tile.IWrenchable;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.nbt.NBTTagList;
- import net.minecraft.src.ModLoader;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.world.Explosion;
- public class TileEntityWoolDyer extends TileEntity implements IInventory, IWrenchable{
- protected BasicSink ic2EnergySink = new BasicSink(this, 1000, 1);
- private ItemStack[] inv;
- public int woolCount = 0;
- public TileEntityWoolDyer() {
- inv = new ItemStack[3];
- }
- @Override
- public void onChunkUnload(){
- ic2EnergySink.onChunkUnload();
- super.onChunkUnload();
- }
- public void readFromNBT(NBTTagCompound nbttagcompound){
- super.readFromNBT(nbttagcompound);
- ic2EnergySink.readFromNBT(nbttagcompound);
- this.woolCount = nbttagcompound.getInteger("woolCount");
- NBTTagList tagList = nbttagcompound.getTagList("Inventory");
- for (int i = 0; i < tagList.tagCount(); i++) {
- NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
- byte slot = tag.getByte("Slot");
- if (slot >= 0 && slot < inv.length) {
- inv[slot] = ItemStack.loadItemStackFromNBT(tag);
- }
- }
- }
- public void writeToNBT(NBTTagCompound nbttagcompound){
- super.writeToNBT(nbttagcompound);
- ic2EnergySink.writeToNBT(nbttagcompound);
- nbttagcompound.setInteger("woolCount", woolCount);
- NBTTagList itemList = new NBTTagList();
- for (int i = 0; i < inv.length; i++) {
- ItemStack stack = inv[i];
- if (stack != null) {
- NBTTagCompound tag = new NBTTagCompound();
- tag.setByte("Slot", (byte) i);
- stack.writeToNBT(tag);
- itemList.appendTag(tag);
- }
- }
- nbttagcompound.setTag("Inventory", itemList);
- }
- public void updateEntity(){
- ic2EnergySink.updateEntity();
- }
- @Override
- public void invalidate(){
- ic2EnergySink.invalidate();
- super.invalidate();
- onChunkUnload();
- }
- @Override
- public int getSizeInventory() {
- return inv.length;
- }
- @Override
- public ItemStack getStackInSlot(int i) {
- return inv[i];
- }
- @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 ItemStack getStackInSlotOnClosing(int slot) {
- ItemStack stack = getStackInSlot(slot);
- if (stack != null) {
- setInventorySlotContents(slot, null);
- }
- return stack;
- }
- @Override
- public void setInventorySlotContents(int slot, ItemStack stack) {
- inv[slot] = stack;
- if (stack != null && stack.stackSize > getInventoryStackLimit()) {
- stack.stackSize = getInventoryStackLimit();
- }
- }
- @Override
- public String getInvName() {
- return "unidye.tileentitywooldyer";
- }
- @Override
- public boolean isInvNameLocalized() {
- return false;
- }
- @Override
- public int getInventoryStackLimit() {
- return 64;
- }
- @Override
- public boolean isUseableByPlayer(EntityPlayer entityplayer) {
- return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this &&
- entityplayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
- }
- @Override
- public void openChest() {
- }
- @Override
- public void closeChest() {
- }
- @Override
- public boolean isItemValidForSlot(int i, ItemStack itemstack) {
- return false;
- }
- @Override
- public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
- return false;
- }
- @Override
- public short getFacing() {
- return 0;
- }
- @Override
- public void setFacing(short facing) {
- }
- @Override
- public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
- return true;
- }
- @Override
- public float getWrenchDropRate() {
- return 1F;
- }
- @Override
- public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
- return new ItemStack(Unidye.woolDyer, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement