This closes #17 and closes #58, I tested and it worked using the script given

Also changes like all packages
inb4 "jared changes a package name in ModTweaker2 breaking compatability
with everything" drama tweet.
This commit is contained in:
jaredlll08 committed 2015-02-20 23:57:32 +02:00
1 parent 4fd2551072
commit ec562b62ea
187 files changed
+977 -991

No files matched your search

@@ -0,0 +1,35 @@
package modtweaker2.mods.tconstruct;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import minetweaker.MineTweakerAPI;
import minetweaker.api.player.IPlayer;
import minetweaker.api.server.ICommandFunction;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.ToolMaterial;
import static modtweaker2.helpers.LogHelper.*;
public class MaterialLogger implements ICommandFunction {
private static ArrayList<String> materials = new ArrayList();
static {
materials = new ArrayList();
for (Map.Entry<String, ToolMaterial> entry : TConstructRegistry.toolMaterialStrings.entrySet()) {
materials.add(entry.getKey());
}
Collections.sort(materials);
}
@Override
public void execute(String[] arguments, IPlayer player) {
System.out.println("Materials: " + materials.size());
for (String s : materials) {
System.out.println("Material " + s);
MineTweakerAPI.logCommand("<" + s + "> -- ");
}
logPrinted(player);
}
}
@@ -0,0 +1,18 @@
package modtweaker2.mods.tconstruct;
import minetweaker.MineTweakerAPI;
import modtweaker2.mods.tconstruct.handlers.Casting;
import modtweaker2.mods.tconstruct.handlers.Drying;
import modtweaker2.mods.tconstruct.handlers.Smeltery;
import modtweaker2.mods.tconstruct.handlers.TiCTweaks;
import modtweaker2.mods.tconstruct.handlers.ToolStats;
public class TConstruct {
public TConstruct() {
MineTweakerAPI.registerClass(Casting.class);
MineTweakerAPI.registerClass(Drying.class);
MineTweakerAPI.registerClass(Smeltery.class);
MineTweakerAPI.registerClass(TiCTweaks.class);
MineTweakerAPI.registerClass(ToolStats.class);
}
}
@@ -0,0 +1,85 @@
package modtweaker2.mods.tconstruct;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import mantle.utils.ItemMetaWrapper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.AlloyMix;
import tconstruct.library.crafting.CastingRecipe;
import tconstruct.library.crafting.DryingRackRecipes.DryingRecipe;
import tconstruct.library.crafting.ModifyBuilder;
import tconstruct.library.crafting.PatternBuilder.ItemKey;
import tconstruct.library.modifier.ItemModifier;
import tconstruct.library.tools.ToolMaterial;
public class TConstructHelper {
public static HashMap<String, Integer> mappings = new HashMap();
public static List<AlloyMix> alloys = null;
public static ArrayList<CastingRecipe> basinCasting = null;
public static ArrayList<CastingRecipe> tableCasting = null;
public static Map<ItemMetaWrapper, FluidStack> smeltingList = null;
public static Map<ItemMetaWrapper, Integer> temperatureList = null;
public static Map<ItemMetaWrapper, ItemStack> renderIndex = null;
public static List<ItemModifier> modifiers = null;
public static List<ItemModifier> modifiers_clone = null;
static {
try {
alloys = tconstruct.library.crafting.Smeltery.getAlloyList();
smeltingList = tconstruct.library.crafting.Smeltery.getSmeltingList();
temperatureList = tconstruct.library.crafting.Smeltery.getTemperatureList();
renderIndex = tconstruct.library.crafting.Smeltery.getRenderIndex();
basinCasting = TConstructRegistry.getBasinCasting().getCastingRecipes();
tableCasting = TConstructRegistry.getTableCasting().getCastingRecipes();
modifiers = ModifyBuilder.instance.itemModifiers;
modifiers_clone = new ArrayList(modifiers);
for (Map.Entry<Integer, ToolMaterial> entry : TConstructRegistry.toolMaterials.entrySet()) {
mappings.put(entry.getValue().materialName, entry.getKey());
}
} catch (Exception e) {}
}
private TConstructHelper() {}
public static int getIDFromString(String material) {
if (!mappings.containsKey(material)) {
return -1;
} else return mappings.get(material);
}
//Returns a Drying Recipe, using reflection as the constructor is not visible
public static DryingRecipe getDryingRecipe(ItemStack input, int time, ItemStack output) {
try {
Constructor constructor = DryingRecipe.class.getDeclaredConstructor(ItemStack.class, int.class, ItemStack.class);
constructor.setAccessible(true);
return (DryingRecipe) constructor.newInstance(input, time, output);
} catch (Exception e) {
e.printStackTrace();
throw new NullPointerException("Failed to instantiate DryingRecipe");
}
}
public static String getMaterialFromID(int id) {
return TConstructRegistry.toolMaterials.get(id).materialName;
}
public static ItemKey getItemKey(Item item, int damage, int value, String material) {
try {
Constructor constructor = ItemKey.class.getDeclaredConstructor(ItemStack.class, int.class, int.class, String.class);
constructor.setAccessible(true);
return (ItemKey) constructor.newInstance(item, damage, value, material);
} catch (Exception e) {
e.printStackTrace();
throw new NullPointerException("Failed to instantiate ItemKey");
}
}
}
@@ -0,0 +1,81 @@
package modtweaker2.mods.tconstruct.handlers;
import java.util.ArrayList;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IItemStack;
import minetweaker.api.liquid.ILiquidStack;
import modtweaker2.mods.tconstruct.TConstructHelper;
import modtweaker2.util.BaseListAddition;
import modtweaker2.util.BaseListRemoval;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import tconstruct.library.crafting.CastingRecipe;
import static modtweaker2.helpers.InputHelper.*;
import static modtweaker2.helpers.StackHelper.*;
@ZenClass("mods.tconstruct.Casting")
public class Casting {
//Adding a TConstruct Casting recipe
@ZenMethod
public static void addBasinRecipe(IItemStack output, ILiquidStack metal, @Optional IItemStack cast, @Optional boolean consume, int delay) {
MineTweakerAPI.apply(new Add(new CastingRecipe(toStack(output), toFluid(metal), toStack(cast), consume, delay, null), TConstructHelper.basinCasting));
}
@ZenMethod
public static void addTableRecipe(IItemStack output, ILiquidStack metal, @Optional IItemStack cast, @Optional boolean consume, int delay) {
MineTweakerAPI.apply(new Add(new CastingRecipe(toStack(output), toFluid(metal), toStack(cast), consume, delay, null), TConstructHelper.tableCasting));
}
//Passes the list to the base list implementation, and adds the recipe
private static class Add extends BaseListAddition {
public Add(CastingRecipe recipe, ArrayList list) {
super("TConstruct Casting", list, recipe);
}
@Override
public String getRecipeInfo() {
return ((CastingRecipe) recipe).output.getDisplayName();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Removing a TConstruct Casting recipe
@ZenMethod
public static void removeBasinRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.basinCasting));
}
@ZenMethod
public static void removeTableRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.tableCasting));
}
//Removes a recipe, apply is never the same for anything, so will always need to override it
private static class Remove extends BaseListRemoval {
public Remove(ItemStack output, ArrayList list) {
super("TConstruct Casting", list, output);
}
//Loops through the registry, to find the item that matches, saves that recipe then removes it
@Override
public void apply() {
for (CastingRecipe r : (ArrayList<CastingRecipe>) list) {
if (r.output != null && areEqual(r.output, stack)) {
recipe = r;
break;
}
}
list.remove(recipe);
}
@Override
public String getRecipeInfo() {
return stack.getDisplayName();
}
}
}
@@ -0,0 +1,70 @@
package modtweaker2.mods.tconstruct.handlers;
import java.util.ArrayList;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IItemStack;
import modtweaker2.mods.tconstruct.TConstructHelper;
import modtweaker2.util.BaseListAddition;
import modtweaker2.util.BaseListRemoval;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import tconstruct.library.crafting.DryingRackRecipes;
import tconstruct.library.crafting.DryingRackRecipes.DryingRecipe;
import static modtweaker2.helpers.InputHelper.*;
import static modtweaker2.helpers.StackHelper.*;
@ZenClass("mods.tconstruct.Drying")
public class Drying {
//Adding a TConstruct Drying Rack recipe
@ZenMethod
public static void addRecipe(IItemStack input, IItemStack output, int time) {
MineTweakerAPI.apply(new Add(TConstructHelper.getDryingRecipe(toStack(input), time, toStack(output))));
}
//Passes the list to the base list implementation, and adds the recipe
private static class Add extends BaseListAddition {
public Add(DryingRecipe recipe) {
super("TConstruct Drying Rack", DryingRackRecipes.recipes, recipe);
}
@Override
public String getRecipeInfo() {
return ((DryingRecipe) recipe).result.getDisplayName();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Removing a TConstruct Drying Rack recipe
@ZenMethod
public static void removeRecipe(IItemStack output) {
MineTweakerAPI.apply(new Remove((toStack(output))));
}
//Removes a recipe, apply is never the same for anything, so will always need to override it
private static class Remove extends BaseListRemoval {
public Remove(ItemStack output) {
super("TConstruct Drying Rack", DryingRackRecipes.recipes, output);
}
//Loops through the registry, to find the item that matches, saves that recipe then removes it
@Override
public void apply() {
for (DryingRecipe r : (ArrayList<DryingRecipe>) list) {
if (r.result != null && areEqual(r.result, stack)) {
recipe = r;
break;
}
}
list.remove(recipe);
}
@Override
public String getRecipeInfo() {
return stack.getDisplayName();
}
}
}
@@ -0,0 +1,40 @@
package modtweaker2.mods.tconstruct.handlers;
import java.util.List;
import minetweaker.MineTweakerAPI;
import modtweaker2.mods.tconstruct.TConstructHelper;
import modtweaker2.util.BaseListRemoval;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import tconstruct.library.modifier.ItemModifier;
@ZenClass("mods.tconstruct.Modifiers")
public class Modifiers {
@ZenMethod
public static void remove(String mod) {
MineTweakerAPI.apply(new Remove(mod));
}
//Searches through the modifiers and removes the first valid entry
private static class Remove extends BaseListRemoval {
private final String check;
public Remove(String check) {
super("Modifier", TConstructHelper.modifiers);
this.check = check;
}
@Override
public void apply() {
for (ItemModifier m : (List<ItemModifier>) list) {
if (m.key.equals(check)) {
recipe = m;
break;
}
}
list.remove(recipe);
}
}
}
@@ -0,0 +1,203 @@
package modtweaker2.mods.tconstruct.handlers;
import static modtweaker2.helpers.InputHelper.*;
import static modtweaker2.helpers.StackHelper.*;
import java.util.ArrayList;
import java.util.Arrays;
import mantle.utils.ItemMetaWrapper;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IItemStack;
import minetweaker.api.liquid.ILiquidStack;
import minetweaker.api.minecraft.MineTweakerMC;
import minetweaker.api.oredict.IOreDictEntry;
import modtweaker2.mods.tconstruct.TConstructHelper;
import modtweaker2.util.BaseDescriptionAddition;
import modtweaker2.util.BaseDescriptionRemoval;
import modtweaker2.util.BaseListAddition;
import modtweaker2.util.BaseListRemoval;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import tconstruct.library.crafting.AlloyMix;
@ZenClass("mods.tconstruct.Smeltery")
public class Smeltery {
/********************************************** TConstruct Alloy Recipes **********************************************/
// Adding a TConstruct Alloy recipe
@ZenMethod
public static void addAlloy(ILiquidStack output, ILiquidStack[] input) {
MineTweakerAPI.apply(new AddAlloy(new AlloyMix(toFluid(output), new ArrayList<FluidStack>(Arrays.asList(toFluids(input))))));
}
// Passes the list to the base list implementation, and adds the recipe
private static class AddAlloy extends BaseListAddition {
public AddAlloy(AlloyMix recipe) {
super("Smeltery - Alloy", TConstructHelper.alloys, recipe);
}
@Override
public String getRecipeInfo() {
return ((AlloyMix) recipe).result.getFluid().getName();
}
}
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Removing a TConstruct Alloy recipe
@ZenMethod
public static void removeAlloy(ILiquidStack output) {
MineTweakerAPI.apply(new RemoveAlloy((toFluid(output))));
}
// Removes a recipe, apply is never the same for anything, so will always
// need to override it
private static class RemoveAlloy extends BaseListRemoval {
public RemoveAlloy(FluidStack output) {
super("Smeltery - Alloy", TConstructHelper.alloys, output);
}
// Loops through the registry, to find the item that matches, saves that
// recipe then removes it
@Override
public void apply() {
for (AlloyMix r : TConstructHelper.alloys) {
if (r != null) {
if (r.result != null && fluid != null && r.result.isFluidStackIdentical(fluid)) {
recipe = r;
break;
}
}
}
if (recipe != null)
TConstructHelper.alloys.remove(recipe);
}
@Override
public String getRecipeInfo() {
return fluid.getFluid().getName();
}
}
/********************************************** TConstruct Melting Recipes **********************************************/
// Adding a TConstruct Melting recipe
@ZenMethod
public static void addMelting(IItemStack input, ILiquidStack output, int temp, @Optional IItemStack block) {
if (block == null)
block = input;
if (isABlock(block)) {
Block theBlock = Block.getBlockFromItem(toStack(block).getItem());
int theMeta = toStack(block).getItemDamage();
MineTweakerAPI.apply(new AddMelting(toStack(input), theBlock, theMeta, temp, toFluid(output)));
}
}
@ZenMethod
public static void addMelting(IOreDictEntry input, ILiquidStack output, int temp, @Optional IItemStack block) {
for (ItemStack stack : OreDictionary.getOres(input.getName())) {
addMelting(MineTweakerMC.getIItemStack(stack), output, temp, block);
}
}
// Takes all the variables and saves them in place
private static class AddMelting extends BaseDescriptionAddition {
private final ItemStack input;
private final Block block;
private final int meta;
private final int temp;
private final FluidStack output;
public AddMelting(ItemStack input, Block block, int meta, int temp, FluidStack output) {
super("Smeltery - Melting");
this.input = input;
this.block = block;
this.meta = meta;
this.temp = temp;
this.output = output;
}
// Adds the Melting recipe
@Override
public void apply() {
tconstruct.library.crafting.Smeltery.instance.addMelting(input, block, meta, temp, output);
}
// Removes the Melting recipe from the hashmaps
@Override
public void undo() {
ItemMetaWrapper in = new ItemMetaWrapper(input);
TConstructHelper.smeltingList.remove(in);
TConstructHelper.temperatureList.remove(in);
TConstructHelper.renderIndex.remove(in);
}
@Override
public String getRecipeInfo() {
return input.getDisplayName();
}
}
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Removing a TConstruct Melting recipe
@ZenMethod
public static void removeMelting(IItemStack input) {
MineTweakerAPI.apply(new RemoveMelting((toStack(input))));
}
@ZenMethod
public static void removeMelting(IOreDictEntry input) {
for (ItemStack stack : OreDictionary.getOres(input.getName())) {
removeMelting(MineTweakerMC.getIItemStack(stack));
}
}
// Removes a recipe, apply is never the same for anything, so will always
// need to override it
private static class RemoveMelting extends BaseDescriptionRemoval {
private final ItemStack input;
private FluidStack fluid;
private Integer temp;
private ItemStack renderer;
public RemoveMelting(ItemStack input) {
super("Smeltery - Melting");
this.input = input;
}
// Gets the current values, and saves, them removes them from the
// hashmaps
@Override
public void apply() {
ItemMetaWrapper in = new ItemMetaWrapper(input);
fluid = TConstructHelper.smeltingList.get(in);
temp = TConstructHelper.temperatureList.get(in);
renderer = TConstructHelper.renderIndex.get(in);
TConstructHelper.smeltingList.remove(in);
TConstructHelper.temperatureList.remove(in);
TConstructHelper.renderIndex.remove(in);
}
// Reads the Melting recipe
@Override
public void undo() {
// tconstruct.library.crafting.Smeltery.instance.addMelting(input,
// Block.getBlockFromItem(renderer.getItem()),
// renderer.getItemDamage(), temp, fluid);
}
@Override
public String getRecipeInfo() {
return input.getDisplayName();
}
}
}
@@ -0,0 +1,131 @@
package modtweaker2.mods.tconstruct.handlers;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IItemStack;
import modtweaker2.helpers.ReflectionHelper;
import modtweaker2.mods.tconstruct.TConstructHelper;
import modtweaker2.util.BaseListAddition;
import modtweaker2.util.BaseListRemoval;
import modtweaker2.util.BaseSetVar;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import tconstruct.library.crafting.PatternBuilder;
import tconstruct.library.crafting.PatternBuilder.ItemKey;
import tconstruct.library.tools.ToolCore;
import tconstruct.tools.TinkerTools;
import static modtweaker2.helpers.InputHelper.*;
import static modtweaker2.helpers.StackHelper.*;
@ZenClass("mods.tconstruct.Tweaks")
public class TiCTweaks {
// Set the maximum RF
@ZenMethod
public static void setRFCapacity(String tool, int capacity) {
MineTweakerAPI.apply(new AdjustRF(tool, capacity));
}
private static class AdjustRF extends BaseSetVar {
public AdjustRF(String tool, int newValue) {
super("RF Maximum for Tinkers Tools", ToolCore.class, ReflectionHelper.getStaticObject(TinkerTools.class, tool), "capacity", 400000, newValue);
}
}
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** Disabling for 0.5, will do this properly for 0.6 **/
// Tweaks for enabling / disabling Patterns
/*
* @ZenMethod public static void removePattern(IItemStack stack) {
* MineTweakerAPI.apply(new DisablePattern(toStack(stack))); }
*
* private static class DisablePattern implements IUndoableAction { private
* String key; private MaterialSet set; private List list; private ItemStack
* stack; private final ItemStack disable;
*
* public DisablePattern(ItemStack disable) { this.disable = disable; }
*
* //Loops through the pattern mappings to find an entry with the same
* material name
*
* @Override public void apply() { for (Entry<List, ItemStack> entry :
* TConstructRegistry.patternPartMapping.entrySet()) { ItemStack check =
* entry.getValue(); if (check.isItemEqual(disable)) { list =
* entry.getKey(); stack = entry.getValue(); break; } }
*
* TConstructRegistry.patternPartMapping.remove(list); }
*
* @Override public boolean canUndo() { return true; }
*
* @Override public void undo() {
* TConstructRegistry.patternPartMapping.put(list, stack); }
*
* @Override public String describe() { return
* "Disabling creation of the pattern for: " + disable.getDisplayName(); }
*
* @Override public String describeUndo() { return
* "Enabling creation of the pattern for: " + disable.getDisplayName(); }
*
* @Override public Object getOverrideKey() { return null; } }
*/
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void addRepairMaterial(IItemStack stack, String material, int value) {
ItemStack input = toStack(stack);
MineTweakerAPI.apply(new Add(TConstructHelper.getItemKey(input.getItem(), input.getItemDamage(), value, material)));
}
// Tweaks for setting repair materials
private static class Add extends BaseListAddition {
public Add(ItemKey recipe) {
super("Repair Material", PatternBuilder.instance.materials, recipe);
}
@Override
public String getRecipeInfo() {
return new ItemStack(((ItemKey) recipe).item, 1, ((ItemKey) recipe).damage).getDisplayName();
}
}
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void removeRepairMaterial(IItemStack output, @Optional String material) {
MineTweakerAPI.apply(new Remove(toStack(output), material));
}
// Removes a recipe, apply is never the same for anything, so will always
// need to override it
private static class Remove extends BaseListRemoval {
private final String material;
public Remove(ItemStack stack, String material) {
super("Repair Material", PatternBuilder.instance.materials, stack);
this.material = material;
}
// Loops through the registry, to find the item that matches, saves that
// recipe then removes it
@Override
public void apply() {
for (ItemKey r : PatternBuilder.instance.materials) {
ItemStack clone = new ItemStack(r.item, 1, r.damage);
if ((material != null && material.equalsIgnoreCase(r.key)) || (material == null)) {
if (clone.isItemEqual(stack)) {
recipe = r;
break;
}
}
}
PatternBuilder.instance.materials.remove(recipe);
}
@Override
public String getRecipeInfo() {
return stack.getDisplayName();
}
}
}
@@ -0,0 +1,246 @@
package modtweaker2.mods.tconstruct.handlers;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import modtweaker2.helpers.ReflectionHelper;
import modtweaker2.mods.tconstruct.TConstructHelper;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.ArrowMaterial;
import tconstruct.library.tools.BowMaterial;
import tconstruct.library.tools.ToolMaterial;
@ZenClass("mods.tconstruct.ToolStats")
public class ToolStats {
@ZenMethod
public static void set(String material, @Optional String name, int level, int durability, int speed, int damage, double handle, int reinforced, double stonebound, String style, String ability) {
if (name == null) name = material + " ";
MineTweakerAPI.apply(new SetToolStats(material, "", new ToolMaterial(material, name, level, durability, speed, damage, (float) handle, reinforced, (float) stonebound, style, ability)));
}
@ZenMethod
public static void setDisplayName(String material, String name) {
MineTweakerAPI.apply(new SetToolStats(material, "displayName", name));
}
@ZenMethod
public static void setHarvestLevel(String material, int value) {
MineTweakerAPI.apply(new SetToolStats(material, "harvestLevel", value));
}
@ZenMethod
public static void setDurability(String material, int value) {
MineTweakerAPI.apply(new SetToolStats(material, "durability", value));
}
@ZenMethod
public static void setSpeed(String material, int value) {
MineTweakerAPI.apply(new SetToolStats(material, "miningspeed", value));
}
@ZenMethod
public static void setDamage(String material, int value) {
MineTweakerAPI.apply(new SetToolStats(material, "attack", value));
}
@ZenMethod
public static void setHandleModifier(String material, double value) {
MineTweakerAPI.apply(new SetToolStats(material, "handleModifier", (float) value));
}
@ZenMethod
public static void setReinforcedLevel(String material, int value) {
MineTweakerAPI.apply(new SetToolStats(material, "reinforced", value));
}
@ZenMethod
public static void setStoneboundLevel(String material, double value) {
MineTweakerAPI.apply(new SetToolStats(material, "stonebound", (float) value));
}
@ZenMethod
public static void setStyle(String material, String name) {
MineTweakerAPI.apply(new SetToolStats(material, "tipStyle", name));
}
@ZenMethod
public static void setAbility(String material, String name) {
MineTweakerAPI.apply(new SetToolStats(material, "ability", name));
}
//Sets various variables with reflection, making my life partially easier :D
private static class SetToolStats implements IUndoableAction {
protected int id;
protected Object old;
protected Object fresh;
protected final String material;
protected final String field;
protected final Object value;
public SetToolStats(String material, String field, Object value) {
this.material = material;
this.field = field;
this.value = value;
}
@Override
public void apply() {
old = TConstructRegistry.toolMaterialStrings.get(material);
id = TConstructHelper.getIDFromString(material);
if (id != -1 && old != null) {
if (value instanceof ToolMaterial) {
fresh = (ToolMaterial) value;
} else {
ToolMaterial t = (ToolMaterial) old;
fresh = new ToolMaterial(t.materialName, t.displayName, t.harvestLevel, t.durability, t.miningspeed, t.attack, t.handleModifier, t.reinforced, t.stonebound, t.tipStyle, t.ability);
ReflectionHelper.setPrivateValue(ToolMaterial.class, fresh, field, value);
}
TConstructRegistry.toolMaterials.put(id, (ToolMaterial) fresh);
TConstructRegistry.toolMaterialStrings.put(material, (ToolMaterial) fresh);
}
}
@Override
public boolean canUndo() {
return TConstructRegistry.toolMaterialStrings != null && id != -1 && old != null;
}
@Override
public void undo() {
TConstructRegistry.toolMaterials.put(id, (ToolMaterial) old);
TConstructRegistry.toolMaterialStrings.put(material, (ToolMaterial) old);
}
@Override
public String describe() {
return "Changing material stats field : + " + field + " for " + material;
}
@Override
public String describeUndo() {
return "Undoing change of material stats field : + " + field + " for " + material;
}
@Override
public Object getOverrideKey() {
return null;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Bow Stats
@ZenMethod
public static void setBowStats(String material, int durability, int drawspeed, double flightspeed) {
MineTweakerAPI.apply(new SetBowStats(material, "", new BowMaterial(durability, drawspeed, (float) flightspeed)));
}
@ZenMethod
public static void setBowDurability(String material, int value) {
MineTweakerAPI.apply(new SetBowStats(material, "durability", value));
}
@ZenMethod
public static void setBowDrawspeed(String material, int value) {
MineTweakerAPI.apply(new SetBowStats(material, "drawspeed", value));
}
@ZenMethod
public static void setBowFlightSpeed(String material, double value) {
MineTweakerAPI.apply(new SetBowStats(material, "flightSpeedMax", (float) value));
}
// Bow Stats
private static class SetBowStats extends SetToolStats {
public SetBowStats(String material, String field, Object value) {
super(material, field, value);
}
@Override
public void apply() {
id = TConstructHelper.getIDFromString(material);
old = TConstructRegistry.bowMaterials.get(id);
if (id != -1 && old != null) {
if (value instanceof BowMaterial) {
fresh = (BowMaterial) value;
} else {
BowMaterial b = (BowMaterial) old;
fresh = new BowMaterial(b.durability, b.drawspeed, b.flightSpeedMax);
ReflectionHelper.setPrivateValue(BowMaterial.class, fresh, field, value);
}
TConstructRegistry.bowMaterials.put(id, (BowMaterial) fresh);
}
}
@Override
public boolean canUndo() {
return TConstructRegistry.bowMaterials != null && id != -1 && old != null;
}
@Override
public void undo() {
TConstructRegistry.bowMaterials.put(id, (BowMaterial) old);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Arrow Stats
@ZenMethod
public static void setArrowStats(String material, double mass, double breakChance, double accuracy) {
MineTweakerAPI.apply(new SetArrowStats(material, "", new ArrowMaterial((float) mass, (float) breakChance, (float) accuracy)));
}
@ZenMethod
public static void setArrowMass(String material, double value) {
MineTweakerAPI.apply(new SetArrowStats(material, "mass", (float) value));
}
@ZenMethod
public static void setArrowBreakChance(String material, double value) {
MineTweakerAPI.apply(new SetArrowStats(material, "breakChance", (float) value));
}
@ZenMethod
public static void setArrowAccuracy(String material, double value) {
MineTweakerAPI.apply(new SetArrowStats(material, "accuracy", (float) value));
}
// Bow Stats
private static class SetArrowStats extends SetToolStats {
public SetArrowStats(String material, String field, Object value) {
super(material, field, value);
}
@Override
public void apply() {
id = TConstructHelper.getIDFromString(material);
old = TConstructRegistry.arrowMaterials.get(id);
if (id != -1 && old != null) {
if (value instanceof ArrowMaterial) {
fresh = (ArrowMaterial) value;
} else {
ArrowMaterial a = (ArrowMaterial) old;
fresh = new ArrowMaterial(a.mass, a.breakChance, a.accuracy);
ReflectionHelper.setPrivateValue(ArrowMaterial.class, fresh, field, value);
}
TConstructRegistry.arrowMaterials.put(id, (ArrowMaterial) fresh);
}
}
@Override
public boolean canUndo() {
return TConstructRegistry.arrowMaterials != null && id != -1 && old != null;
}
@Override
public void undo() {
TConstructRegistry.arrowMaterials.put(id, (ArrowMaterial) old);
}
}
}