Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.earthcomputer.farmersheaven;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.ICrafting;
- import net.minecraft.inventory.Slot;
- import net.minecraft.inventory.SlotCrafting;
- import net.minecraft.inventory.SlotFurnaceFuel;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.tileentity.TileEntityFurnace;
- import net.minecraft.util.BlockPos;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.common.FMLCommonHandler;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- public class ContainerAutoCraftingTable extends Container
- {
- private TileEntityAutoCraftingTable craftingTable;
- private int craftTime = 0;
- private int burnTime = 0;
- private int maxBurnTime = 200;
- public ContainerAutoCraftingTable(EntityPlayer player, World world, BlockPos pos)
- {
- TileEntity tileEntity = world.getTileEntity(pos);
- if(tileEntity instanceof TileEntityAutoCraftingTable)
- craftingTable = (TileEntityAutoCraftingTable) tileEntity;
- else craftingTable = null;
- for(int j = 0; j < 3; j++)
- {
- for(int i = 0; i < 3; i++)
- {
- addSlotToContainer(new Slot(craftingTable, i + j * 3, 30 + i * 18, 17 + j * 18));
- }
- }
- addSlotToContainer(new SlotCrafting(player, craftingTable.getInventoryCrafting(), craftingTable, 9, 124, 35) {
- @Override
- public void onPickupFromSlot(EntityPlayer player, ItemStack stack)
- {
- FMLCommonHandler.instance()
- .firePlayerCraftingEvent(player, stack, craftingTable.getInventoryCrafting());
- onCrafting(stack);
- }
- });
- addSlotToContainer(new SlotFurnaceFuel(craftingTable, 10, 93, 55));
- bindPlayerInventory(player.inventory);
- }
- public TileEntityAutoCraftingTable getCraftingTable()
- {
- return craftingTable;
- }
- private void bindPlayerInventory(InventoryPlayer invPlayer)
- {
- // main inventory
- for(int j = 0; j < 3; j++)
- {
- for(int i = 0; i < 9; i++)
- {
- addSlotToContainer(new Slot(invPlayer, i + j * 9 + 9, 8 + i * 18, 84 + j * 18));
- }
- }
- // hotbar
- for(int i = 0; i < 9; i++)
- {
- addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142));
- }
- }
- @Override
- public boolean canInteractWith(EntityPlayer player)
- {
- return craftingTable.isUseableByPlayer(player);
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer player, int index)
- {
- ItemStack itemstack = null;
- Slot slot = (Slot) inventorySlots.get(index);
- if(slot != null && slot.getHasStack())
- {
- ItemStack itemstack1 = slot.getStack();
- itemstack = itemstack1.copy();
- boolean flag = index >= craftingTable.getSizeInventory() && index < craftingTable.getSizeInventory() + 36;
- if(index == 9) // result
- {
- if(!mergeItemStack(itemstack1, craftingTable.getSizeInventory(), craftingTable.getSizeInventory() + 36,
- true)){ return null; }
- }
- else if(!flag) // craft matrix or fuel slot
- {
- if(!this.mergeItemStack(itemstack1, craftingTable.getSizeInventory(),
- craftingTable.getSizeInventory() + 27, false)){ return null; }
- }
- else if(TileEntityFurnace.isItemFuel(itemstack1))
- {
- if(mergeItemStack(itemstack1, 10, 11, false)) flag = false;
- }
- if(flag)
- {
- if(index >= craftingTable.getSizeInventory() && index < craftingTable.getSizeInventory() + 27) // main inventory
- {
- if(!mergeItemStack(itemstack1, craftingTable.getSizeInventory() + 27,
- craftingTable.getSizeInventory() + 36, false)){ return null; }
- }
- else if(index >= craftingTable.getSizeInventory() + 27 && index < craftingTable.getSizeInventory() + 36) // hotbar
- {
- if(!this.mergeItemStack(itemstack1, craftingTable.getSizeInventory(),
- craftingTable.getSizeInventory() + 27, false)){ return null; }
- }
- }
- if(itemstack1.stackSize == 0)
- {
- slot.putStack((ItemStack) null);
- }
- else
- {
- slot.onSlotChanged();
- }
- if(itemstack1.stackSize == itemstack.stackSize){ return null; }
- slot.onPickupFromSlot(player, itemstack1);
- }
- return itemstack;
- }
- @Override
- public void addCraftingToCrafters(ICrafting listener)
- {
- super.addCraftingToCrafters(listener);
- listener.func_175173_a(this, craftingTable);
- }
- @Override
- public void detectAndSendChanges()
- {
- super.detectAndSendChanges();
- for(Object object : crafters)
- {
- ICrafting crafting = (ICrafting) object;
- if(craftTime != craftingTable.getCraftTime())
- crafting.sendProgressBarUpdate(this, 0, craftingTable.getCraftTime());
- if(burnTime != craftingTable.getBurnTime())
- crafting.sendProgressBarUpdate(this, 1, craftingTable.getBurnTime());
- if(maxBurnTime != craftingTable.getMaxBurnTime())
- crafting.sendProgressBarUpdate(this, 2, craftingTable.getMaxBurnTime());
- }
- craftTime = craftingTable.getCraftTime();
- burnTime = craftingTable.getBurnTime();
- maxBurnTime = craftingTable.getMaxBurnTime();
- }
- @Override
- @SideOnly(Side.CLIENT)
- public void updateProgressBar(int id, int newValue)
- {
- craftingTable.setField(id, newValue);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment