@Override public void updateEntity() { if (internalPlayer == null) { internalInventoryCrafting = new InternalInventoryCrafting(); internalPlayer = new InternalPlayer(); craftSlot = new SlotCrafting(internalPlayer, internalInventoryCrafting, craftResult, 0, 0, 0); updateRecipe(); } if (!!worldObj.isRemote) return; if (lastMode == ActionMachineControl.Mode.Off) return; updateRecipe(); searchNeighborsForIngredients(); locateAndBindIngredients(); updateRecipeOutputDisplay(); justCrafted = false; if (canCraftAndOutput()) { if (getEnergy() >= getRequiredEnergy()) { craftItem(); justCrafted = true; } } else { craftable = false; internalInventoryCrafting.tempStacks = null; internalInventoryCrafting.hitCount = null; setEnergy(0); } }
private void updateRecipe() { if (internalInventoryCrafting == null) { return; } internalInventoryCrafting.recipeUpdate(true); if (this.currentRecipe == null || !this.currentRecipe.matches(internalInventoryCrafting, worldObj)) { currentRecipe = CraftingHelper.findMatchingRecipe(internalInventoryCrafting, worldObj); } internalInventoryCrafting.recipeUpdate(false); markDirty(); }
private void updateRecipeOutputDisplay() { if (internalInventoryCrafting == null || currentRecipe == null) { craftResult.setInventorySlotContents(0, null); return; } ItemStack resultStack = getRecipeOutput(); if (resultStack == null) { internalInventoryCrafting.recipeUpdate(true); resultStack = getRecipeOutput(); internalInventoryCrafting.recipeUpdate(false); } craftResult.setInventorySlotContents(0, resultStack); markDirty(); }
private void locateAndBindIngredients() { internalInventoryCrafting.tempStacks = new InventoryCopy(inv).getItemStacks(); internalInventoryCrafting.hitCount = new int[internalInventoryCrafting.tempStacks.length]; ItemStack[] inputSlots = internalInventoryCrafting.tempStacks; for (int gridSlot = 0; gridSlot < craftingSlots.getSizeInventory(); gridSlot++) { internalInventoryCrafting.bindings[gridSlot] = -1; if (craftingSlots.getStackInSlot(gridSlot) == null) continue; boolean foundMatch = false; for (int inputSlot = 0; inputSlot < inputSlots.length; inputSlot++) { if (!isMatchingIngredient(gridSlot, inputSlot)) continue; if (internalInventoryCrafting.hitCount[inputSlot] < inputSlots[inputSlot].stackSize && internalInventoryCrafting.hitCount[inputSlot] < inputSlots[inputSlot].getMaxStackSize()) { internalInventoryCrafting.bindings[gridSlot] = inputSlot; internalInventoryCrafting.hitCount[inputSlot]++; foundMatch = true; break; } } if (!foundMatch) return; } }