Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.jam.icc.tileentity;
- import java.util.List;
- import java.util.UUID;
- import com.jam.icc.block.BlockItemCollectorChest;
- import com.jam.icc.block.BlockItemCollectorEnderChest;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.Slot;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTBase;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.network.NetworkManager;
- import net.minecraft.network.play.server.SPacketUpdateTileEntity;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.EntitySelectors;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.ITickable;
- import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraftforge.common.capabilities.Capability;
- import net.minecraftforge.items.CapabilityItemHandler;
- import net.minecraftforge.items.IItemHandler;
- import net.minecraftforge.items.ItemHandlerHelper;
- import net.minecraftforge.items.ItemStackHandler;
- public class TileEntityICEC extends TileEntity implements ITickable{
- public static final int SIZE1 = 27;
- int currentTickRate = 20;
- int counter = 0;
- public static UUID playerName;
- // This item handler will hold the inventory slots
- //private ItemStackHandler itemStackHandler = new ItemStackHandler(SIZE) {
- // @Override
- // protected void onContentsChanged(int slot) {
- // // We need to tell the tile entity that something has changed so
- // that the chest contents is persisted
- // TileEntityICEC.this.markDirty();
- // }
- //};
- // This item handler will hold the filter slot
- private ItemStackHandler filterStackHandler = new ItemStackHandler(1) {
- @Override
- protected void onContentsChanged(int slot) {
- // We need to tell the tile entity that something has changed so
- // that the chest c
- //contents is persisted
- TileEntityICEC.this.markDirty();
- }
- };
- private boolean hasBeenCleared;
- @Override
- public void readFromNBT(NBTTagCompound compound) {
- super.readFromNBT(compound);
- if (compound.hasKey("filterItems")) {
- filterStackHandler.deserializeNBT((NBTTagCompound) compound.getTag("filterItems"));
- }
- compound.getUniqueId("playerName");
- }
- @Override
- public NBTTagCompound writeToNBT(NBTTagCompound compound) {
- super.writeToNBT(compound);
- compound.setTag("filterItems", filterStackHandler.serializeNBT());
- return compound;
- }
- private ItemStackHandler ItemHandler = new ItemStackHandler(27) {
- @Override
- protected void onContentsChanged(int slot) {
- /*
- * if the slots in the container changes, change the slots in the players ender chest inventory.
- */
- EntityPlayer player = world.getPlayerEntityByUUID(getTileData().getUniqueId("playerName"));
- for(int i = 0; i < 27; i++)
- {
- player.getInventoryEnderChest().setInventorySlotContents(i, this.getStackInSlot(i));;
- }
- }
- };
- /**
- * Called from the tile entity's block in the onBlockPlacedBy method.
- * @param player
- */
- public void onPlaced(EntityPlayer player)
- {
- playerName = player.getUniqueID();
- this.getTileData().setUniqueId("playerName", playerName);
- }
- public void onOpened(EntityPlayer player)
- {
- for(int i = 0; i < 27; i++)
- {
- ItemHandler.setStackInSlot(i, player.getInventoryEnderChest().getStackInSlot(i));
- }
- }
- /**
- * returns whether or not you are the placer of the tile entity's block.
- * @param player
- * @return
- */
- public boolean isPlacer(EntityPlayer player)
- {
- if(player.getUniqueID().equals(this.getTileData().getUniqueId("playerName")) )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- @Override
- public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
- if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
- return true;
- }
- return super.hasCapability(capability, facing);
- }
- public ItemStackHandler enderstack()
- {
- return ItemHandler;
- }
- public ItemStackHandler filterstack()
- {
- return filterStackHandler;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment