Add MineTweaker 3 Integration.

This commit is contained in:
joshiejack 2014-10-16 05:26:15 +01:00
parent 25bc226994
commit 772bcf1ee6
8 changed files with 648 additions and 0 deletions

View file

@ -56,6 +56,7 @@ dependencies {
compile "codechicken:CodeChickenLib:${config.minecraft_version}-${config.CCLIB_version}:dev"
compile "codechicken:CodeChickenCore:${config.minecraft_version}-${config.ccc_version}:dev"
compile "codechicken:NotEnoughItems:${config.minecraft_version}-${config.NEI_version}:dev"
compile files("libs/MineTweaker3-Dev-1.7.10-3.0.9.jar")
}

View file

@ -28,6 +28,7 @@ import WayofTime.alchemicalWizardry.common.summoning.SummoningHelperAW;
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorRegistry;
import WayofTime.alchemicalWizardry.common.tileEntity.*;
import WayofTime.alchemicalWizardry.common.tileEntity.gui.GuiHandler;
import WayofTime.alchemicalWizardry.common.tweaker.MineTweakerIntegration;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
@ -847,6 +848,11 @@ public class AlchemicalWizardry
PamHarvestCompatRegistry.registerPamHandlers();
System.out.println("Loaded Harvestcraft Handlers!");
}
if(Loader.isModLoaded("MineTweaker3")) {
MineTweakerIntegration.register();
System.out.println("Loaded MineTweaker 3 Integration");
}
BloodMagicConfiguration.loadBlacklist();
}

View file

@ -0,0 +1,131 @@
package WayofTime.alchemicalWizardry.common.tweaker;
import static WayofTime.alchemicalWizardry.common.tweaker.MTHelper.toStack;
import static WayofTime.alchemicalWizardry.common.tweaker.MTHelper.toStacks;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IItemStack;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import WayofTime.alchemicalWizardry.api.alchemy.AlchemyRecipe;
import WayofTime.alchemicalWizardry.api.alchemy.AlchemyRecipeRegistry;
/**
* MineTweaker3 Alchemy Recipe Handler by joshie *
*/
@ZenClass("mods.bloodmagic.Alchemy")
public class Alchemy
{
@ZenMethod
public static void addRecipe(IItemStack output, IItemStack[] input, int tier, int lp) {
MineTweakerAPI.apply(new Add(new AlchemyRecipe(toStack(output), (int) (((double) lp) / 100), toStacks(input), tier)));
}
private static class Add implements IUndoableAction
{
private final AlchemyRecipe recipe;
public Add(AlchemyRecipe recipe)
{
this.recipe = recipe;
}
@Override
public void apply()
{
AlchemyRecipeRegistry.recipes.add(recipe);
}
@Override
public boolean canUndo()
{
return AlchemyRecipeRegistry.recipes != null;
}
@Override
public void undo()
{
AlchemyRecipeRegistry.recipes.remove(recipe);
}
@Override
public String describe()
{
return "Adding Alchemy Recipe for " + ((AlchemyRecipe) recipe).getResult().getDisplayName();
}
@Override
public String describeUndo()
{
return "Removing Alchemy Recipe for " + ((AlchemyRecipe) recipe).getResult().getDisplayName();
}
@Override
public Object getOverrideKey()
{
return null;
}
}
@ZenMethod
public static void removeRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove(toStack(output)));
}
private static class Remove implements IUndoableAction
{
private final ItemStack output;
private AlchemyRecipe recipe;
public Remove(ItemStack output)
{
this.output = output;
}
@Override
public void apply()
{
for (AlchemyRecipe r : AlchemyRecipeRegistry.recipes)
{
if (r.getResult() != null && r.getResult().isItemEqual(output))
{
recipe = r;
break;
}
}
AlchemyRecipeRegistry.recipes.remove(recipe);
}
@Override
public boolean canUndo()
{
return AlchemyRecipeRegistry.recipes != null && recipe != null;
}
@Override
public void undo()
{
AlchemyRecipeRegistry.recipes.add(recipe);
}
@Override
public String describe()
{
return "Removing Alchemy Recipe for " + output.getDisplayName();
}
@Override
public String describeUndo()
{
return "Restoring Alchemy Recipe for " + output.getDisplayName();
}
@Override
public Object getOverrideKey()
{
return null;
}
}
}

