Fix insulated and uninsulated IC2 wires producing the same coils, closes #64

This commit is contained in:
malte0811 2019-01-20 20:30:14 +01:00
parent 86cefa9162
commit 507b5e11d8
2 changed files with 48 additions and 32 deletions

View File

@ -21,11 +21,15 @@ import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.compat.Compat;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraftforge.common.crafting.CompoundIngredient;
import net.minecraftforge.common.crafting.IngredientNBT;
import net.minecraftforge.oredict.OreIngredient;
import techreborn.api.TechRebornAPI;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
public final class IC2TRHelper {
public static Ingredient getStack(String type, String variant) {
@ -34,55 +38,57 @@ public final class IC2TRHelper {
return new OreIngredient("itemRubber");
}
}
Set<ItemStack> stacks = new HashSet<>(Compat.getIC2Item.apply(type, variant));
if (IndustrialWires.hasTechReborn) {
switch (type) {
case "cable":
stacks.add(getTRCable(variant));
break;
case "crafting":
switch (variant) {
case "alloy":
Collection<Ingredient> ingreds;
{
Set<ItemStack> stacks = new HashSet<>(Compat.getIC2Item.apply(type, variant));
if (IndustrialWires.hasTechReborn) {
switch (type) {
case "cable":
stacks.add(getTRCable(variant));
break;
case "crafting":
if ("alloy".equals(variant)) {
stacks.add(TechRebornAPI.subItemRetriever.getPlateByName("advanced_alloy"));
break;
}
break;
case "te":
if (variant.equals("mv_transformer")) {
stacks.add(new ItemStack(TechRebornAPI.getBlock("MV_TRANSFORMER")));
}
}
break;
case "te":
if (variant.equals("mv_transformer")) {
stacks.add(new ItemStack(TechRebornAPI.getBlock("MV_TRANSFORMER")));
}
}
}
stacks.removeIf(ItemStack::isEmpty);
ingreds = stacks.stream().map(MyNBTIngredient::new).collect(Collectors.toList());
}
stacks.removeIf(ItemStack::isEmpty);
if (stacks.isEmpty()) {
if (ingreds.isEmpty()) {
switch (type) {
case "cable":
return getIECable(variant.substring("type:".length(), variant.indexOf(',')));
case "crafting":
switch (variant) {
case "coil":
stacks.add(new ItemStack(IEObjects.blockMetalDecoration0));
ingreds.add(new MyIngredient(new ItemStack(IEObjects.blockMetalDecoration0)));
break;
case "alloy":
return new OreIngredient("plateConstantan");
case "electric_motor":
stacks.add(new ItemStack(IEObjects.itemMaterial, 1, 27));
ingreds.add(new MyIngredient(new ItemStack(IEObjects.itemMaterial, 1, 27)));
break;
case "rubber":
stacks.add(new ItemStack(IEObjects.itemMaterial, 1, 13));
ingreds.add(new MyIngredient(new ItemStack(IEObjects.itemMaterial, 1, 13)));
break;
}
break;
case "te":
if (variant.equals("mv_transformer")) {
stacks.add(new ItemStack(IEObjects.blockConnectors, 1, 7));
ingreds.add(new MyIngredient(new ItemStack(IEObjects.blockConnectors, 1, 7)));
}
}
}
if (stacks.size()==0) {
if (ingreds.size() == 0) {
IndustrialWires.logger.info("No ingredient found for "+type+", "+variant);
}
return Ingredient.fromStacks(stacks.toArray(new ItemStack[0]));
return new MyCompoundIngredient(ingreds);
}
public static ItemStack getTRCable(String variant) {
@ -127,4 +133,22 @@ public final class IC2TRHelper {
type = Character.toUpperCase(type.charAt(0))+type.substring(1);
return new OreIngredient("wire"+type);
}
private static class MyNBTIngredient extends IngredientNBT {
public MyNBTIngredient(ItemStack stack) {
super(stack);
}
}
private static class MyCompoundIngredient extends CompoundIngredient {
public MyCompoundIngredient(Collection<Ingredient> children) {
super(children);
}
}
private static class MyIngredient extends Ingredient {
public MyIngredient(ItemStack stack) {
super(stack);
}
}
}

View File

@ -17,10 +17,8 @@ package malte0811.industrialwires.crafting.factories;
import com.google.gson.JsonObject;
import malte0811.industrialwires.crafting.IC2TRHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraftforge.common.crafting.IIngredientFactory;
import net.minecraftforge.common.crafting.IngredientNBT;
import net.minecraftforge.common.crafting.JsonContext;
import javax.annotation.Nonnull;
@ -33,10 +31,4 @@ public class IC2ItemFactory implements IIngredientFactory {
String variant = json.get("variant").getAsString();
return IC2TRHelper.getStack(name, variant);
}
private class MyNBTIngredient extends IngredientNBT {
public MyNBTIngredient(ItemStack stack) {
super(stack);
}
}
}