Recipes to make the wires when IC2 isn't installed
This commit is contained in:
parent
1c24abda2c
commit
220b74ab94
|
@ -26,19 +26,21 @@ import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class RecipeCoilLength extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {
|
public class RecipeCoilLength extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {
|
||||||
public final ItemStack coil;
|
public final ItemStack coil;
|
||||||
public final Ingredient cable;
|
public final List<Pair<Ingredient, Integer>> cables;
|
||||||
private final int maxLength;
|
private final int maxLength;
|
||||||
|
|
||||||
public RecipeCoilLength(ItemStack coil, Ingredient cable) {
|
public RecipeCoilLength(ItemStack coil, List<Pair<Ingredient, Integer>> cables) {
|
||||||
this.coil = coil;
|
this.coil = coil;
|
||||||
this.cable = cable;
|
this.cables = cables;
|
||||||
maxLength = ItemIC2Coil.getMaxWireLength(this.coil);
|
maxLength = ItemIC2Coil.getMaxWireLength(this.coil);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,26 +83,29 @@ public class RecipeCoilLength extends IForgeRegistryEntry.Impl<IRecipe> implemen
|
||||||
ret.set(i, currStack);
|
ret.set(i, currStack);
|
||||||
ItemIC2Coil.setLength(currStack, -length);
|
ItemIC2Coil.setLength(currStack, -length);
|
||||||
}
|
}
|
||||||
} else if (isCable(curr)) {
|
} else {
|
||||||
length--;
|
length -= getCableLength(curr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getLength(InventoryCrafting inv) {
|
private int getLength(InventoryCrafting inv) {
|
||||||
int cableLength = 0;
|
int totalLength = 0;
|
||||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||||
ItemStack curr = inv.getStackInSlot(i);
|
ItemStack curr = inv.getStackInSlot(i);
|
||||||
if (OreDictionary.itemMatches(curr, coil, false)) {
|
if (OreDictionary.itemMatches(curr, coil, false)) {
|
||||||
cableLength += ItemIC2Coil.getLength(curr);
|
totalLength += ItemIC2Coil.getLength(curr);
|
||||||
} else if (isCable(curr)) {
|
} else {
|
||||||
cableLength++;
|
int slotLength = getCableLength(curr);
|
||||||
} else if (!curr.isEmpty()) {
|
if (slotLength>0) {
|
||||||
return -1;
|
totalLength += slotLength;
|
||||||
|
} else if (!curr.isEmpty()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cableLength;
|
return totalLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -109,8 +114,11 @@ public class RecipeCoilLength extends IForgeRegistryEntry.Impl<IRecipe> implemen
|
||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
NonNullList<Ingredient> ret = NonNullList.withSize(9, Ingredient.EMPTY);
|
NonNullList<Ingredient> ret = NonNullList.withSize(9, Ingredient.EMPTY);
|
||||||
for (int i = 0;i<ret.size();i++) {
|
for (int i = 0;i<ret.size();i++) {
|
||||||
ItemStack[] types = new ItemStack[cable.getMatchingStacks().length+1];
|
int length = 1;
|
||||||
int length = types.length;
|
for (Pair<Ingredient, Integer> cable:cables) {
|
||||||
|
length += cable.getLeft().getMatchingStacks().length;
|
||||||
|
}
|
||||||
|
ItemStack[] types = new ItemStack[length];
|
||||||
int cablePos = 0;
|
int cablePos = 0;
|
||||||
if (r.nextBoolean()) {
|
if (r.nextBoolean()) {
|
||||||
types[length-1] = coil;
|
types[length-1] = coil;
|
||||||
|
@ -118,19 +126,23 @@ public class RecipeCoilLength extends IForgeRegistryEntry.Impl<IRecipe> implemen
|
||||||
types[0] = coil;
|
types[0] = coil;
|
||||||
cablePos = 1;
|
cablePos = 1;
|
||||||
}
|
}
|
||||||
System.arraycopy(cable.getMatchingStacks(), 0, types, cablePos, length-1);
|
for (Pair<Ingredient, Integer> cable : cables) {
|
||||||
|
ItemStack[] matching = cable.getLeft().getMatchingStacks();
|
||||||
|
System.arraycopy(matching, 0, types, cablePos, matching.length);
|
||||||
|
cablePos += matching.length;
|
||||||
|
}
|
||||||
ret.set(i, new UnmatchedIngredient(types));
|
ret.set(i, new UnmatchedIngredient(types));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCable(ItemStack stack) {
|
private int getCableLength(ItemStack stack) {
|
||||||
for (ItemStack curr:cable.getMatchingStacks()) {
|
for (Pair<Ingredient, Integer> ingred:cables) {
|
||||||
if (ItemStack.areItemsEqual(stack, curr) && ItemStack.areItemStackTagsEqual(stack, curr)) {
|
if (ingred.getLeft().apply(stack)) {
|
||||||
return true;
|
return ingred.getRight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//There is probably a better way to do this...
|
//There is probably a better way to do this...
|
||||||
|
|
|
@ -15,17 +15,32 @@
|
||||||
|
|
||||||
package malte0811.industrialWires.crafting.factories;
|
package malte0811.industrialWires.crafting.factories;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import malte0811.industrialWires.crafting.RecipeCoilLength;
|
import malte0811.industrialWires.crafting.RecipeCoilLength;
|
||||||
|
import net.minecraft.item.crafting.Ingredient;
|
||||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||||
import net.minecraftforge.common.crafting.IRecipeFactory;
|
import net.minecraftforge.common.crafting.IRecipeFactory;
|
||||||
import net.minecraftforge.common.crafting.JsonContext;
|
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 {
|
public class WireCoilFactory implements IRecipeFactory {
|
||||||
@Override
|
@Override
|
||||||
public RecipeCoilLength parse(JsonContext context, JsonObject json) {
|
public RecipeCoilLength parse(JsonContext context, JsonObject json) {
|
||||||
JsonObject coil = json.getAsJsonObject("coil");
|
JsonObject coil = json.getAsJsonObject("coil");
|
||||||
JsonObject cable = json.getAsJsonObject("cable");
|
JsonArray cables = json.getAsJsonArray("cables");
|
||||||
return new RecipeCoilLength(CraftingHelper.getItemStack(coil, context), CraftingHelper.getIngredient(cable, context));
|
List<Pair<Ingredient, Integer>> 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
{
|
{
|
||||||
"type": "industrialwires:wire_coil",
|
"type": "industrialwires:wire_coil",
|
||||||
"cable": {
|
"cables": [
|
||||||
"type": "industrialwires:ic2_item",
|
{
|
||||||
"name": "cable",
|
"length": 1,
|
||||||
"variant": "type:copper,insulation:0"
|
"ingredient": {
|
||||||
},
|
"type": "industrialwires:ic2_item",
|
||||||
|
"name": "cable",
|
||||||
|
"variant": "type:copper,insulation:0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 8,
|
||||||
|
"ingredient": {
|
||||||
|
"item": "immersiveengineering:wirecoil",
|
||||||
|
"data": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"coil": {
|
"coil": {
|
||||||
"item": "industrialwires:ic2_wire_coil",
|
"item": "industrialwires:ic2_wire_coil",
|
||||||
"data": 1
|
"data": 1
|
||||||
},
|
}
|
||||||
"conditions": [
|
|
||||||
{
|
|
||||||
"type": "forge:mod_loaded",
|
|
||||||
"modid": "ic2"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
|
@ -1,18 +1,24 @@
|
||||||
{
|
{
|
||||||
"type": "industrialwires:wire_coil",
|
"type": "industrialwires:wire_coil",
|
||||||
"cable": {
|
"cables": [
|
||||||
"type": "industrialwires:ic2_item",
|
{
|
||||||
"name": "cable",
|
"length": 1,
|
||||||
"variant": "type:copper,insulation:1"
|
"ingredient": {
|
||||||
},
|
"type": "industrialwires:ic2_item",
|
||||||
|
"name": "cable",
|
||||||
|
"variant": "type:copper,insulation:1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 8,
|
||||||
|
"ingredient": {
|
||||||
|
"item": "immersiveengineering:wirecoil",
|
||||||
|
"data": 6
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"coil": {
|
"coil": {
|
||||||
"item": "industrialwires:ic2_wire_coil",
|
"item": "industrialwires:ic2_wire_coil",
|
||||||
"data": 6
|
"data": 6
|
||||||
},
|
}
|
||||||
"conditions": [
|
|
||||||
{
|
|
||||||
"type": "forge:mod_loaded",
|
|
||||||
"modid": "ic2"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
|
@ -1,10 +1,13 @@
|
||||||
{
|
{
|
||||||
"type": "industrialwires:wire_coil",
|
"type": "industrialwires:wire_coil",
|
||||||
"cable": {
|
"cables": [{
|
||||||
"type": "industrialwires:ic2_item",
|
"length": 1,
|
||||||
"name": "cable",
|
"ingredient": {
|
||||||
"variant": "type:glass,insulation:0"
|
"type": "industrialwires:ic2_item",
|
||||||
},
|
"name": "cable",
|
||||||
|
"variant": "type:glass,insulation:0"
|
||||||
|
}
|
||||||
|
}],
|
||||||
"coil": {
|
"coil": {
|
||||||
"item": "industrialwires:ic2_wire_coil",
|
"item": "industrialwires:ic2_wire_coil",
|
||||||
"data": 4
|
"data": 4
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
{
|
{
|
||||||
"type": "industrialwires:wire_coil",
|
"type": "industrialwires:wire_coil",
|
||||||
"cable": {
|
"cables": [
|
||||||
"type": "industrialwires:ic2_item",
|
{
|
||||||
"name": "cable",
|
"length": 1,
|
||||||
"variant": "type:gold,insulation:0"
|
"ingredient": {
|
||||||
},
|
"type": "industrialwires:ic2_item",
|
||||||
|
"name": "cable",
|
||||||
|
"variant": "type:gold,insulation:0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 8,
|
||||||
|
"ingredient": {
|
||||||
|
"item": "immersiveengineering:wirecoil",
|
||||||
|
"data": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"coil": {
|
"coil": {
|
||||||
"item": "industrialwires:ic2_wire_coil",
|
"item": "industrialwires:ic2_wire_coil",
|
||||||
"data": 2
|
"data": 2
|
||||||
},
|
}
|
||||||
"conditions": [
|
|
||||||
{
|
|
||||||
"type": "forge:mod_loaded",
|
|
||||||
"modid": "ic2"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
|
@ -1,18 +1,24 @@
|
||||||
{
|
{
|
||||||
"type": "industrialwires:wire_coil",
|
"type": "industrialwires:wire_coil",
|
||||||
"cable": {
|
"cables": [
|
||||||
"type": "industrialwires:ic2_item",
|
{
|
||||||
"name": "cable",
|
"length": 1,
|
||||||
"variant": "type:gold,insulation:2"
|
"ingredient": {
|
||||||
},
|
"type": "industrialwires:ic2_item",
|
||||||
|
"name": "cable",
|
||||||
|
"variant": "type:gold,insulation:2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 8,
|
||||||
|
"ingredient": {
|
||||||
|
"item": "immersiveengineering:wirecoil",
|
||||||
|
"data": 7
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"coil": {
|
"coil": {
|
||||||
"item": "industrialwires:ic2_wire_coil",
|
"item": "industrialwires:ic2_wire_coil",
|
||||||
"data": 7
|
"data": 7
|
||||||
},
|
}
|
||||||
"conditions": [
|
|
||||||
{
|
|
||||||
"type": "forge:mod_loaded",
|
|
||||||
"modid": "ic2"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
|
@ -1,18 +1,24 @@
|
||||||
{
|
{
|
||||||
"type": "industrialwires:wire_coil",
|
"type": "industrialwires:wire_coil",
|
||||||
"cable": {
|
"cables": [
|
||||||
"type": "industrialwires:ic2_item",
|
{
|
||||||
"name": "cable",
|
"length": 1,
|
||||||
"variant": "type:iron,insulation:0"
|
"ingredient": {
|
||||||
},
|
"type": "industrialwires:ic2_item",
|
||||||
|
"name": "cable",
|
||||||
|
"variant": "type:iron,insulation:0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 8,
|
||||||
|
"ingredient": {
|
||||||
|
"item": "immersiveengineering:wirecoil",
|
||||||
|
"data": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"coil": {
|
"coil": {
|
||||||
"item": "industrialwires:ic2_wire_coil",
|
"item": "industrialwires:ic2_wire_coil",
|
||||||
"data": 3
|
"data": 3
|
||||||
},
|
}
|
||||||
"conditions": [
|
|
||||||
{
|
|
||||||
"type": "forge:mod_loaded",
|
|
||||||
"modid": "ic2"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
|
@ -1,10 +1,15 @@
|
||||||
{
|
{
|
||||||
"type": "industrialwires:wire_coil",
|
"type": "industrialwires:wire_coil",
|
||||||
"cable": {
|
"cables": [
|
||||||
"type": "industrialwires:ic2_item",
|
{
|
||||||
"name": "cable",
|
"length": 1,
|
||||||
"variant": "type:tin,insulation:0"
|
"ingredient": {
|
||||||
},
|
"type": "industrialwires:ic2_item",
|
||||||
|
"name": "cable",
|
||||||
|
"variant": "type:tin,insulation:0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"coil": {
|
"coil": {
|
||||||
"item": "industrialwires:ic2_wire_coil",
|
"item": "industrialwires:ic2_wire_coil",
|
||||||
"data": 0
|
"data": 0
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
{
|
{
|
||||||
"type": "industrialwires:wire_coil",
|
"type": "industrialwires:wire_coil",
|
||||||
"cable": {
|
"cables": [{
|
||||||
"type": "industrialwires:ic2_item",
|
"length": 1,
|
||||||
"name": "cable",
|
"ingredient": {
|
||||||
"variant": "type:tin,insulation:1"
|
"type": "industrialwires:ic2_item",
|
||||||
},
|
"name": "cable",
|
||||||
|
"variant": "type:tin,insulation:1"
|
||||||
|
}
|
||||||
|
}],
|
||||||
"coil": {
|
"coil": {
|
||||||
"item": "industrialwires:ic2_wire_coil",
|
"item": "industrialwires:ic2_wire_coil",
|
||||||
"data": 5
|
"data": 5
|
||||||
|
|
Loading…
Reference in a new issue