diff --git a/src/main/java/malte0811/industrialWires/crafting/RecipeCoilLength.java b/src/main/java/malte0811/industrialWires/crafting/RecipeCoilLength.java index 7a94207..94ef9c8 100644 --- a/src/main/java/malte0811/industrialWires/crafting/RecipeCoilLength.java +++ b/src/main/java/malte0811/industrialWires/crafting/RecipeCoilLength.java @@ -26,19 +26,21 @@ import net.minecraft.util.NonNullList; import net.minecraft.world.World; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.registries.IForgeRegistryEntry; +import org.apache.commons.lang3.tuple.Pair; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.List; import java.util.Random; public class RecipeCoilLength extends IForgeRegistryEntry.Impl implements IRecipe { public final ItemStack coil; - public final Ingredient cable; + public final List> cables; private final int maxLength; - public RecipeCoilLength(ItemStack coil, Ingredient cable) { + public RecipeCoilLength(ItemStack coil, List> cables) { this.coil = coil; - this.cable = cable; + this.cables = cables; maxLength = ItemIC2Coil.getMaxWireLength(this.coil); } @@ -81,26 +83,29 @@ public class RecipeCoilLength extends IForgeRegistryEntry.Impl implemen ret.set(i, currStack); ItemIC2Coil.setLength(currStack, -length); } - } else if (isCable(curr)) { - length--; + } else { + length -= getCableLength(curr); } } return ret; } private int getLength(InventoryCrafting inv) { - int cableLength = 0; + int totalLength = 0; for (int i = 0; i < inv.getSizeInventory(); i++) { ItemStack curr = inv.getStackInSlot(i); if (OreDictionary.itemMatches(curr, coil, false)) { - cableLength += ItemIC2Coil.getLength(curr); - } else if (isCable(curr)) { - cableLength++; - } else if (!curr.isEmpty()) { - return -1; + totalLength += ItemIC2Coil.getLength(curr); + } else { + int slotLength = getCableLength(curr); + if (slotLength>0) { + totalLength += slotLength; + } else if (!curr.isEmpty()) { + return -1; + } } } - return cableLength; + return totalLength; } @Nonnull @@ -109,8 +114,11 @@ public class RecipeCoilLength extends IForgeRegistryEntry.Impl implemen Random r = new Random(); NonNullList ret = NonNullList.withSize(9, Ingredient.EMPTY); for (int i = 0;i cable:cables) { + length += cable.getLeft().getMatchingStacks().length; + } + ItemStack[] types = new ItemStack[length]; int cablePos = 0; if (r.nextBoolean()) { types[length-1] = coil; @@ -118,19 +126,23 @@ public class RecipeCoilLength extends IForgeRegistryEntry.Impl implemen types[0] = coil; cablePos = 1; } - System.arraycopy(cable.getMatchingStacks(), 0, types, cablePos, length-1); + for (Pair cable : cables) { + ItemStack[] matching = cable.getLeft().getMatchingStacks(); + System.arraycopy(matching, 0, types, cablePos, matching.length); + cablePos += matching.length; + } ret.set(i, new UnmatchedIngredient(types)); } return ret; } - private boolean isCable(ItemStack stack) { - for (ItemStack curr:cable.getMatchingStacks()) { - if (ItemStack.areItemsEqual(stack, curr) && ItemStack.areItemStackTagsEqual(stack, curr)) { - return true; + private int getCableLength(ItemStack stack) { + for (Pair ingred:cables) { + if (ingred.getLeft().apply(stack)) { + return ingred.getRight(); } } - return false; + return 0; } //There is probably a better way to do this... diff --git a/src/main/java/malte0811/industrialWires/crafting/factories/WireCoilFactory.java b/src/main/java/malte0811/industrialWires/crafting/factories/WireCoilFactory.java index ee597f6..092a574 100644 --- a/src/main/java/malte0811/industrialWires/crafting/factories/WireCoilFactory.java +++ b/src/main/java/malte0811/industrialWires/crafting/factories/WireCoilFactory.java @@ -15,17 +15,32 @@ package malte0811.industrialWires.crafting.factories; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import malte0811.industrialWires.crafting.RecipeCoilLength; +import net.minecraft.item.crafting.Ingredient; import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.common.crafting.IRecipeFactory; import net.minecraftforge.common.crafting.JsonContext; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.ArrayList; +import java.util.List; public class WireCoilFactory implements IRecipeFactory { @Override public RecipeCoilLength parse(JsonContext context, JsonObject json) { JsonObject coil = json.getAsJsonObject("coil"); - JsonObject cable = json.getAsJsonObject("cable"); - return new RecipeCoilLength(CraftingHelper.getItemStack(coil, context), CraftingHelper.getIngredient(cable, context)); + JsonArray cables = json.getAsJsonArray("cables"); + List> cablesList = new ArrayList<>(cables.size()); + for (JsonElement ele:cables) { + JsonObject obj = ele.getAsJsonObject(); + int length = obj.get("length").getAsInt(); + Ingredient ingred = CraftingHelper.getIngredient(obj.getAsJsonObject("ingredient"), context); + cablesList.add(new ImmutablePair<>(ingred, length)); + } + return new RecipeCoilLength(CraftingHelper.getItemStack(coil, context), cablesList); } } diff --git a/src/main/resources/assets/industrialwires/recipes/wire_copper.json b/src/main/resources/assets/industrialwires/recipes/wire_copper.json index fa4589c..d4b0796 100644 --- a/src/main/resources/assets/industrialwires/recipes/wire_copper.json +++ b/src/main/resources/assets/industrialwires/recipes/wire_copper.json @@ -1,18 +1,24 @@ { "type": "industrialwires:wire_coil", - "cable": { - "type": "industrialwires:ic2_item", - "name": "cable", - "variant": "type:copper,insulation:0" - }, + "cables": [ + { + "length": 1, + "ingredient": { + "type": "industrialwires:ic2_item", + "name": "cable", + "variant": "type:copper,insulation:0" + } + }, + { + "length": 8, + "ingredient": { + "item": "immersiveengineering:wirecoil", + "data": 0 + } + } + ], "coil": { "item": "industrialwires:ic2_wire_coil", "data": 1 - }, - "conditions": [ - { - "type": "forge:mod_loaded", - "modid": "ic2" - } - ] + } } \ No newline at end of file diff --git a/src/main/resources/assets/industrialwires/recipes/wire_copper_ins.json b/src/main/resources/assets/industrialwires/recipes/wire_copper_ins.json index 0febd11..9df6f65 100644 --- a/src/main/resources/assets/industrialwires/recipes/wire_copper_ins.json +++ b/src/main/resources/assets/industrialwires/recipes/wire_copper_ins.json @@ -1,18 +1,24 @@ { "type": "industrialwires:wire_coil", - "cable": { - "type": "industrialwires:ic2_item", - "name": "cable", - "variant": "type:copper,insulation:1" - }, + "cables": [ + { + "length": 1, + "ingredient": { + "type": "industrialwires:ic2_item", + "name": "cable", + "variant": "type:copper,insulation:1" + } + }, + { + "length": 8, + "ingredient": { + "item": "immersiveengineering:wirecoil", + "data": 6 + } + } + ], "coil": { "item": "industrialwires:ic2_wire_coil", "data": 6 - }, - "conditions": [ - { - "type": "forge:mod_loaded", - "modid": "ic2" - } - ] + } } \ No newline at end of file diff --git a/src/main/resources/assets/industrialwires/recipes/wire_glass.json b/src/main/resources/assets/industrialwires/recipes/wire_glass.json index ca346a0..2489c83 100644 --- a/src/main/resources/assets/industrialwires/recipes/wire_glass.json +++ b/src/main/resources/assets/industrialwires/recipes/wire_glass.json @@ -1,10 +1,13 @@ { "type": "industrialwires:wire_coil", - "cable": { - "type": "industrialwires:ic2_item", - "name": "cable", - "variant": "type:glass,insulation:0" - }, + "cables": [{ + "length": 1, + "ingredient": { + "type": "industrialwires:ic2_item", + "name": "cable", + "variant": "type:glass,insulation:0" + } + }], "coil": { "item": "industrialwires:ic2_wire_coil", "data": 4 diff --git a/src/main/resources/assets/industrialwires/recipes/wire_gold.json b/src/main/resources/assets/industrialwires/recipes/wire_gold.json index 629e217..1f06cab 100644 --- a/src/main/resources/assets/industrialwires/recipes/wire_gold.json +++ b/src/main/resources/assets/industrialwires/recipes/wire_gold.json @@ -1,18 +1,24 @@ { "type": "industrialwires:wire_coil", - "cable": { - "type": "industrialwires:ic2_item", - "name": "cable", - "variant": "type:gold,insulation:0" - }, + "cables": [ + { + "length": 1, + "ingredient": { + "type": "industrialwires:ic2_item", + "name": "cable", + "variant": "type:gold,insulation:0" + } + }, + { + "length": 8, + "ingredient": { + "item": "immersiveengineering:wirecoil", + "data": 1 + } + } + ], "coil": { "item": "industrialwires:ic2_wire_coil", "data": 2 - }, - "conditions": [ - { - "type": "forge:mod_loaded", - "modid": "ic2" - } - ] + } } \ No newline at end of file diff --git a/src/main/resources/assets/industrialwires/recipes/wire_gold_ins.json b/src/main/resources/assets/industrialwires/recipes/wire_gold_ins.json index 153721d..cf2e17c 100644 --- a/src/main/resources/assets/industrialwires/recipes/wire_gold_ins.json +++ b/src/main/resources/assets/industrialwires/recipes/wire_gold_ins.json @@ -1,18 +1,24 @@ { "type": "industrialwires:wire_coil", - "cable": { - "type": "industrialwires:ic2_item", - "name": "cable", - "variant": "type:gold,insulation:2" - }, + "cables": [ + { + "length": 1, + "ingredient": { + "type": "industrialwires:ic2_item", + "name": "cable", + "variant": "type:gold,insulation:2" + } + }, + { + "length": 8, + "ingredient": { + "item": "immersiveengineering:wirecoil", + "data": 7 + } + } + ], "coil": { "item": "industrialwires:ic2_wire_coil", "data": 7 - }, - "conditions": [ - { - "type": "forge:mod_loaded", - "modid": "ic2" - } - ] + } } \ No newline at end of file diff --git a/src/main/resources/assets/industrialwires/recipes/wire_hv.json b/src/main/resources/assets/industrialwires/recipes/wire_hv.json index 945f441..6a2f806 100644 --- a/src/main/resources/assets/industrialwires/recipes/wire_hv.json +++ b/src/main/resources/assets/industrialwires/recipes/wire_hv.json @@ -1,18 +1,24 @@ { "type": "industrialwires:wire_coil", - "cable": { - "type": "industrialwires:ic2_item", - "name": "cable", - "variant": "type:iron,insulation:0" - }, + "cables": [ + { + "length": 1, + "ingredient": { + "type": "industrialwires:ic2_item", + "name": "cable", + "variant": "type:iron,insulation:0" + } + }, + { + "length": 8, + "ingredient": { + "item": "immersiveengineering:wirecoil", + "data": 2 + } + } + ], "coil": { "item": "industrialwires:ic2_wire_coil", "data": 3 - }, - "conditions": [ - { - "type": "forge:mod_loaded", - "modid": "ic2" - } - ] + } } \ No newline at end of file diff --git a/src/main/resources/assets/industrialwires/recipes/wire_tin.json b/src/main/resources/assets/industrialwires/recipes/wire_tin.json index e98bd58..12162b3 100644 --- a/src/main/resources/assets/industrialwires/recipes/wire_tin.json +++ b/src/main/resources/assets/industrialwires/recipes/wire_tin.json @@ -1,10 +1,15 @@ { "type": "industrialwires:wire_coil", - "cable": { - "type": "industrialwires:ic2_item", - "name": "cable", - "variant": "type:tin,insulation:0" - }, + "cables": [ + { + "length": 1, + "ingredient": { + "type": "industrialwires:ic2_item", + "name": "cable", + "variant": "type:tin,insulation:0" + } + } + ], "coil": { "item": "industrialwires:ic2_wire_coil", "data": 0 diff --git a/src/main/resources/assets/industrialwires/recipes/wire_tin_ins.json b/src/main/resources/assets/industrialwires/recipes/wire_tin_ins.json index 85d8397..951fd97 100644 --- a/src/main/resources/assets/industrialwires/recipes/wire_tin_ins.json +++ b/src/main/resources/assets/industrialwires/recipes/wire_tin_ins.json @@ -1,10 +1,13 @@ { "type": "industrialwires:wire_coil", - "cable": { - "type": "industrialwires:ic2_item", - "name": "cable", - "variant": "type:tin,insulation:1" - }, + "cables": [{ + "length": 1, + "ingredient": { + "type": "industrialwires:ic2_item", + "name": "cable", + "variant": "type:tin,insulation:1" + } + }], "coil": { "item": "industrialwires:ic2_wire_coil", "data": 5