View file

@ -0,0 +1,130 @@
package WayofTime.alchemicalWizardry.common.tweaker;
import static WayofTime.alchemicalWizardry.common.tweaker.MTHelper.toStack;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IItemStack;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import WayofTime.alchemicalWizardry.api.bindingRegistry.BindingRecipe;
import WayofTime.alchemicalWizardry.api.bindingRegistry.BindingRegistry;
/**
* MineTweaker3 Binding Recipe Handler by joshie *
*/
@ZenClass("mods.bloodmagic.Binding")
public class Binding
{
@ZenMethod
public static void addRecipe(IItemStack input, IItemStack output) {
MineTweakerAPI.apply(new Add(new BindingRecipe(toStack(output), toStack(input))));
}
private static class Add implements IUndoableAction
{
private final BindingRecipe recipe;
public Add(BindingRecipe recipe)
{
this.recipe = recipe;
}
@Override
public void apply()
{
BindingRegistry.bindingRecipes.add(recipe);
}
@Override
public boolean canUndo()
{
return BindingRegistry.bindingRecipes != null;
}
@Override
public void undo()
{
BindingRegistry.bindingRecipes.remove(recipe);
}
@Override
public String describe()
{
return "Adding Binding Recipe for " + ((BindingRecipe) recipe).getResult().getDisplayName();
}
@Override
public String describeUndo()
{
return "Removing Binding Recipe for " + ((BindingRecipe) recipe).getResult().getDisplayName();
}
@Override
public Object getOverrideKey()
{
return null;
}
}
@ZenMethod
public static void removeRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove(toStack(output)));
}
private static class Remove implements IUndoableAction
{
private final ItemStack output;
private BindingRecipe recipe;
public Remove(ItemStack output)
{
this.output = output;
}
@Override
public void apply()
{
for (BindingRecipe r : BindingRegistry.bindingRecipes)
{
if (r.getResult() != null && r.getResult().isItemEqual(output))
{
recipe = r;
break;
}
}
BindingRegistry.bindingRecipes.remove(recipe);
}
@Override
public boolean canUndo()
{
return BindingRegistry.bindingRecipes != null && recipe != null;
}
@Override
public void undo()
{
BindingRegistry.bindingRecipes.add(recipe);
}
@Override
public String describe()
{
return "Removing Binding Recipe for " + output.getDisplayName();
}
@Override
public String describeUndo()
{
return "Restoring Binding Recipe for " + output.getDisplayName();
}
@Override
public Object getOverrideKey()
{
return null;
}
}
}

View file

