Skip to content

Instantly share code, notes, and snippets.

/container.java Secret

Created May 28, 2016
Embed
What would you like to do?
package com.koopamillion.inventory;
import com.koopamillion.slot.SlotOutput;
import com.koopamillion.tile_entity.TileEntityElectricFurnace;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.world.World;
public class ContainerElectricFurnace extends Container{
public final EntityPlayer player;
public final World world;
public final int x;
public final int y;
public final int z;
public TileEntityElectricFurnace tileentity;
public static final int INPUT = 0, OUTPUT = 1;
public ContainerElectricFurnace(EntityPlayer player, World world, int x, int y, int z){
this.player = player;
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.tileentity = (TileEntityElectricFurnace) world.getTileEntity(x, y, z);
this.detectAndSendChanges();
updateSlots();
}
public boolean canInteractWith(EntityPlayer player){
return tileentity.isUseableByPlayer(player);
}
public void updateSlots(){
this.inventorySlots.clear();
this.addSlotToContainer(new Slot(tileentity, INPUT, 56, 35)); //item to smelt
this.addSlotToContainer(new Slot(tileentity, 3, 116, 10)); //upgrades input
this.addSlotToContainer(new SlotOutput(player, tileentity, 4, 152, 28)); //upgrades
this.addSlotToContainer(new SlotOutput(player, tileentity, 5, 152, 10)); //upgrades
this.addSlotToContainer(new SlotOutput(player, tileentity, 6, 152, 46)); //upgrades
this.addSlotToContainer(new SlotOutput(player, tileentity, 7, 152, 64)); //upgrades
this.addSlotToContainer(new Slot(tileentity, 8, 8, 60)); //battery
this.detectAndSendChanges();
this.addSlotToContainer(new SlotOutput(player, tileentity, OUTPUT, 116, 35)); //smelted item
for(int i = 0; i < 3; ++i){
for(int j = 0; j < 9; ++j){
this.addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for(int i = 0; i < 9; ++i){
this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 142)); //ep 33 to watch
}
}
public ItemStack transferStackInSlot(EntityPlayer player, int slotId)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(slotId);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
// If itemstack is in Output stack
if (slotId == OUTPUT)
{
// try to place in player inventory / action bar; add 36+1 because mergeItemStack uses < index,
// so the last slot in the inventory won't get checked if you don't add 1
if (!this.mergeItemStack(itemstack1, OUTPUT+1, OUTPUT+36+1, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
// itemstack is in player inventory, try to place in appropriate furnace slot
else if (slotId != INPUT)
{
// if it can be smelted, place in the input slots
if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null)
{
// try to place in either Input slot; add 1 to final input slot because mergeItemStack uses < index
if (!this.mergeItemStack(itemstack1, INPUT, INPUT+1, false))
{
return null;
}
}
// item in player's inventory, but not in action bar
else if (slotId >= OUTPUT+1 && slotId < OUTPUT+28)
{
// place in action bar
if (!this.mergeItemStack(itemstack1, OUTPUT+28, OUTPUT+37, false))
{
return null;
}
}
// item in action bar - place in player inventory
else if (slotId >= OUTPUT+28 && slotId < OUTPUT+37 && !this.mergeItemStack(itemstack1, OUTPUT+1, OUTPUT+28, false))
{
return null;
}
}
// In one of the infuser slots; try to place in player inventory / action bar
else if (!this.mergeItemStack(itemstack1, OUTPUT+1, OUTPUT+37, 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment