From ff741068c27dd846f39c7340cb57d2eda08a2478 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 2 Jan 2016 02:16:11 +0100 Subject: [PATCH] MineTweaker test..? I guess? --- .../actuallyadditions/blocks/InitBlocks.java | 2 +- .../actuallyadditions/items/InitItems.java | 2 +- .../util/{ => compat}/CompatUtil.java | 4 +- .../util/compat/minetweaker/Crusher.java | 126 ++++++++++++++++++ .../util/compat/minetweaker/MineTweaker.java | 23 ++++ 5 files changed, 153 insertions(+), 4 deletions(-) rename src/main/java/de/ellpeck/actuallyadditions/util/{ => compat}/CompatUtil.java (95%) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/util/compat/minetweaker/Crusher.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/util/compat/minetweaker/MineTweaker.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/blocks/InitBlocks.java b/src/main/java/de/ellpeck/actuallyadditions/blocks/InitBlocks.java index 54337ad7f..d10ad3701 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/blocks/InitBlocks.java +++ b/src/main/java/de/ellpeck/actuallyadditions/blocks/InitBlocks.java @@ -16,8 +16,8 @@ import de.ellpeck.actuallyadditions.blocks.base.BlockStair; import de.ellpeck.actuallyadditions.blocks.base.BlockWallAA; import de.ellpeck.actuallyadditions.blocks.metalists.TheMiscBlocks; import de.ellpeck.actuallyadditions.config.values.ConfigBoolValues; -import de.ellpeck.actuallyadditions.util.CompatUtil; import de.ellpeck.actuallyadditions.util.ModUtil; +import de.ellpeck.actuallyadditions.util.compat.CompatUtil; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.item.EnumRarity; diff --git a/src/main/java/de/ellpeck/actuallyadditions/items/InitItems.java b/src/main/java/de/ellpeck/actuallyadditions/items/InitItems.java index 96606ff9c..cf7d2c272 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/items/InitItems.java +++ b/src/main/java/de/ellpeck/actuallyadditions/items/InitItems.java @@ -19,9 +19,9 @@ import de.ellpeck.actuallyadditions.items.metalists.TheFoods; import de.ellpeck.actuallyadditions.items.metalists.TheMiscItems; import de.ellpeck.actuallyadditions.material.InitArmorMaterials; import de.ellpeck.actuallyadditions.material.InitToolMaterials; -import de.ellpeck.actuallyadditions.util.CompatUtil; import de.ellpeck.actuallyadditions.util.ModUtil; import de.ellpeck.actuallyadditions.util.Util; +import de.ellpeck.actuallyadditions.util.compat.CompatUtil; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.EnumRarity; diff --git a/src/main/java/de/ellpeck/actuallyadditions/util/CompatUtil.java b/src/main/java/de/ellpeck/actuallyadditions/util/compat/CompatUtil.java similarity index 95% rename from src/main/java/de/ellpeck/actuallyadditions/util/CompatUtil.java rename to src/main/java/de/ellpeck/actuallyadditions/util/compat/CompatUtil.java index 5ec4c187b..918931743 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/util/CompatUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/util/compat/CompatUtil.java @@ -5,10 +5,10 @@ * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md * View the source code at https://github.com/Ellpeck/ActuallyAdditions * - * © 2015 Ellpeck + * © 2016 Ellpeck */ -package de.ellpeck.actuallyadditions.util; +package de.ellpeck.actuallyadditions.util.compat; import cpw.mods.fml.common.event.FMLInterModComms; import de.ellpeck.actuallyadditions.items.ItemSeed; diff --git a/src/main/java/de/ellpeck/actuallyadditions/util/compat/minetweaker/Crusher.java b/src/main/java/de/ellpeck/actuallyadditions/util/compat/minetweaker/Crusher.java new file mode 100644 index 000000000..cc042a4ef --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/util/compat/minetweaker/Crusher.java @@ -0,0 +1,126 @@ +/* + * This file ("Crusher.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.util.compat.minetweaker; + +import de.ellpeck.actuallyadditions.recipe.CrusherRecipeRegistry; +import de.ellpeck.actuallyadditions.util.ItemUtil; +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.minecraft.MineTweakerMC; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.ArrayList; +import java.util.List; + +@ZenClass("mods.actuallyadditions.crusher") +public class Crusher{ + + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack outputOne, @Optional IItemStack outputTwo, @Optional int outputTwoChance){ + CrusherRecipeRegistry.CrusherRecipe recipe = new CrusherRecipeRegistry.CrusherRecipe(MineTweakerMC.getItemStack(input), MineTweakerMC.getItemStack(outputOne), MineTweakerMC.getItemStack(outputTwo), outputTwoChance); + MineTweakerAPI.apply(new Add(recipe)); + } + + @ZenMethod + public static void removeRecipe(IItemStack outputOne){ + MineTweakerAPI.apply(new Remove(MineTweakerMC.getItemStack(outputOne))); + } + + private static class Add implements IUndoableAction{ + + private CrusherRecipeRegistry.CrusherRecipe recipe; + + public Add(CrusherRecipeRegistry.CrusherRecipe recipe){ + this.recipe = recipe; + } + + @Override + public void apply(){ + CrusherRecipeRegistry.recipes.add(this.recipe); + } + + @Override + public boolean canUndo(){ + return true; + } + + @Override + public void undo(){ + CrusherRecipeRegistry.recipes.remove(this.recipe); + } + + @Override + public String describe(){ + return "Adding Crusher Recipe for "+this.recipe.getRecipeOutputOnes().get(0); + } + + @Override + public String describeUndo(){ + return "Removing added Crusher Recipe for "+this.recipe.getRecipeOutputOnes().get(0); + } + + @Override + public Object getOverrideKey(){ + return null; + } + } + + private static class Remove implements IUndoableAction{ + + private final ItemStack output; + private List removedRecipes = new ArrayList(); + + public Remove(ItemStack output){ + this.output = output; + } + + @Override + public void apply(){ + this.removedRecipes.clear(); + + for(CrusherRecipeRegistry.CrusherRecipe recipe : CrusherRecipeRegistry.recipes){ + if(ItemUtil.contains(recipe.getRecipeOutputOnes(), this.output, true)){ + this.removedRecipes.add(recipe); + } + } + CrusherRecipeRegistry.recipes.removeAll(this.removedRecipes); + } + + @Override + public boolean canUndo(){ + return true; + } + + @Override + public void undo(){ + CrusherRecipeRegistry.recipes.addAll(this.removedRecipes); + } + + @Override + public String describe(){ + return "Removing Crusher Recipe for "+this.output.getDisplayName(); + } + + @Override + public String describeUndo(){ + return "Re-Adding Crusher Recipe for "+this.output.getDisplayName(); + } + + @Override + public Object getOverrideKey(){ + return null; + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/util/compat/minetweaker/MineTweaker.java b/src/main/java/de/ellpeck/actuallyadditions/util/compat/minetweaker/MineTweaker.java new file mode 100644 index 000000000..108379f76 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/util/compat/minetweaker/MineTweaker.java @@ -0,0 +1,23 @@ +/* + * This file ("MineTweaker.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.util.compat.minetweaker; + +import cpw.mods.fml.common.Loader; +import minetweaker.MineTweakerAPI; + +public class MineTweaker{ + + public static void init(){ + if(Loader.isModLoaded("MineTweaker3")){ + MineTweakerAPI.registerClass(Crusher.class); + } + } +}