@ -0,0 +1,133 @@
package WayofTime.alchemicalWizardry.common.tweaker;
import static WayofTime.alchemicalWizardry.common.tweaker.MTHelper.toStack;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IItemStack;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import WayofTime.alchemicalWizardry.api.altarRecipeRegistry.AltarRecipe;
import WayofTime.alchemicalWizardry.api.altarRecipeRegistry.AltarRecipeRegistry;
/**
* MineTweaker3 Blood Altar Recipe Handler by joshie *
*/
@ZenClass("mods.bloodmagic.Altar")
public class BloodAltar
{
@ZenMethod
public static void addRecipe(IItemStack output, IItemStack input, int tier, int lp, @Optional int consume, @Optional int drain) {
consume = consume > 0 ? consume : 20;
drain = drain > 0 ? drain : 20;
MineTweakerAPI.apply(new Add(new AltarRecipe(toStack(output), toStack(input), tier, lp, consume, drain, false)));
}
private static class Add implements IUndoableAction
{
private final AltarRecipe recipe;
public Add(AltarRecipe recipe)
{
this.recipe = recipe;
}
@Override
public void apply()
{
AltarRecipeRegistry.altarRecipes.add(recipe);
}
@Override
public boolean canUndo()
{
return AltarRecipeRegistry.altarRecipes != null;
}
@Override
public void undo()
{
AltarRecipeRegistry.altarRecipes.remove(recipe);
}
@Override
public String describe()
{
return "Adding Blood Altar Recipe for " + ((AltarRecipe) recipe).getResult().getDisplayName();
}
@Override
public String describeUndo()
{
return "Removing Blood Altar Recipe for " + ((AltarRecipe) recipe).getResult().getDisplayName();
}
@Override
public Object getOverrideKey()
{
return null;
}
}
@ZenMethod
public static void removeRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove(toStack(output)));
}
private static class Remove implements IUndoableAction
{
private final ItemStack output;
private AltarRecipe recipe;
public Remove(ItemStack output)
{
this.output = output;
}
@Override
public void apply()
{
for (AltarRecipe r : AltarRecipeRegistry.altarRecipes)
{
if (r.getResult() != null && r.getResult().isItemEqual(output))
{
recipe = r;
break;
}
}
AltarRecipeRegistry.altarRecipes.remove(recipe);
}
@Override
public boolean canUndo()
{
return AltarRecipeRegistry.altarRecipes != null && recipe != null;
}
@Override
public void undo()
{
AltarRecipeRegistry.altarRecipes.add(recipe);
}
@Override
public String describe()
{
return "Removing Blood Altar Recipe for " + output.getDisplayName();
}
@Override
public String describeUndo()
{
return "Restoring Blood Altar Recipe for " + output.getDisplayName();
}
@Override
public Object getOverrideKey()
{
return null;
}
}
}

View file

@ -0,0 +1,146 @@
package WayofTime.alchemicalWizardry.common.tweaker;
import static WayofTime.alchemicalWizardry.common.tweaker.MTHelper.toObjects;
import static WayofTime.alchemicalWizardry.common.tweaker.MTHelper.toShapedObjects;
import static WayofTime.alchemicalWizardry.common.tweaker.MTHelper.toStack;
import java.util.List;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import WayofTime.alchemicalWizardry.api.items.ShapedBloodOrbRecipe;
/**
* MineTweaker3 Blood Orb Recipe Handler by joshie *
*/
@ZenClass("mods.bloodmagic.BloodOrb")
public class BloodOrb
{
@ZenMethod
public static void addShaped(IItemStack output, IIngredient[][] ingredients)
{
MineTweakerAPI.apply(new Add(false, toStack(output), toShapedObjects(ingredients)));
}
@ZenMethod
public static void addShapeless(IItemStack output, IIngredient[] ingredients)
{
MineTweakerAPI.apply(new Add(true, toStack(output), toObjects(ingredients)));
}
private static class Add implements IUndoableAction {
private IRecipe iRecipe;
private final boolean isShapeless;
private final ItemStack output;
private final Object[] recipe;
public Add(boolean isShapeless, ItemStack output, Object... recipe)
{
this.isShapeless = isShapeless;
this.output = output;
this.recipe = recipe;
}
@Override
public void apply()
{
if (isShapeless) iRecipe = new ShapedBloodOrbRecipe(output, recipe);
else iRecipe = new ShapedBloodOrbRecipe(output, recipe);
CraftingManager.getInstance().getRecipeList().add(iRecipe);
}
@Override
public boolean canUndo()
{
return CraftingManager.getInstance().getRecipeList() != null;
}
@Override
public void undo()
{
CraftingManager.getInstance().getRecipeList().remove(iRecipe);
}
@Override
public String describe() {
return "Adding Blood Orb Recipe for " + output.getDisplayName();
}
@Override
public String describeUndo()
{
return "Removing Blood Orb Recipe for " + output.getDisplayName();
}
@Override
public Object getOverrideKey()
{
return null;
}
}
@ZenMethod
public static void removeRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove(toStack(output)));
}
private static class Remove implements IUndoableAction {
private final ItemStack output;
private IRecipe iRecipe;
public Remove(ItemStack output)
{
this.output = output;
}
@Override
public void apply()
{
for (IRecipe r : (List<IRecipe>) CraftingManager.getInstance().getRecipeList())
{
if(r.getRecipeOutput() != null && r.getRecipeOutput().isItemEqual(output)) {
iRecipe = r;
break;
}
}
CraftingManager.getInstance().getRecipeList().remove(iRecipe);
}
@Override
public boolean canUndo()
{
return CraftingManager.getInstance().getRecipeList() != null && iRecipe != null;
}
@Override
public void undo()
{
CraftingManager.getInstance().getRecipeList().add(iRecipe);
}
@Override
public String describe() {
return "Removing Blood Orb Recipe for " + output.getDisplayName();
}
@Override
public String describeUndo()
{
return "Restoring Blood Orb Recipe for " + output.getDisplayName();
}
@Override
public Object getOverrideKey()
{
return null;
}
}
}

