Update rolling machine CT support for 1.12 closes #1251
This commit is contained in:
parent
3010afa351
commit
ffe13d0c79
2 changed files with 41 additions and 11 deletions
|
@ -36,6 +36,8 @@ import net.minecraft.util.NonNullList;
|
|||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
@ -45,7 +47,7 @@ import java.util.HashMap;
|
|||
public class RollingMachineRecipe {
|
||||
|
||||
public static final RollingMachineRecipe instance = new RollingMachineRecipe();
|
||||
private final HashMap<ResourceLocation, IRecipe> recipes = new HashMap<>();
|
||||
private static final HashMap<ResourceLocation, IRecipe> recipes = new HashMap<>();
|
||||
|
||||
public void addShapedOreRecipe(ResourceLocation resourceLocation, ItemStack outputItemStack, Object... objectInputs) {
|
||||
Validate.notNull(outputItemStack);
|
||||
|
@ -65,6 +67,18 @@ public class RollingMachineRecipe {
|
|||
recipes.put(resourceLocation, new ShapelessOreRecipe(resourceLocation, outputItemStack, objectInputs));
|
||||
}
|
||||
|
||||
public static ResourceLocation getNameForRecipe(ItemStack output) {
|
||||
ModContainer activeContainer = Loader.instance().activeModContainer();
|
||||
ResourceLocation baseLoc = new ResourceLocation(activeContainer.getModId(), output.getItem().getRegistryName().getResourcePath());
|
||||
ResourceLocation recipeLoc = baseLoc;
|
||||
int index = 0;
|
||||
while (recipes.containsKey(recipeLoc)) {
|
||||
index++;
|
||||
recipeLoc = new ResourceLocation(activeContainer.getModId(), baseLoc.getResourcePath() + "_" + index);
|
||||
}
|
||||
return recipeLoc;
|
||||
}
|
||||
|
||||
public void addRecipe(ResourceLocation resourceLocation, ItemStack output, Object... components) {
|
||||
String s = "";
|
||||
int i = 0;
|
||||
|
|
|
@ -32,6 +32,7 @@ import reborncore.common.util.ItemUtils;
|
|||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import techreborn.api.RollingMachineRecipe;
|
||||
import techreborn.api.TechRebornAPI;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -40,16 +41,15 @@ import java.util.Map;
|
|||
@ZenClass("mods.techreborn.rollingMachine")
|
||||
public class CTRollingMachine {
|
||||
|
||||
//TODO 1.12 Crafttweaker
|
||||
// @ZenMethod
|
||||
// public static void addShaped(IItemStack output, IIngredient[][] ingredients) {
|
||||
// TechRebornAPI.addRollingOreMachinceRecipe(toStack(output), toShapedObjects(ingredients));
|
||||
// }
|
||||
@ZenMethod
|
||||
public static void addShaped(IItemStack output, IIngredient[][] ingredients) {
|
||||
TechRebornAPI.addRollingOreMachinceRecipe(RollingMachineRecipe.getNameForRecipe(CraftTweakerCompat.toStack(output)), CraftTweakerCompat.toStack(output), toShapedObjects(ingredients));
|
||||
}
|
||||
|
||||
// @ZenMethod
|
||||
// public static void addShapeless(IItemStack output, IIngredient[] ingredients) {
|
||||
// TechRebornAPI.addShapelessOreRollingMachinceRecipe(toStack(output), toObjects(ingredients));
|
||||
// }
|
||||
@ZenMethod
|
||||
public static void addShapeless(IItemStack output, IIngredient[] ingredients) {
|
||||
TechRebornAPI.addShapelessOreRollingMachinceRecipe(RollingMachineRecipe.getNameForRecipe(CraftTweakerCompat.toStack(output)), CraftTweakerCompat.toStack(output), toObjects(ingredients));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IItemStack output) {
|
||||
|
@ -63,7 +63,7 @@ public class CTRollingMachine {
|
|||
RollingMachineRecipe.instance.getRecipeList().remove(resourceLocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Object[] toShapedObjects(IIngredient[][] ingredients) {
|
||||
if (ingredients == null)
|
||||
return null;
|
||||
|
@ -86,4 +86,20 @@ public class CTRollingMachine {
|
|||
return prep.toArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static Object[] toObjects(IIngredient[] ingredient) {
|
||||
if (ingredient == null)
|
||||
return null;
|
||||
else {
|
||||
Object[] output = new Object[ingredient.length];
|
||||
for (int i = 0; i < ingredient.length; i++) {
|
||||
if (ingredient[i] != null) {
|
||||
output[i] = CraftTweakerCompat.toObject(ingredient[i]);
|
||||
} else
|
||||
output[i] = "";
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue