Merge pull request #786 from Need4Speed402/master

Rewritten Auto workbenches - Crowd source testing time!
This commit is contained in:
CovertJaguar 2013-04-27 10:27:04 -07:00
commit a0eab6d603
4 changed files with 291 additions and 482 deletions

View file

@ -472,6 +472,19 @@ public class Utils {
stacks[i] = null;
}
}
public static void readStacksFromNBT(NBTTagCompound nbt, String name, IInventory inv) {
NBTTagList nbttaglist = nbt.getTagList(name);
for (int i = 0; i < inv.getSizeInventory(); ++i)
if (i < nbttaglist.tagCount()) {
NBTTagCompound nbttagcompound2 = (NBTTagCompound) nbttaglist.tagAt(i);
inv.setInventorySlotContents(i, ItemStack.loadItemStackFromNBT(nbttagcompound2));
} else {
inv.setInventorySlotContents(i, null);
}
}
public static void writeStacksToNBT(NBTTagCompound nbt, String name, ItemStack[] stacks) {
NBTTagList nbttaglist = new NBTTagList();
@ -487,7 +500,22 @@ public class Utils {
nbt.setTag(name, nbttaglist);
}
public static void writeStacksToNBT(NBTTagCompound nbt, String name, IInventory inv) {
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < inv.getSizeInventory(); ++i) {
NBTTagCompound cpt = new NBTTagCompound();
nbttaglist.appendTag(cpt);
if (inv.getStackInSlot(i) != null) {
inv.getStackInSlot(i).writeToNBT(cpt);
}
}
nbt.setTag(name, nbttaglist);
}
public static ItemStack consumeItem(ItemStack stack) {
if (stack.stackSize == 1) {
if (stack.getItem().hasContainerItem())

View file

@ -27,58 +27,50 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockAutoWorkbench extends BlockBuildCraft {
private Icon topTexture;
private Icon sideTexture;
Icon topTexture;
Icon sideTexture;
public BlockAutoWorkbench(int i) {
super(i, Material.wood);
setHardness(1.0F);
public BlockAutoWorkbench(int blockID) {
super(blockID, Material.wood);
this.setHardness(1);
}
@Override
public Icon getIcon(int i, int j) {
if (i == 1 || i == 0)
public Icon getIcon(int side, int metadata) {
if (side == 1 || side == 0) {
return topTexture;
else
}else{
return sideTexture;
}
}
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
super.onBlockActivated(world, i, j, k, entityplayer, par6, par7, par8, par9);
// Drop through if the player is sneaking
if (entityplayer.isSneaking())
return false;
if (entityplayer.getCurrentEquippedItem() != null) {
if (entityplayer.getCurrentEquippedItem().getItem() instanceof IItemPipe)
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float blockX, float blockY, float blockZ) {
if (player.isSneaking() || (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof IItemPipe)) {
return false;
}
if (!CoreProxy.proxy.isRenderWorld(world)) {
entityplayer.openGui(BuildCraftFactory.instance, GuiIds.AUTO_CRAFTING_TABLE, world, i, j, k);
player.openGui(BuildCraftFactory.instance, GuiIds.AUTO_CRAFTING_TABLE, world, x, y, z);
}
return true;
}
@Override
public TileEntity createNewTileEntity(World var1) {
public TileEntity createNewTileEntity(World world) {
return new TileAutoWorkbench();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void addCreativeItems(ArrayList itemList) {
itemList.add(new ItemStack(this));
public void addCreativeItems(ArrayList list) {
list.add(new ItemStack(this));
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
topTexture = par1IconRegister.registerIcon("buildcraft:autoWorkbench_top");
sideTexture = par1IconRegister.registerIcon("buildcraft:autoWorkbench_side");
public void registerIcons(IconRegister register) {
topTexture = register.registerIcon("buildcraft:autoWorkbench_top");
sideTexture = register.registerIcon("buildcraft:autoWorkbench_side");
}
}

View file

@ -9,393 +9,235 @@
package buildcraft.factory;
import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.ISidedInventory;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import buildcraft.api.core.Position;
import buildcraft.api.inventory.ISpecialInventory;
import buildcraft.core.inventory.TransactorRoundRobin;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.CraftingHelper;
import buildcraft.core.utils.SidedInventoryAdapter;
import buildcraft.core.utils.Utils;
public class TileAutoWorkbench extends TileEntity implements ISpecialInventory {
private ItemStack stackList[] = new ItemStack[9];
private IRecipe currentRecipe = null;
class LocalInventoryCrafting extends InventoryCrafting {
public LocalInventoryCrafting() {
super(new Container() {
@SuppressWarnings("all")
public boolean isUsableByPlayer(EntityPlayer entityplayer) {
return false;
}
@SuppressWarnings("all")
public boolean canInteractWith(EntityPlayer entityplayer) {
// TODO Auto-generated method stub
return false;
}
}, 3, 3);
// TODO Auto-generated constructor stub
private IInventory craftResult = new InventoryCraftResult();
private InventoryCrafting crafting = new InventoryCrafting(new Container() {
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
return false;
}
@Override
public void onCraftMatrixChanged(IInventory inventory) {}
}, 3, 3);
@Override
public void onInventoryChanged() {
craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(crafting, this.worldObj));
super.onInventoryChanged();
}
public IRecipe getCurrentRecipe() {
return currentRecipe ;
public IInventory getCraftResult() {
return this.craftResult;
}
@Override
public int getSizeInventory() {
return stackList.length;
return this.crafting.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int i) {
return stackList[i];
public ItemStack getStackInSlot(int slot) {
return this.crafting.getStackInSlot(slot);
}
@Override
public ItemStack decrStackSize(int slotId, int count) {
if (stackList[slotId] == null)
return null;
if (stackList[slotId].stackSize > count)
return stackList[slotId].splitStack(count);
ItemStack stack = stackList[slotId];
stackList[slotId] = null;
return stack;
public ItemStack decrStackSize(int slot, int amount) {
ItemStack item = this.crafting.decrStackSize(slot, amount);
this.onInventoryChanged();
return item;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
stackList[i] = itemstack;
public void setInventorySlotContents(int slot, ItemStack stack) {
this.crafting.setInventorySlotContents(slot, stack);
this.onInventoryChanged();
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
if (this.stackList[slot] == null)
return null;
ItemStack stackToTake = this.stackList[slot];
this.stackList[slot] = null;
return stackToTake;
return this.crafting.getStackInSlotOnClosing(slot);
}
@Override
public String getInvName() {
return "";
return "AutoCrafting";
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this;
public boolean isUseableByPlayer(EntityPlayer player) {
return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) == this;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
Utils.readStacksFromNBT(nbttagcompound, "stackList", stackList);
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
Utils.writeStacksToNBT(nbttagcompound, "stackList", stackList);
}
class StackPointer {
IInventory inventory;
int index;
ItemStack item;
}
public ItemStack findRecipe() {
InventoryCrafting craftMatrix = new LocalInventoryCrafting();
for (int i = 0; i < getSizeInventory(); ++i) {
ItemStack stack = getStackInSlot(i);
craftMatrix.setInventorySlotContents(i, stack);
}
if(this.currentRecipe == null || !this.currentRecipe.matches(craftMatrix, worldObj))
currentRecipe = CraftingHelper.findMatchingRecipe(craftMatrix, worldObj);
if(currentRecipe!=null)
return currentRecipe.getCraftingResult(craftMatrix);
return null;
}
public ItemStack extractItem(boolean doRemove, boolean removeRecipe) {
InventoryCrafting craftMatrix = new LocalInventoryCrafting();
LinkedList<StackPointer> pointerList = new LinkedList<StackPointer>();
int itemsToLeave = (removeRecipe ? 0 : 1);
for (int i = 0; i < getSizeInventory(); ++i) {
ItemStack stack = getStackInSlot(i);
if (stack != null) {
if (stack.stackSize <= itemsToLeave) {
StackPointer pointer = getNearbyItem(stack);
if (pointer == null) {
resetPointers(pointerList);
return null;
} else {
pointerList.add(pointer);
}
} else {
StackPointer pointer = new StackPointer();
pointer.inventory = this;
pointer.item = this.decrStackSize(i, 1);
pointer.index = i;
stack = pointer.item;
pointerList.add(pointer);
public void refilFromNeibour(){
//pre-compute to see if there are enough items
{
ItemStack[] required = new ItemStack[this.getSizeInventory()];
for (int slot = 0; slot < this.getSizeInventory(); slot++){
ItemStack item = this.getStackInSlot(slot);
if (item != null && item.stackSize == 1){
required[slot] = item.copy();
}
}
craftMatrix.setInventorySlotContents(i, stack);
}
if(this.currentRecipe == null || !this.currentRecipe.matches(craftMatrix, worldObj))
currentRecipe = buildcraft.core.utils.CraftingHelper.findMatchingRecipe(craftMatrix, worldObj);
ItemStack resultStack = null;
if(currentRecipe != null) {
resultStack = currentRecipe.getCraftingResult(craftMatrix);
}
if (resultStack == null || !doRemove) {
resetPointers(pointerList);
} else {
for (StackPointer p : pointerList) {
// replace with the container where appropriate
if (p.item.getItem().getContainerItem() != null) {
ItemStack newStack = p.item.getItem().getContainerItemStack(p.item);
if (p.item.isItemStackDamageable()) {
if (newStack.getItemDamage() >= p.item.getMaxDamage()) {
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(CoreProxy.proxy.getBuildCraftPlayer(worldObj, xCoord, yCoord, zCoord),
newStack));
this.worldObj.playSoundAtEntity(CoreProxy.proxy.getBuildCraftPlayer(worldObj, xCoord, yCoord, zCoord), "random.break", 0.8F,
0.8F + this.worldObj.rand.nextFloat() * 0.4F);
newStack = null;
}
}
p.inventory.setInventorySlotContents(p.index, newStack);
}
}
}
return resultStack;
}
public void resetPointers(LinkedList<StackPointer> pointers) {
for (StackPointer p : pointers) {
ItemStack item = p.inventory.getStackInSlot(p.index);
if (item == null) {
p.inventory.setInventorySlotContents(p.index, p.item);
} else {
p.inventory.getStackInSlot(p.index).stackSize++;
}
}
}
public StackPointer getNearbyItem(ItemStack stack) {
StackPointer pointer = null;
if (pointer == null) {
pointer = getNearbyItemFromOrientation(stack, ForgeDirection.WEST);
}
if (pointer == null) {
pointer = getNearbyItemFromOrientation(stack, ForgeDirection.EAST);
}
if (pointer == null) {
pointer = getNearbyItemFromOrientation(stack, ForgeDirection.DOWN);
}
if (pointer == null) {
pointer = getNearbyItemFromOrientation(stack, ForgeDirection.UP);
}
if (pointer == null) {
pointer = getNearbyItemFromOrientation(stack, ForgeDirection.NORTH);
}
if (pointer == null) {
pointer = getNearbyItemFromOrientation(stack, ForgeDirection.SOUTH);
}
if (pointer == null) {
pointer = getNearbyItemFromOrientation(stack, ForgeDirection.UNKNOWN);
}
return pointer;
}
public StackPointer getNearbyItemFromOrientation(ItemStack itemStack, ForgeDirection direction) {
TileEntity tile = worldObj.getBlockTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
if (tile instanceof ISpecialInventory) {
// Don't get stuff out of ISpecialInventory for now / we wouldn't
// know how to put it back... And it's not clear if we want to
// have workbenches automatically getting things from one another.
return null;
}
IInventory inventory = null;
if (tile instanceof ISidedInventory){
inventory = new SidedInventoryAdapter((ISidedInventory) tile, direction.getOpposite());
} else if (tile instanceof IInventory) {
inventory = Utils.getInventory((IInventory) tile);
}
if (inventory == null) return null;
for (int j = 0; j < inventory.getSizeInventory(); ++j) {
ItemStack stack = inventory.getStackInSlot(j);
if (stack != null) {
if (stack.stackSize > 0) {
if (stack.itemID == itemStack.itemID) {
if (!stack.isItemStackDamageable()) {
if (stack.itemID == itemStack.itemID && stack.getItemDamage() == itemStack.getItemDamage()) {
inventory.decrStackSize(j, 1);
StackPointer result = new StackPointer();
result.inventory = inventory;
result.index = j;
result.item = stack;
return result;
}
} else {
if (stack.itemID == itemStack.itemID) {
inventory.decrStackSize(j, 1);
StackPointer result = new StackPointer();
result.inventory = inventory;
result.index = j;
result.item = stack;
return result;
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS){
TileEntity tileEntity = this.worldObj.getBlockTileEntity(side.offsetX + this.xCoord, side.offsetY + this.yCoord, side.offsetZ + this.zCoord);
if (tileEntity instanceof IInventory){
IInventory inventory = (IInventory) tileEntity;
ItemStack remaining = null;
for (int slot = 0; slot < inventory.getSizeInventory(); slot++){
ItemStack item = inventory.getStackInSlot(slot);
if (item != null){
remaining = item.copy();
for (int index = 0; index < required.length; index++){
if (required[index] != null && item.isItemEqual(required[index])){
required[index] = null;
if (remaining.stackSize == 1){
remaining = null;
break;
}else{
remaining.stackSize--;
}
}
}
}
}
}
}
for (int index = 0; index < required.length; index++){
if (required[index] != null) return;
}
}
return null;
}
public StackPointer getNearbyItem(int itemId, int damage) {
StackPointer pointer = null;
pointer = getNearbyItemFromOrientation(itemId, damage, ForgeDirection.WEST);
if (pointer == null) {
pointer = getNearbyItemFromOrientation(itemId, damage, ForgeDirection.EAST);
}
if (pointer == null) {
pointer = getNearbyItemFromOrientation(itemId, damage, ForgeDirection.DOWN);
}
if (pointer == null) {
pointer = getNearbyItemFromOrientation(itemId, damage, ForgeDirection.UP);
}
if (pointer == null) {
pointer = getNearbyItemFromOrientation(itemId, damage, ForgeDirection.NORTH);
}
if (pointer == null) {
pointer = getNearbyItemFromOrientation(itemId, damage, ForgeDirection.SOUTH);
}
return pointer;
}
public StackPointer getNearbyItemFromOrientation(int itemId, int damage, ForgeDirection orientation) {
Position p = new Position(xCoord, yCoord, zCoord, orientation);
p.moveForwards(1.0);
TileEntity tile = worldObj.getBlockTileEntity((int) p.x, (int) p.y, (int) p.z);
if (tile instanceof ISpecialInventory) {
// Don't get stuff out of ISpecialInventory for now / we wouldn't
// know how to put it back... And it's not clear if we want to
// have workbenches automatically getting things from one another.
} else if (tile instanceof IInventory) {
IInventory inventory = Utils.getInventory((IInventory) tile);
for (int j = 0; j < inventory.getSizeInventory(); ++j) {
ItemStack stack = inventory.getStackInSlot(j);
if (stack != null && stack.stackSize > 0 && stack.itemID == itemId && stack.getItemDamage() == damage) {
inventory.decrStackSize(j, 1);
StackPointer result = new StackPointer();
result.inventory = inventory;
result.index = j;
result.item = stack;
return result;
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS){
TileEntity tileEntity = this.worldObj.getBlockTileEntity(side.offsetX + this.xCoord, side.offsetY + this.yCoord, side.offsetZ + this.zCoord);
/*
* FIXME: make this support ISidedInvontory. That means forge's and vanilla's implementation
* perhaps have this work with ISpecialInvenotry?
*/
if (tileEntity instanceof IInventory){
IInventory inventory = (IInventory) tileEntity;
for (int slot = 0; slot < inventory.getSizeInventory(); slot++){
ItemStack item = inventory.getStackInSlot(slot);
if (item != null){
boolean refilAll = false;
for (int slot1 = 0; slot1 < this.getSizeInventory(); slot1++){
ItemStack item1 = this.getStackInSlot(slot1);
if (item1 != null && item1.stackSize == 1 && item.isItemEqual(item1)){
item1.stackSize++;
inventory.decrStackSize(slot, 1);
if (slot1 == this.getSizeInventory() - 1) refilAll = true;
}else{
refilAll = false;
}
}
if (refilAll) return;
}
}
}
}
}
private void craft(){
for (int slot = 0; slot < this.getSizeInventory(); slot++){
ItemStack item = this.getStackInSlot(slot);
if (item != null){
this.decrStackSize(slot, 1);
if (item.getItem().hasContainerItem()){
ItemStack item2 = item.getItem().getContainerItemStack(item);
return null;
if (item2.isItemStackDamageable() && item2.getItemDamage() > item2.getMaxDamage()){
this.worldObj.playSoundAtEntity(CoreProxy.proxy.getBuildCraftPlayer(worldObj, xCoord, yCoord, zCoord), "random.break", 0.8F,
0.8F + this.worldObj.rand.nextFloat() * 0.4F);
item2 = null;
}
this.crafting.setInventorySlotContents(slot, item2);
}
}
}
}
private boolean canCraft() {
if (this.craftResult.getStackInSlot(0) == null){
return false;
}
for (int slot = 0; slot < this.getSizeInventory(); slot++){
ItemStack stack = this.getStackInSlot(slot);
if (stack != null && stack.stackSize <= 1){
if (!stack.getItem().hasContainerItem()){
ItemStack item = stack.getItem().getContainerItemStack(stack);
if (item == null || item.stackSize <= 0){
return false;
}
}
}
}
return true;
}
@Override
public void openChest() {
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
Utils.readStacksFromNBT(nbt, "stackList", this);
this.onInventoryChanged();
}
@Override
public void closeChest() {
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
Utils.writeStacksToNBT(nbt, "stackList", this);
}
/* ISPECIALINVENTORY */
public void openChest() {}
public void closeChest() {}
@Override
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
return new TransactorRoundRobin(this).add(stack, from, doAdd).stackSize;
@ -403,21 +245,34 @@ public class TileAutoWorkbench extends TileEntity implements ISpecialInventory {
@Override
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
return new ItemStack[] { extractItem(doRemove, false) };
ItemStack item = null;
ItemStack result = this.craftResult.getStackInSlot(0);
if (result != null){
if (!this.canCraft()){
this.refilFromNeibour();
if (!this.canCraft()){
return new ItemStack[0];
}
}
this.craft();
item = result.copy();
}else{
return new ItemStack[0];
}
return new ItemStack[] { item };
}
@Override
public boolean isInvNameLocalized()
{
// TODO Auto-generated method stub
public boolean isInvNameLocalized(){
return false;
}
@Override
public boolean isStackValidForSlot(int i, ItemStack itemstack)
{
// TODO Auto-generated method stub
public boolean isStackValidForSlot(int slot, ItemStack stack){
return false;
}
}

View file

@ -9,153 +9,87 @@
package buildcraft.factory.gui;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.AchievementList;
import net.minecraft.item.crafting.CraftingManager;
import buildcraft.core.gui.BuildCraftContainer;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.factory.TileAutoWorkbench;
public class ContainerAutoWorkbench extends BuildCraftContainer {
TileAutoWorkbench tile;
TileAutoWorkbench parent = null;
// public InventoryCrafting craftMatrix;
public IInventory craftResult;
public class SlotAutoCrafting extends Slot {
private final IInventory craftMatrix;
private EntityPlayer thePlayer;
public SlotAutoCrafting(EntityPlayer entityplayer, IInventory iinventory, IInventory iinventory1, int i, int j, int k) {
super(iinventory1, i, j, k);
thePlayer = entityplayer;
craftMatrix = iinventory;
}
@Override
public boolean isItemValid(ItemStack itemstack) {
return false;
}
@Override
public void onPickupFromSlot(EntityPlayer pl, ItemStack itemstack) {
CoreProxy.proxy.onCraftingPickup(thePlayer.worldObj, thePlayer, itemstack);
if (itemstack.itemID == Block.workbench.blockID) {
thePlayer.addStat(AchievementList.buildWorkBench, 1);
} else if (itemstack.itemID == Item.pickaxeWood.itemID) {
thePlayer.addStat(AchievementList.buildPickaxe, 1);
} else if (itemstack.itemID == Block.furnaceIdle.blockID) {
thePlayer.addStat(AchievementList.buildFurnace, 1);
} else if (itemstack.itemID == Item.hoeWood.itemID) {
thePlayer.addStat(AchievementList.buildHoe, 1);
} else if (itemstack.itemID == Item.bread.itemID) {
thePlayer.addStat(AchievementList.makeBread, 1);
} else if (itemstack.itemID == Item.cake.itemID) {
thePlayer.addStat(AchievementList.bakeCake, 1);
} else if (itemstack.itemID == Item.pickaxeStone.itemID) {
thePlayer.addStat(AchievementList.buildBetterPickaxe, 1);
} else if (itemstack.itemID == Item.swordWood.itemID) {
thePlayer.addStat(AchievementList.buildSword, 1);
} else if (itemstack.itemID == Block.enchantmentTable.blockID) {
thePlayer.addStat(AchievementList.enchantments, 1);
} else if (itemstack.itemID == Block.bookShelf.blockID) {
thePlayer.addStat(AchievementList.bookcase, 1);
public ContainerAutoWorkbench(InventoryPlayer playerInventory, TileAutoWorkbench tileEntity) {
super(tileEntity.getSizeInventory());
this.parent = tileEntity;
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
this.addSlotToContainer(new Slot(this.parent, y * 3 + x, x * 18 + 30, y * 18 + 17));
}
CoreProxy.proxy.TakenFromCrafting(thePlayer, itemstack, craftMatrix);
// FIXME: Autocrafting table should post a forge event.
// ForgeHooks.onTakenFromCrafting(thePlayer, itemstack, craftMatrix);
tile.extractItem(true, true);
}
}
public ContainerAutoWorkbench(InventoryPlayer inventoryplayer, TileAutoWorkbench tile) {
super(tile.getSizeInventory());
craftResult = new InventoryCraftResult();
this.tile = tile;
addSlotToContainer(new SlotAutoCrafting(inventoryplayer.player, tile, craftResult, 0, 124, 35));
for (int l = 0; l < 3; l++) {
for (int k1 = 0; k1 < 3; k1++) {
addSlotToContainer(new Slot(tile, k1 + l * 3, 30 + k1 * 18, 17 + l * 18));
this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.parent, parent.getCraftResult(), 0, 124, 35));
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 9; y++) {
this.addSlotToContainer(new Slot(playerInventory, x * 9 + y + 9, y * 18 + 8, x * 18 + 84));
}
}
for (int x = 0; x < 9; x++){
this.addSlotToContainer(new Slot(playerInventory, x, x * 18 + 8, 142));
}
for (int i1 = 0; i1 < 3; i1++) {
for (int l1 = 0; l1 < 9; l1++) {
addSlotToContainer(new Slot(inventoryplayer, l1 + i1 * 9 + 9, 8 + l1 * 18, 84 + i1 * 18));
}
}
for (int j1 = 0; j1 < 9; j1++) {
addSlotToContainer(new Slot(inventoryplayer, j1, 8 + j1 * 18, 142));
}
onCraftMatrixChanged(tile);
this.onCraftMatrixChanged(parent);
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
craftResult.setInventorySlotContents(0, tile.findRecipe());
}
@Override
public ItemStack slotClick(int i, int j, int flag, EntityPlayer entityplayer) {
// This call ensures that the ouptut is correctly computed
craftResult.setInventorySlotContents(0, tile.findRecipe());
ItemStack ret = super.slotClick(i, j, flag, entityplayer);
onCraftMatrixChanged(tile);
return ret;
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
return tile.isUseableByPlayer(entityplayer);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer pl, int i) {
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
Slot output = (Slot) inventorySlots.get(slot);
ItemStack itemstack = null;
Slot slot = (Slot) inventorySlots.get(i);
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
if (output != null && output.getHasStack()){
ItemStack itemstack1 = output.getStack();
itemstack = itemstack1.copy();
if (i == 0) {
if (!mergeItemStack(itemstack1, 10, 46, true))
return null;
} else if (i >= 10 && i < 37) {
if (!mergeItemStack(itemstack1, 37, 46, false))
return null;
} else if (i >= 37 && i < 46) {
if (!mergeItemStack(itemstack1, 10, 37, false))
return null;
} else if (!mergeItemStack(itemstack1, 10, 46, false))
return null;
if (itemstack1.stackSize == 0) {
slot.putStack(null);
if (slot == 9 ? !mergeItemStack(itemstack1, 10, 46, true) : slot < 37 ?
slot < 10 ? !this.mergeItemStack(itemstack1, 10, 46, false) : !this.mergeItemStack(itemstack1, 37, 46, false) :
!this.mergeItemStack(itemstack1, 10, 37, false)){
itemstack = null;
}else if (itemstack1.stackSize == 0) {
output.putStack(null);
} else {
slot.onSlotChanged();
output.onSlotChanged();
}
if (itemstack1.stackSize != itemstack.stackSize) {
slot.onPickupFromSlot(pl, itemstack1);
} else
return null;
}
if (slot == 9){
((SlotCrafting) output).onPickupFromSlot(player, itemstack);
}
this.parent.onInventoryChanged();
return itemstack;
}
@Override
protected void retrySlotClick(int par1, int par2, boolean par3, EntityPlayer par4EntityPlayer) {
if (par1 != 9){
super.retrySlotClick(par1, par2, par3, par4EntityPlayer);
}
}
@Override
public void onCraftMatrixChanged(IInventory inventory) {
inventory.onInventoryChanged();
super.onCraftMatrixChanged(inventory);
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return this.parent.isUseableByPlayer(player);
}
}