package com.witchworks.client.gui.container;

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;

/**
 * Created by Joseph on 7/17/2017.
 */
public class ContainerOven extends Container {

	//Todo: Continue, life is getting in the way, as well as a damaged sleep cycle.
	private final IInventory oven;


	public ContainerOven(InventoryPlayer playerInventory, IInventory inventory) {
		this.oven = inventory;

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 6; j++) {
				this.addSlotToContainer(new ContainerOven.SlotItem(inventory, j + i * 6 + 1, 62 + j * 18, 16 + i * 18));
			}
		}

		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < 9; ++j) {
				this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
			}
		}

		for (int k = 0; k < 9; ++k) {
			this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
		}
	}

	public void addListener(IContainerListener listener) {
		super.addListener(listener);
		listener.sendAllWindowProperties(this, this.oven);
	}

	@Override
	public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
		final Slot slot = inventorySlots.get(slotIndex);
		ItemStack copy = ItemStack.EMPTY;

		if (slot != null && slot.getHasStack()) {
			final ItemStack original = slot.getStack();
			copy = original.copy();

			if (slotIndex == 0) {
				if (!mergeItemStack(original, 4, 55, true)) return ItemStack.EMPTY;
				slot.onSlotChange(original, copy);
			} else if (slotIndex > 4) {
				if (original.getCount() == 1 && !mergeItemStack(original, 0, 1, false)) return ItemStack.EMPTY;
				slot.onSlotChange(original, copy);
			} else {
				if (!mergeItemStack(original, 4, 55, true)) return ItemStack.EMPTY;
				slot.onSlotChange(original, copy);
			}

			if (original.getCount() == 0) {
				slot.putStack(ItemStack.EMPTY);
			} else {
				slot.onSlotChanged();
			}

			if (original.getCount() == copy.getCount()) return ItemStack.EMPTY;

			slot.onTake(player, original);
		}

		return copy;
	}

	@Override
	public boolean canInteractWith(EntityPlayer playerIn) {
		return !playerIn.isSpectator();
	}

	private class SlotItem extends Slot {

		SlotItem(IInventory inventoryIn, int slotIndex, int x, int y) {
			super(inventoryIn, slotIndex, x, y);
		}

		public int getItemStackLimit(ItemStack stack) {
			return 64;
		}
	}
}
@@ -186,59 +186,8 @@
 er;%0A
-import net.minecraft.inventory.IContainerListener;%0A
 impo
@@ -505,17 +505,16 @@
  oven;%0A%0A
-%0A
 %09public 
@@ -612,619 +612,8 @@
 ory;
-%0A%0A%09%09for (int i = 0; i %3C 3; i++) %7B%0A%09%09%09for (int j = 0; j %3C 6; j++) %7B%0A%09%09%09%09this.addSlotToContainer(new ContainerOven.SlotItem(inventory, j + i * 6 + 1, 62 + j * 18, 16 + i * 18));%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09for (int i = 0; i %3C 3; ++i) %7B%0A%09%09%09for (int j = 0; j %3C 9; ++j) %7B%0A%09%09%09%09this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09for (int k = 0; k %3C 9; ++k) %7B%0A%09%09%09this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));%0A%09%09%7D%0A%09%7D%0A%0A%09public void addListener(IContainerListener listener) %7B%0A%09%09super.addListener(listener);%0A%09%09listener.sendAllWindowProperties(this, this.oven);
 %0A%09%7D%0A
@@ -1697,160 +1697,9 @@
 %09%7D%0A%0A
-%09private class SlotItem extends Slot %7B%0A%0A%09%09SlotItem(IInventory inventoryIn, int slotIndex, int x, int y) %7B%0A%09%09%09super(inventoryIn, slotIndex, x, y);%0A%09%09%7D%0A%0A%09
+%0A
 %09pub
@@ -1745,17 +1745,16 @@
 ck) %7B%0A%09%09
-%09
 return 6
@@ -1756,16 +1756,12 @@
 urn 64;%0A
-%09%09%7D%0A
 %09%7D%0A%7D

Revert "slapped bits of apiary code onto the oven so i can rework it to function for the oven"