Skip to content

Commit

Permalink
More Recipe Clean Up
Browse files Browse the repository at this point in the history
  • Loading branch information
Nedelosk committed Jun 23, 2017
1 parent 81e2e18 commit 2c6ed06
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
10 changes: 6 additions & 4 deletions src/main/java/forestry/core/recipes/RecipePair.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@

import javax.annotation.Nullable;

import net.minecraft.util.NonNullList;

import forestry.api.recipes.IForestryRecipe;
import forestry.core.utils.InventoryUtil;

public class RecipePair<R extends IForestryRecipe> {

public static final RecipePair EMPTY = new RecipePair(null, null);

@Nullable
private final R recipe;
@Nullable
private final String[][] oreDictEntries;
private final NonNullList<String> oreDictEntries;

public RecipePair(R recipe, String[][] oreDictEntries) {
this.recipe = recipe;
this.oreDictEntries = oreDictEntries;
this.oreDictEntries = InventoryUtil.getOreDictAsList(oreDictEntries);
}

public boolean isEmpty(){
Expand All @@ -36,7 +38,7 @@ public R getRecipe() {
return recipe;
}

public String[][] getOreDictEntries() {
public NonNullList<String> getOreDictEntries() {
return oreDictEntries;
}
}
5 changes: 2 additions & 3 deletions src/main/java/forestry/factory/tiles/TileCarpenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu

@Nullable
private ICarpenterRecipe currentRecipe;
@Nullable
private String[][] oreDicts;
private NonNullList<String> oreDicts;

private ItemStack getBoxStack() {
return getInternalInventory().getStackInSlot(InventoryCarpenter.SLOT_BOX);
Expand Down Expand Up @@ -199,7 +198,7 @@ private boolean removeItemResources(boolean doRemove) {

NonNullList<ItemStack> craftingSets = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT);
IInventory inventory = new InventoryMapper(getInternalInventory(), InventoryCarpenter.SLOT_INVENTORY_1, InventoryCarpenter.SLOT_INVENTORY_COUNT);
return InventoryUtil.removeSets(inventory, 1, craftingSets, InventoryUtil.getOreDictAsList(oreDicts), null, true, false, doRemove);
return InventoryUtil.removeSets(inventory, 1, craftingSets, oreDicts, null, true, false, doRemove);
}

/* STATE INFORMATION */
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/forestry/factory/tiles/TileFabricator.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ private void craftResult() {

// Remove resources
NonNullList<ItemStack> crafting = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT);
if (removeFromInventory(crafting, myRecipePair.getOreDictEntries(), myRecipe, false)) {
if (removeFromInventory(crafting, myRecipePair, false)) {
FluidStack drained = moltenTank.drainInternal(liquid, false);
if (drained != null && drained.isFluidStackIdentical(liquid)) {
removeFromInventory(crafting, myRecipePair.getOreDictEntries(), myRecipe, true);
removeFromInventory(crafting, myRecipePair, true);
moltenTank.drain(liquid.amount, true);

// Damage plan
Expand All @@ -228,9 +228,9 @@ private void craftResult() {
}
}

private boolean removeFromInventory(NonNullList<ItemStack> set, String[][] oreDicts, IFabricatorRecipe recipe, boolean doRemove) {
private boolean removeFromInventory(NonNullList<ItemStack> set, RecipePair<IFabricatorRecipe> recipePair, boolean doRemove) {
IInventory inventory = new InventoryMapper(this, InventoryFabricator.SLOT_INVENTORY_1, InventoryFabricator.SLOT_INVENTORY_COUNT);
return InventoryUtil.removeSets(inventory, 1, set, InventoryUtil.getOreDictAsList(oreDicts), null, true, false, doRemove);
return InventoryUtil.removeSets(inventory, 1, set, recipePair.getOreDictEntries(), null, true, false, doRemove);
}

@Override
Expand All @@ -241,10 +241,10 @@ public boolean hasWork() {

ItemStack plan = getStackInSlot(InventoryFabricator.SLOT_PLAN);
RecipePair<IFabricatorRecipe> recipePair = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory);
IFabricatorRecipe recipe = recipePair.getRecipe();
if (recipe != null) {
if (!recipePair.isEmpty()) {
IFabricatorRecipe recipe = recipePair.getRecipe();
NonNullList<ItemStack> crafting = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT);
hasResources = removeFromInventory(crafting, recipePair.getOreDictEntries(), recipe, false);
hasResources = removeFromInventory(crafting, recipePair, false);
FluidStack toDrain = recipe.getLiquid();
FluidStack drained = moltenTank.drainInternal(toDrain, false);
hasLiquidResources = drained != null && drained.isFluidStackIdentical(toDrain);
Expand Down

0 comments on commit 2c6ed06

Please sign in to comment.