View file

@ -0,0 +1,83 @@
package WayofTime.alchemicalWizardry.common.tweaker;
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
import java.util.ArrayList;
import stanhebben.zenscript.annotations.ZenClass;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import minetweaker.api.oredict.IOreDictEntry;
import net.minecraft.item.ItemStack;
/**
* MineTweaker3 Helper by joshie *
*/
public class MTHelper {
public static ItemStack toStack(IItemStack iStack) {
return getItemStack(iStack);
}
public static ItemStack[] toStacks(IItemStack[] iStack) {
if (iStack == null) return null;
else {
ItemStack[] output = new ItemStack[iStack.length];
for (int i = 0; i < iStack.length; i++) {
output[i] = toStack(iStack[i]);
}
return output;
}
}
public static Object toObject(IIngredient iStack) {
if (iStack == null) return null;
else {
if (iStack instanceof IOreDictEntry) {
return toString((IOreDictEntry) iStack);
} else if (iStack instanceof IItemStack) {
return getItemStack((IItemStack) iStack);
} else return null;
}
}
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] = toObject(ingredient[i]);
} else output[i] = "";
}
return output;
}
}
public static Object[] toShapedObjects(IIngredient[][] ingredients) {
if (ingredients == null) return null;
else {
ArrayList prep = new ArrayList();
prep.add("abc");
prep.add("def");
prep.add("ghi");
char[][] map = new char[][] { { 'a', 'b', 'c' }, { 'd', 'e', 'f' }, { 'g', 'h', 'i' } };
for (int x = 0; x < ingredients.length; x++) {
if (ingredients[x] != null) {
for (int y = 0; y < ingredients[x].length; y++) {
if (ingredients[x][y] != null && x < map.length && y < map[x].length) {
prep.add(map[x][y]);
prep.add(toObject(ingredients[x][y]));
}
}
}
}
return prep.toArray();
}
}
public static String toString(IOreDictEntry entry) {
return ((IOreDictEntry) entry).getName();
}
}

View file

@ -0,0 +1,18 @@
package WayofTime.alchemicalWizardry.common.tweaker;
import stanhebben.zenscript.annotations.ZenClass;
import minetweaker.MineTweakerAPI;
/**
* MineTweaker3 Integration by joshie *
*/
public class MineTweakerIntegration
{
public static void register()
{
MineTweakerAPI.registerClass(Alchemy.class);
MineTweakerAPI.registerClass(Binding.class);
MineTweakerAPI.registerClass(BloodAltar.class);
MineTweakerAPI.registerClass(BloodOrb.class);
}
}