ControlC ControlC.com

VWE WF CONTAINER

Views: 202Total Chars: 3,322
Created: 10/24/14 6:13:59AM ET
Self Destructs: Never
package com.masseyDev.VWE.Containers;

import com.masseyDev.VWE.Blocks.WeaponsForge;
import com.masseyDev.VWE.TileEntities.TileEntityWeaponsForge;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerEnchantment;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

/**
* Created by Massey Dev on 20/10/2014.
*/
public class ContainerWeaponsForge extends Container {

private TileEntityWeaponsForge WF;

public ContainerWeaponsForge (InventoryPlayer inventoryPlayer, TileEntityWeaponsForge te){

//commonly used vanilla code that adds the player's inventory
bindPlayerInventory(inventoryPlayer);

WF = te;
int a,b,c;
//the Slot constructor takes the IInventory and the slot number in that it binds to
//and the x-y coordinates it resides on-screen
addSlotToContainer(new Slot(WF, 16, 124,/* CORRECTION VALUE */-18 + 29)); // OUTPUT SLOT
for(int i = 0; i != 4; i++){ //INPUT SLOTS
for(int j = 0; j != 4; j++) {
a = (j + (i * 4)); // slot index
b = 17 + j * 18; // X co-ords
c = -17 + i * 18; //Y co-ords
addSlotToContainer(new Slot(WF, a, b, c));
}
}

}

protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
int a,b,c;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
a = j + i * 9 + 9;
b = 8 + j * 18;
c = 60 + i * 18;
addSlotToContainer(new Slot(inventoryPlayer, a, b, c));
}
}

for (int i = 0; i < 9; i++) {
a = i;
b = 8 + i * 18;
c = 118;
addSlotToContainer(new Slot(inventoryPlayer, a, b, c));
}
}

@Override
public boolean canInteractWith(EntityPlayer entityPlayer) {
return WF.isUseableByPlayer(entityPlayer);
}

@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
ItemStack stack = null;
Slot slotObject = (Slot) inventorySlots.get(slot);


//null checks and checks if the item can be stacked (maxStackSize > 1)
if (slotObject != null && slotObject.getHasStack()) {
ItemStack stackInSlot = slotObject.getStack();
stack = stackInSlot.copy();

//merges the item into player inventory since its in the tileEntity
if (slot < 9) {
if (!this.mergeItemStack(stackInSlot, 0, 35, true)) {
return null;
}
}
//places it into the tileEntity is possible since its in the player inventory
else if (!this.mergeItemStack(stackInSlot, 0, 9, false)) {
return null;
}

if (stackInSlot.stackSize == 0) {
slotObject.putStack(null);
} else {
slotObject.onSlotChanged();
}

if (stackInSlot.stackSize == stack.stackSize) {
return null;
}
slotObject.onPickupFromSlot(player, stackInSlot);
}
return stack;
}


}
3,322 chars, 362 words, 101 lines·Create new version