mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-23 21:39:51 +00:00
Fix #1568 Oredict carpenter problem
This commit is contained in:
1 parent
23a9af3020
commit
00b4b6552c
6 files changed
+86
-41
No files matched your search
@@ -196,16 +196,17 @@ public abstract class RecipeUtil {
|
||||
GameRegistry.addSmelting(res, prod, xp);
|
||||
}
|
||||
|
||||
public static boolean matches(IDescriptiveRecipe recipe, IInventory inventoryCrafting) {
|
||||
public static String[][] matches(IDescriptiveRecipe recipe, IInventory inventoryCrafting) {
|
||||
NonNullList<NonNullList<ItemStack>> recipeIngredients = recipe.getIngredients();
|
||||
NonNullList<String> oreDicts = recipe.getOreDicts();
|
||||
int width = recipe.getWidth();
|
||||
int height = recipe.getHeight();
|
||||
return matches(recipeIngredients, width, height, inventoryCrafting);
|
||||
return matches(recipeIngredients, oreDicts, width, height, inventoryCrafting);
|
||||
}
|
||||
|
||||
public static boolean matches(NonNullList<NonNullList<ItemStack>> recipeIngredients, int width, int height, IInventory inventoryCrafting) {
|
||||
public static String[][] matches(NonNullList<NonNullList<ItemStack>> recipeIngredients, NonNullList<String> oreDicts, int width, int height, IInventory inventoryCrafting) {
|
||||
ItemStack[][] resources = getResources(inventoryCrafting);
|
||||
return matches(recipeIngredients, width, height, resources);
|
||||
return matches(recipeIngredients, oreDicts, width, height, resources);
|
||||
}
|
||||
|
||||
public static ItemStack[][] getResources(IInventory inventoryCrafting) {
|
||||
@@ -219,23 +220,28 @@ public abstract class RecipeUtil {
|
||||
return resources;
|
||||
}
|
||||
|
||||
public static boolean matches(NonNullList<NonNullList<ItemStack>> recipeIngredients, int width, int height, ItemStack[][] resources) {
|
||||
@Nullable
|
||||
public static String[][] matches(NonNullList<NonNullList<ItemStack>> recipeIngredients, NonNullList<String> oreDicts, int width, int height, ItemStack[][] resources) {
|
||||
for (int i = 0; i <= 3 - width; i++) {
|
||||
for (int j = 0; j <= 3 - height; j++) {
|
||||
if (checkMatch(recipeIngredients, width, height, resources, i, j, true)) {
|
||||
return true;
|
||||
String[][] resourceDicts = checkMatch(recipeIngredients, oreDicts, width, height, resources, i, j, true);
|
||||
if (resourceDicts != null) {
|
||||
return resourceDicts;
|
||||
}
|
||||
|
||||
if (checkMatch(recipeIngredients, width, height, resources, i, j, false)) {
|
||||
return true;
|
||||
resourceDicts = checkMatch(recipeIngredients, oreDicts, width, height, resources, i, j, false);
|
||||
if (resourceDicts != null) {
|
||||
return resourceDicts;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean checkMatch(NonNullList<NonNullList<ItemStack>> recipeIngredients, int width, int height, ItemStack[][] resources, int xInGrid, int yInGrid, boolean mirror) {
|
||||
@Nullable
|
||||
private static String[][] checkMatch(NonNullList<NonNullList<ItemStack>> recipeIngredients, NonNullList<String> oreDicts, int width, int height, ItemStack[][] resources, int xInGrid, int yInGrid, boolean mirror) {
|
||||
String[][] resourceDicts = new String[3][3];
|
||||
for (int k = 0; k < 3; k++) {
|
||||
for (int l = 0; l < 3; l++) {
|
||||
ItemStack resource = resources[k][l];
|
||||
@@ -243,22 +249,27 @@ public abstract class RecipeUtil {
|
||||
int widthIt = k - xInGrid;
|
||||
int heightIt = l - yInGrid;
|
||||
NonNullList<ItemStack> recipeIngredient = null;
|
||||
String oreDict = "";
|
||||
|
||||
if (widthIt >= 0 && heightIt >= 0 && widthIt < width && heightIt < height) {
|
||||
int position;
|
||||
if (mirror) {
|
||||
recipeIngredient = recipeIngredients.get(width - widthIt - 1 + heightIt * width);
|
||||
position = width - widthIt - 1 + heightIt * width;
|
||||
} else {
|
||||
recipeIngredient = recipeIngredients.get(widthIt + heightIt * width);
|
||||
position = widthIt + heightIt * width;
|
||||
}
|
||||
recipeIngredient = recipeIngredients.get(position);
|
||||
oreDict = oreDicts.get(position);
|
||||
}
|
||||
|
||||
if (!checkIngredientMatch(recipeIngredient, resource)) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
resourceDicts[k][l] = oreDict;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return resourceDicts;
|
||||
}
|
||||
|
||||
private static boolean checkIngredientMatch(@Nullable NonNullList<ItemStack> recipeIngredient, ItemStack resource) {
|
||||
|
||||
@@ -377,6 +377,19 @@ public abstract class InventoryUtil {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static NonNullList<String> getOreDictAsList(String[][] oreDicts) {
|
||||
NonNullList<String> result = NonNullList.withSize(9, "");
|
||||
if(oreDicts == null || oreDicts.length == 0){
|
||||
return result;
|
||||
}
|
||||
for (int i = 0; i < oreDicts.length; i++) {
|
||||
for (int d = 0; d < oreDicts.length; d++) {
|
||||
result.set(i, oreDicts[i][d]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean tryAddStacksCopy(IInventory inventory, NonNullList<ItemStack> stacks, int startSlot, int slots, boolean all) {
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
package forestry.factory.recipes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -48,30 +51,31 @@ public class CarpenterRecipeManager implements ICarpenterManager {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ICarpenterRecipe findMatchingRecipe(@Nullable FluidStack liquid, ItemStack item, IInventory inventorycrafting) {
|
||||
public static Pair<ICarpenterRecipe, String[][]> findMatchingRecipe(@Nullable FluidStack liquid, ItemStack item, IInventory inventorycrafting) {
|
||||
for (ICarpenterRecipe recipe : recipes) {
|
||||
if (matches(recipe, liquid, item, inventorycrafting)) {
|
||||
return recipe;
|
||||
String[][] resourceDicts = matches(recipe, liquid, item, inventorycrafting);
|
||||
if (resourceDicts != null) {
|
||||
return Pair.of(recipe, resourceDicts);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return Pair.of(null, null);
|
||||
}
|
||||
|
||||
public static boolean matches(@Nullable ICarpenterRecipe recipe, @Nullable FluidStack resource, ItemStack item, IInventory inventoryCrafting) {
|
||||
public static String[][] matches(@Nullable ICarpenterRecipe recipe, @Nullable FluidStack resource, ItemStack item, IInventory inventoryCrafting) {
|
||||
if (recipe == null) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
FluidStack liquid = recipe.getFluidResource();
|
||||
if (liquid != null) {
|
||||
if (resource == null || !resource.containsFluid(liquid)) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack box = recipe.getBox();
|
||||
if (!box.isEmpty() && !ItemStackUtil.isCraftingEquivalent(box, item)) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
IDescriptiveRecipe internal = recipe.getCraftingGridRecipe();
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
package forestry.factory.recipes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -39,19 +42,20 @@ public class FabricatorRecipeManager implements IFabricatorManager {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IFabricatorRecipe findMatchingRecipe(ItemStack plan, IInventory resources) {
|
||||
public static Pair<IFabricatorRecipe, String[][]> findMatchingRecipe(ItemStack plan, IInventory resources) {
|
||||
ItemStack[][] gridResources = RecipeUtil.getResources(resources);
|
||||
|
||||
for (IFabricatorRecipe recipe : recipes) {
|
||||
if (!recipe.getPlan().isEmpty() && !ItemStackUtil.isCraftingEquivalent(recipe.getPlan(), plan)) {
|
||||
continue;
|
||||
}
|
||||
if (RecipeUtil.matches(recipe.getIngredients(), recipe.getWidth(), recipe.getHeight(), gridResources)) {
|
||||
return recipe;
|
||||
String[][] oreDicts = RecipeUtil.matches(recipe.getIngredients(), recipe.getOreDicts(), recipe.getWidth(), recipe.getHeight(), gridResources);
|
||||
if (oreDicts != null) {
|
||||
return Pair.of(recipe, oreDicts);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return Pair.of(null, null);
|
||||
}
|
||||
|
||||
public static boolean isPlan(ItemStack plan) {
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.api.core.IErrorLogic;
|
||||
@@ -57,6 +60,8 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
|
||||
@Nullable
|
||||
private ICarpenterRecipe currentRecipe;
|
||||
@Nullable
|
||||
private String[][] oreDicts;
|
||||
|
||||
private ItemStack getBoxStack() {
|
||||
return getInternalInventory().getStackInSlot(InventoryCarpenter.SLOT_BOX);
|
||||
@@ -109,8 +114,10 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CarpenterRecipeManager.matches(currentRecipe, resourceTank.getFluid(), getBoxStack(), craftingInventory)) {
|
||||
currentRecipe = CarpenterRecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory);
|
||||
if (CarpenterRecipeManager.matches(currentRecipe, resourceTank.getFluid(), getBoxStack(), craftingInventory) == null) {
|
||||
Pair<ICarpenterRecipe, String[][]> recipePair = CarpenterRecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory);
|
||||
currentRecipe = recipePair.getLeft();
|
||||
oreDicts = recipePair.getRight();
|
||||
|
||||
if (currentRecipe != null) {
|
||||
int recipeTime = currentRecipe.getPackagingTime();
|
||||
@@ -186,7 +193,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
|
||||
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, currentRecipe.getCraftingGridRecipe().getOreDicts(), null, true, false, doRemove);
|
||||
return InventoryUtil.removeSets(inventory, 1, craftingSets, InventoryUtil.getOreDictAsList(oreDicts), null, true, false, doRemove);
|
||||
}
|
||||
|
||||
/* STATE INFORMATION */
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.api.core.IErrorLogic;
|
||||
@@ -161,19 +164,20 @@ public class TileFabricator extends TilePowered implements ISlotPickupWatcher, I
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private IFabricatorRecipe getRecipe() {
|
||||
private Pair<IFabricatorRecipe, String[][]> getRecipe() {
|
||||
IInventoryAdapter inventory = getInternalInventory();
|
||||
ItemStack plan = inventory.getStackInSlot(InventoryFabricator.SLOT_PLAN);
|
||||
FluidStack liquid = moltenTank.getFluid();
|
||||
IFabricatorRecipe recipe = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory);
|
||||
Pair<IFabricatorRecipe, String[][]> recipePair = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory);
|
||||
IFabricatorRecipe recipe = recipePair.getLeft();
|
||||
if (liquid != null && recipe != null && !liquid.containsFluid(recipe.getLiquid())) {
|
||||
return null;
|
||||
}
|
||||
return recipe;
|
||||
return recipePair;
|
||||
}
|
||||
|
||||
public ItemStack getResult() {
|
||||
IFabricatorRecipe myRecipe = getRecipe();
|
||||
IFabricatorRecipe myRecipe = getRecipe().getLeft();
|
||||
|
||||
if (myRecipe == null) {
|
||||
return ItemStack.EMPTY;
|
||||
@@ -191,17 +195,18 @@ public class TileFabricator extends TilePowered implements ISlotPickupWatcher, I
|
||||
}
|
||||
|
||||
private void craftResult() {
|
||||
IFabricatorRecipe myRecipe = getRecipe();
|
||||
Pair<IFabricatorRecipe, String[][]> myRecipePair = getRecipe();
|
||||
ItemStack craftResult = getResult();
|
||||
IFabricatorRecipe myRecipe = myRecipePair.getLeft();
|
||||
if (myRecipe != null && !craftResult.isEmpty() && getStackInSlot(InventoryFabricator.SLOT_RESULT).isEmpty()) {
|
||||
FluidStack liquid = myRecipe.getLiquid();
|
||||
|
||||
// Remove resources
|
||||
NonNullList<ItemStack> crafting = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT);
|
||||
if (removeFromInventory(crafting, myRecipe, false)) {
|
||||
if (removeFromInventory(crafting, myRecipePair.getRight(), myRecipe, false)) {
|
||||
FluidStack drained = moltenTank.drainInternal(liquid, false);
|
||||
if (drained != null && drained.isFluidStackIdentical(liquid)) {
|
||||
removeFromInventory(crafting, myRecipe, true);
|
||||
removeFromInventory(crafting, myRecipePair.getRight(), myRecipe, true);
|
||||
moltenTank.drain(liquid.amount, true);
|
||||
|
||||
// Damage plan
|
||||
@@ -219,9 +224,9 @@ public class TileFabricator extends TilePowered implements ISlotPickupWatcher, I
|
||||
}
|
||||
}
|
||||
|
||||
private boolean removeFromInventory(NonNullList<ItemStack> set, IFabricatorRecipe recipe, boolean doRemove) {
|
||||
private boolean removeFromInventory(NonNullList<ItemStack> set, String[][] oreDicts, IFabricatorRecipe recipe, boolean doRemove) {
|
||||
IInventory inventory = new InventoryMapper(this, InventoryFabricator.SLOT_INVENTORY_1, InventoryFabricator.SLOT_INVENTORY_COUNT);
|
||||
return InventoryUtil.removeSets(inventory, 1, set, recipe.getOreDicts(), null, true, false, doRemove);
|
||||
return InventoryUtil.removeSets(inventory, 1, set, InventoryUtil.getOreDictAsList(oreDicts), null, true, false, doRemove);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -231,10 +236,11 @@ public class TileFabricator extends TilePowered implements ISlotPickupWatcher, I
|
||||
boolean hasResources = true;
|
||||
|
||||
ItemStack plan = getStackInSlot(InventoryFabricator.SLOT_PLAN);
|
||||
IFabricatorRecipe recipe = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory);
|
||||
Pair<IFabricatorRecipe, String[][]> recipePair = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory);
|
||||
IFabricatorRecipe recipe = recipePair.getLeft();
|
||||
if (recipe != null) {
|
||||
NonNullList<ItemStack> crafting = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT);
|
||||
hasResources = removeFromInventory(crafting, recipe, false);
|
||||
hasResources = removeFromInventory(crafting, recipePair.getRight(), recipe, false);
|
||||
FluidStack toDrain = recipe.getLiquid();
|
||||
FluidStack drained = moltenTank.drainInternal(toDrain, false);
|
||||
hasLiquidResources = drained != null && drained.isFluidStackIdentical(toDrain);
|
||||
|
||||
Reference in new issue
Block a user