Fixed minetweaker support for AlloyFurnace
This commit is contained in:
parent
eb25b96355
commit
f9823b6ba6
3 changed files with 149 additions and 93 deletions
|
@ -25,7 +25,7 @@ public class CompatManager {
|
||||||
registerCompact(RecipesBiomesOPlenty.class, "BiomesOPlenty");
|
registerCompact(RecipesBiomesOPlenty.class, "BiomesOPlenty");
|
||||||
registerCompact(RecipesThaumcraft.class, "Thaumcraft");
|
registerCompact(RecipesThaumcraft.class, "Thaumcraft");
|
||||||
registerCompact(RecipesForestry.class, "Forestry");
|
registerCompact(RecipesForestry.class, "Forestry");
|
||||||
registerCompact(MinetweakerCompat.class, "MineTweaker");
|
registerCompact(MinetweakerCompat.class, "MineTweaker3");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerCompact(Class<?> moduleClass, String... modid) {
|
public void registerCompact(Class<?> moduleClass, String... modid) {
|
||||||
|
|
|
@ -4,15 +4,18 @@ import minetweaker.IUndoableAction;
|
||||||
import minetweaker.MineTweakerAPI;
|
import minetweaker.MineTweakerAPI;
|
||||||
import minetweaker.api.item.IIngredient;
|
import minetweaker.api.item.IIngredient;
|
||||||
import minetweaker.api.item.IItemStack;
|
import minetweaker.api.item.IItemStack;
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import stanhebben.zenscript.annotations.ZenClass;
|
import stanhebben.zenscript.annotations.ZenClass;
|
||||||
import stanhebben.zenscript.annotations.ZenMethod;
|
import stanhebben.zenscript.annotations.ZenMethod;
|
||||||
import techreborn.api.recipe.IBaseRecipeType;
|
import techreborn.api.recipe.IBaseRecipeType;
|
||||||
import techreborn.api.recipe.RecipeHandler;
|
import techreborn.api.recipe.RecipeHandler;
|
||||||
import techreborn.api.recipe.machines.AlloySmelterRecipe;
|
import techreborn.api.recipe.machines.AlloySmelterRecipe;
|
||||||
|
import techreborn.lib.Reference;
|
||||||
|
import techreborn.util.CraftingHelper;
|
||||||
import techreborn.util.ItemUtils;
|
import techreborn.util.ItemUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mods.techreborn.alloySmelter.addRecipe(<minecraft:gold_ingot>, <minecraft:iron_ingot>, <minecraft:diamond>, 20, 100);
|
* mods.techreborn.alloySmelter.addRecipe(<minecraft:gold_ingot>, <minecraft:iron_ingot>, <minecraft:diamond>, 20, 100);
|
||||||
*/
|
*/
|
||||||
|
@ -20,91 +23,52 @@ import techreborn.util.ItemUtils;
|
||||||
@ZenClass("mods.techreborn.alloySmelter")
|
@ZenClass("mods.techreborn.alloySmelter")
|
||||||
public class MTAlloySmelter {
|
public class MTAlloySmelter {
|
||||||
|
|
||||||
@ZenMethod
|
|
||||||
public static void addRecipe(IItemStack output, IItemStack input1, IItemStack input2, int ticktime, int eutick) {
|
|
||||||
MineTweakerAPI.apply(new AddRecipeAction(input1, input2, output, ticktime, eutick));
|
|
||||||
}
|
|
||||||
|
|
||||||
@ZenMethod
|
@ZenMethod
|
||||||
public static void remove(IIngredient output) {
|
public static void addRecipe(IItemStack output, IIngredient input1, IIngredient input2, int ticktime, int euTick) {
|
||||||
for (IBaseRecipeType recipeType : RecipeHandler.recipeList) {
|
ItemStack oInput1 = (ItemStack) MinetweakerCompat.toObject(input1);
|
||||||
if (recipeType.getRecipeName().equals("alloySmelterRecipe")) {
|
if (oInput1 == null)
|
||||||
for (ItemStack outputstack : recipeType.getOutputs()) {
|
return;
|
||||||
if (ItemUtils.isItemEqual(MineTweakerMC.getItemStack(output), outputstack, true, false, false)) {
|
|
||||||
MineTweakerAPI.apply(new RemoveRecipeAction(recipeType));
|
ItemStack oInput2 = (ItemStack) MinetweakerCompat.toObject(input2);
|
||||||
}
|
if (oInput2 == null)
|
||||||
}
|
return;
|
||||||
}
|
|
||||||
}
|
AlloySmelterRecipe r = new AlloySmelterRecipe(oInput1, oInput2, MinetweakerCompat.toStack(output), ticktime, euTick);
|
||||||
|
|
||||||
|
MineTweakerAPI.apply(new Add(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class AddRecipeAction extends AlloySmelterRecipe implements IUndoableAction {
|
private static class Add implements IUndoableAction {
|
||||||
|
private final AlloySmelterRecipe recipe;
|
||||||
|
|
||||||
public AddRecipeAction(IItemStack input1, IItemStack input2, IItemStack output1, int tickTime, int euPerTick) {
|
public Add(AlloySmelterRecipe recipe) {
|
||||||
super(MineTweakerMC.getItemStack(input1), MineTweakerMC.getItemStack(input2), MineTweakerMC.getItemStack(output1), tickTime, euPerTick);
|
this.recipe = recipe;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
RecipeHandler.addRecipe(this);
|
RecipeHandler.addRecipe(recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUndo() {
|
public boolean canUndo() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undo() {
|
public void undo() {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
return "Adding recipe to the alloy furnace";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "Removing recipe to the alloy furnace";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class RemoveRecipeAction implements IUndoableAction {
|
|
||||||
private final IBaseRecipeType recipe;
|
|
||||||
|
|
||||||
public RemoveRecipeAction(IBaseRecipeType recipeType) {
|
|
||||||
this.recipe = recipeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
RecipeHandler.recipeList.remove(recipe);
|
RecipeHandler.recipeList.remove(recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String describe() {
|
public String describe() {
|
||||||
return "Removing" + recipe.getUserFreindlyName() + "recipe";
|
return "Adding Alloy Smelter Recipe for " + recipe.getOutput(0).getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String describeUndo() {
|
public String describeUndo() {
|
||||||
return "Restoring" + recipe.getUserFreindlyName() + "recipe";
|
return "Removing Alloy Smelter Recipe for " + recipe.getOutput(0).getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -112,4 +76,64 @@ public class MTAlloySmelter {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ZenMethod
|
||||||
|
public static void removeRecipe(IItemStack output)
|
||||||
|
{
|
||||||
|
MineTweakerAPI.apply(new Remove(MinetweakerCompat.toStack(output)));
|
||||||
|
}
|
||||||
|
private static class Remove implements IUndoableAction
|
||||||
|
{
|
||||||
|
private final ItemStack output;
|
||||||
|
List<AlloySmelterRecipe> removedRecipes;
|
||||||
|
public Remove(ItemStack output)
|
||||||
|
{
|
||||||
|
this.output = output;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void apply()
|
||||||
|
{
|
||||||
|
for(IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)){
|
||||||
|
for(ItemStack stack : recipeType.getOutputs()){
|
||||||
|
if(ItemUtils.isItemEqual(stack, output, true, false)){
|
||||||
|
removedRecipes.add((AlloySmelterRecipe) recipeType);
|
||||||
|
RecipeHandler.recipeList.remove(recipeType);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void undo()
|
||||||
|
{
|
||||||
|
if(removedRecipes!=null){
|
||||||
|
for(AlloySmelterRecipe recipe : removedRecipes){
|
||||||
|
if(recipe!=null){
|
||||||
|
RecipeHandler.addRecipe(recipe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String describe()
|
||||||
|
{
|
||||||
|
return "Removing Alloy Smelter Recipe for " + output.getDisplayName();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String describeUndo()
|
||||||
|
{
|
||||||
|
return "Re-Adding Alloy Smelter Recipe for " + output.getDisplayName();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Object getOverrideKey()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean canUndo()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,20 @@ import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||||
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||||
import minetweaker.MineTweakerAPI;
|
import minetweaker.MineTweakerAPI;
|
||||||
|
import minetweaker.api.item.IIngredient;
|
||||||
|
import minetweaker.api.item.IItemStack;
|
||||||
|
import minetweaker.api.item.IngredientStack;
|
||||||
|
import minetweaker.api.liquid.ILiquidStack;
|
||||||
|
import minetweaker.api.oredict.IOreDictEntry;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import techreborn.compat.ICompatModule;
|
import techreborn.compat.ICompatModule;
|
||||||
|
|
||||||
|
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||||
|
import static minetweaker.api.minecraft.MineTweakerMC.getLiquidStack;
|
||||||
|
|
||||||
|
|
||||||
public class MinetweakerCompat implements ICompatModule {
|
public class MinetweakerCompat implements ICompatModule {
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,16 +27,37 @@ public class MinetweakerCompat implements ICompatModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(FMLInitializationEvent event) {
|
public void init(FMLInitializationEvent event) {
|
||||||
MineTweakerAPI.registerClass(MTAlloySmelter.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postInit(FMLPostInitializationEvent event) {
|
public void postInit(FMLPostInitializationEvent event) {
|
||||||
|
MineTweakerAPI.registerClass(MTAlloySmelter.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serverStarting(FMLServerStartingEvent event) {
|
public void serverStarting(FMLServerStartingEvent event) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ItemStack toStack(IItemStack iStack) {
|
||||||
|
return getItemStack(iStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object toObject(IIngredient iStack) {
|
||||||
|
if (iStack == null)
|
||||||
|
return null;
|
||||||
|
else {
|
||||||
|
if (iStack instanceof IOreDictEntry)
|
||||||
|
return ((IOreDictEntry) iStack).getName();
|
||||||
|
else if (iStack instanceof IItemStack)
|
||||||
|
return getItemStack((IItemStack) iStack);
|
||||||
|
else if (iStack instanceof IngredientStack) {
|
||||||
|
IIngredient ingr = ReflectionHelper.getPrivateValue(IngredientStack.class, (IngredientStack) iStack, "ingredient");
|
||||||
|
return toObject(ingr);
|
||||||
|
} else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue