Revert AutoWorkBench changes

Please continue the rewrite, but on the "crafting" branch for the
moment.
This commit is contained in:
CovertJaguar 2013-04-28 10:45:40 -07:00
parent c39ad7242e
commit 4c37a6c7fb
4 changed files with 490 additions and 288 deletions

View file

@ -472,19 +472,6 @@ 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();
@ -500,22 +487,7 @@ 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,50 +27,58 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockAutoWorkbench extends BlockBuildCraft {
private Icon topTexture;
private Icon sideTexture;
public BlockAutoWorkbench(int blockID) {
super(blockID, Material.wood);
this.setHardness(1);
Icon topTexture;
Icon sideTexture;
public BlockAutoWorkbench(int i) {
super(i, Material.wood);
setHardness(1.0F);
}
@Override
public Icon getIcon(int side, int metadata) {
if (side == 1 || side == 0) {
public Icon getIcon(int i, int j) {
if (i == 1 || i == 0)
return topTexture;
}else{
else
return sideTexture;
}
}
@Override
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)) {
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)
return false;
}
if (!CoreProxy.proxy.isRenderWorld(world)) {
player.openGui(BuildCraftFactory.instance, GuiIds.AUTO_CRAFTING_TABLE, world, x, y, z);
entityplayer.openGui(BuildCraftFactory.instance, GuiIds.AUTO_CRAFTING_TABLE, world, i, j, k);
}
return true;
}
@Override
public TileEntity createNewTileEntity(World world) {
public TileEntity createNewTileEntity(World var1) {
return new TileAutoWorkbench();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void addCreativeItems(ArrayList list) {
list.add(new ItemStack(this));
public void addCreativeItems(ArrayList itemList) {
itemList.add(new ItemStack(this));
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister register) {
topTexture = register.registerIcon("buildcraft:autoWorkbench_top");
sideTexture = register.registerIcon("buildcraft:autoWorkbench_side");
public void registerIcons(IconRegister par1IconRegister)
{
topTexture = par1IconRegister.registerIcon("buildcraft:autoWorkbench_top");
sideTexture = par1IconRegister.registerIcon("buildcraft:autoWorkbench_side");
}
}

View file

@ -9,222 +9,393 @@
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.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
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 IInventory craftResult = new InventoryCraftResult();
private InventoryCrafting crafting = new InventoryCrafting(new Container() {
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
return false;
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
}
@Override
public void onCraftMatrixChanged(IInventory inventory) {}
}, 3, 3);
@Override
public void onInventoryChanged() {
craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(crafting, this.worldObj));
super.onInventoryChanged();
}
public IInventory getCraftResult() {
return this.craftResult;
public IRecipe getCurrentRecipe() {
return currentRecipe ;
}
@Override
public int getSizeInventory() {
return this.crafting.getSizeInventory();
return stackList.length;
}
@Override
public ItemStack getStackInSlot(int slot) {
return this.crafting.getStackInSlot(slot);
public ItemStack getStackInSlot(int i) {
return stackList[i];
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
ItemStack item = this.crafting.decrStackSize(slot, amount);
super.onInventoryChanged();
return item;
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;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
this.crafting.setInventorySlotContents(slot, stack);
super.onInventoryChanged();
public void setInventorySlotContents(int i, ItemStack itemstack) {
stackList[i] = itemstack;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
return this.crafting.getStackInSlotOnClosing(slot);
if (this.stackList[slot] == null)
return null;
ItemStack stackToTake = this.stackList[slot];
this.stackList[slot] = null;
return stackToTake;
}
@Override
public String getInvName() {
return "AutoCrafting";
return "";
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) == this;
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this;
}
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 && !item.getItem().hasContainerItem()){
required[slot] = item.copy();
@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);
}
}
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--;
}
}
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 (int index = 0; index < required.length; index++){
if (required[index] != null) return;
}
}
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){
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 (this.canCraft()) 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;
}
}
}
}
public void craft(){
for (int slot = 0; slot < this.getSizeInventory(); slot++){
ItemStack item = this.getStackInSlot(slot);
if (item != null){
if (item.getItem().hasContainerItem()){
ItemStack container = item.getItem().getContainerItemStack(item);
if (container.isItemStackDamageable() && container.getItemDamage() > container.getMaxDamage()){
this.worldObj.playSoundEffect(this.xCoord + 0.5F, this.yCoord + 0.5F, this.zCoord + 0.5F, "random.break", 0.8F, 0.8F + this.worldObj.rand.nextFloat() * 0.4F);
container = null;
}
this.crafting.setInventorySlotContents(slot, container);
}else{
this.decrStackSize(slot, 1);
}
}
}
}
public 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 && !stack.getItem().hasContainerItem()){
return false;
}
}
return true;
return null;
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
Utils.readStacksFromNBT(nbt, "stackList", this);
this.onInventoryChanged();
public void openChest() {
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
Utils.writeStacksToNBT(nbt, "stackList", this);
public void closeChest() {
}
public void openChest() {}
public void closeChest() {}
/* ISPECIALINVENTORY */
@Override
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
return new TransactorRoundRobin(this).add(stack, from, doAdd).stackSize;
@ -232,36 +403,21 @@ public class TileAutoWorkbench extends TileEntity implements ISpecialInventory {
@Override
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
ItemStack item = null;
ItemStack result = this.craftResult.getStackInSlot(0);
if (result != null){
if (!this.canCraft()){
this.refilFromNeibour();
if (!this.canCraft()){
return null;
}
}
if(doRemove) {
this.craft();
}
item = result.copy();
}else{
return null;
}
return new ItemStack[] { item };
return new ItemStack[] { extractItem(doRemove, false) };
}
@Override
public boolean isInvNameLocalized(){
public boolean isInvNameLocalized()
{
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isStackValidForSlot(int slot, ItemStack stack){
public boolean isStackValidForSlot(int i, ItemStack itemstack)
{
// TODO Auto-generated method stub
return false;
}
}
}

View file

@ -9,87 +9,153 @@
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.inventory.SlotCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.stats.AchievementList;
import buildcraft.core.gui.BuildCraftContainer;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.factory.TileAutoWorkbench;
public class ContainerAutoWorkbench extends BuildCraftContainer {
TileAutoWorkbench parent = null;
TileAutoWorkbench tile;
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));
}
}
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));
// 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);
}
CoreProxy.proxy.TakenFromCrafting(thePlayer, itemstack, craftMatrix);
// FIXME: Autocrafting table should post a forge event.
// ForgeHooks.onTakenFromCrafting(thePlayer, itemstack, craftMatrix);
tile.extractItem(true, true);
}
this.onCraftMatrixChanged(parent);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
Slot output = (Slot) inventorySlots.get(slot);
ItemStack itemstack = null;
if (output != null && output.getHasStack()){
ItemStack itemstack1 = output.getStack();
itemstack = itemstack1.copy();
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 {
output.onSlotChanged();
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));
}
}
if (slot == 9){
((SlotCrafting) output).onPickupFromSlot(player, itemstack);
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);
}
@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) {
ItemStack itemstack = null;
Slot slot = (Slot) inventorySlots.get(i);
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.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);
} else {
slot.onSlotChanged();
}
if (itemstack1.stackSize != itemstack.stackSize) {
slot.onPickupFromSlot(pl, itemstack1);
} else
return null;
}
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);
}
}