Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.herobrine.future.tile.advancedfurnace;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.IContainerListener;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.Slot;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.crafting.FurnaceRecipes;
- import net.minecraft.tileentity.TileEntityFurnace;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import net.minecraftforge.items.CapabilityItemHandler;
- import net.minecraftforge.items.IItemHandler;
- import net.minecraftforge.items.SlotItemHandler;
- public class ContainerAdvancedFurnace extends Container {
- public final TileAdvancedFurnace te;
- public final InventoryPlayer playerInventory;
- private int fuelLeft, progress, itemOriginalFuel;
- private boolean isBurningBinary;
- public ContainerAdvancedFurnace(InventoryPlayer playerInv, TileAdvancedFurnace te) {
- this.te = te;
- this.playerInventory = playerInv;
- addOwnSlots();
- addPlayerSlots(playerInv);
- }
- private void addOwnSlots() {
- IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
- addSlotToContainer(new SlotItemHandler(handler, 0, 56, 17));
- addSlotToContainer(new SlotItemHandler(handler, 1, 56, 53));
- addSlotToContainer(new SlotItemHandler(handler, 2, 116, 35));
- }
- private void addPlayerSlots(IInventory playerInv) {
- for (int row = 0; row < 3; ++row) {
- for (int col = 0; col < 9; ++col) {//Inventory
- int x = 9 + col * 18 - 1;
- int y = row * 18 + 70 + 14;
- this.addSlotToContainer(new Slot(playerInv, col + row * 9 + 9, x, y));
- }
- }
- for (int row = 0; row < 9; ++row) {//Hotbar
- int x = 9 + row * 18 - 1;
- int y = 58 + 70 + 14;
- this.addSlotToContainer(new Slot(playerInv, row, x, y));
- }
- }
- @Override
- public boolean canInteractWith(EntityPlayer playerIn) {
- return te.canInteractWith(playerIn);
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { // Re-uses the transferStackInSlot from ContainerFurnace
- ItemStack itemstack = ItemStack.EMPTY;
- Slot slot = this.inventorySlots.get(index);
- if (slot != null && slot.getHasStack()) {
- ItemStack itemstack1 = slot.getStack();
- itemstack = itemstack1.copy();
- if (index == 2) {
- if (!this.mergeItemStack(itemstack1, 3, 39, true)) {
- return ItemStack.EMPTY;
- }
- slot.onSlotChange(itemstack1, itemstack);
- }
- else if (index != 1 && index != 0) {
- if (!FurnaceRecipes.instance().getSmeltingResult(itemstack1).isEmpty()) {
- if (!this.mergeItemStack(itemstack1, 0, 1, false)) {
- return ItemStack.EMPTY;
- }
- }
- else if (TileEntityFurnace.isItemFuel(itemstack1)) {
- if (!this.mergeItemStack(itemstack1, 1, 2, false)) {
- return ItemStack.EMPTY;
- }
- }
- else if (index < 30) {
- if (!this.mergeItemStack(itemstack1, 30, 39, false)) {
- return ItemStack.EMPTY;
- }
- }
- else if (index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)) {
- return ItemStack.EMPTY;
- }
- }
- else if (!this.mergeItemStack(itemstack1, 3, 39, false)) {
- return ItemStack.EMPTY;
- }
- if (itemstack1.isEmpty()) {
- slot.putStack(ItemStack.EMPTY);
- }
- else {
- slot.onSlotChanged();
- }
- if (itemstack1.getCount() == itemstack.getCount()) {
- return ItemStack.EMPTY;
- }
- slot.onTake(playerIn, itemstack1);
- }
- return itemstack;
- }
- @Override
- public void detectAndSendChanges() {
- super.detectAndSendChanges();
- for (IContainerListener listener : listeners) {
- if (this.progress != te.progress) listener.sendWindowProperty(this, 1, te.progress);
- if (this.itemOriginalFuel != te.itemOriginalFuel) listener.sendWindowProperty(this, 2, te.itemOriginalFuel);
- if (this.isBurningBinary != te.isBurning) listener.sendWindowProperty(this, 3, boolVal(te.isBurning));
- if (this.fuelLeft != te.fuelLeft) listener.sendWindowProperty(this, 4, te.fuelLeft);
- }
- this.fuelLeft = te.fuelLeft;
- this.progress = te.progress;
- this.itemOriginalFuel = te.itemOriginalFuel;
- this.isBurningBinary = te.isBurning;
- }
- @Override
- @SideOnly(Side.CLIENT)
- public void updateProgressBar(int id, int data) {
- switch (id) {
- case 1: {
- te.progress = data;
- }
- case 2: {
- te.itemOriginalFuel = data;
- }
- case 3: {
- te.isBurning = binVal(data);
- }
- case 4: {
- te.fuelLeft = data;
- }
- }
- }
- @Override
- public void addListener(IContainerListener listener) {
- super.addListener(listener);
- //addListener(listener.sendAllWindowProperties(this, this.te.combinedInventoryHandler);
- }
- protected boolean binVal(int binary) {
- return binary != 0;
- }
- protected int boolVal(boolean bool) {
- return bool ? 1 : 0;
- }
- }
Add Comment
Please, Sign In to add comment