Merge pull request #206 from Zixxl/master

Commits for v0.9.2
This commit is contained in:
Zixxl 2015-07-27 08:39:55 +02:00
commit 12238d395a
21 changed files with 532 additions and 22 deletions

View file

@ -17,7 +17,7 @@ buildscript {
apply plugin: 'forge'
version = "0.9.1"
version = "0.9.2"
group= "modtweaker" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "ModTweaker~2"

Binary file not shown.

View file

@ -4,6 +4,6 @@ public class ModProps {
public static final String NAME = "Mod Tweaker 2", name = NAME;
public static final String MODID = "modtweaker2", modid = MODID;
public static final String VERSION = "0.9.1", version = VERSION;
public static final String VERSION = "0.9.2", version = VERSION;
public static final String DEPENDENCIES = "required-after:MineTweaker3", dependencies = DEPENDENCIES;
}

View file

@ -1,6 +1,7 @@
package modtweaker2.helpers;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import mekanism.api.gas.GasStack;
@ -9,6 +10,8 @@ import minetweaker.MineTweakerImplementationAPI;
import minetweaker.api.player.IPlayer;
import minetweaker.mc1710.item.MCItemStack;
import modtweaker2.mods.mekanism.gas.MCGasStack;
import modtweaker2.mods.thaumcraft.aspect.AspectStack;
import modtweaker2.mods.thaumcraft.aspect.MCAspectStack;
import modtweaker2.utils.TweakerPlugin;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
@ -19,6 +22,8 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
public class LogHelper {
public static void logPrinted(IPlayer player) {
@ -66,6 +71,14 @@ public class LogHelper {
return new MCItemStack(new ItemStack((Block)object, 1, 0)).toString();
} else if (TweakerPlugin.isLoaded("Mekanism") && object instanceof GasStack) {
return new MCGasStack((GasStack)object).toString();
} else if (TweakerPlugin.isLoaded("Thaumcraft") && object instanceof AspectStack) {
return new MCAspectStack((AspectStack)object).toString();
} else if(TweakerPlugin.isLoaded("Thaumcraft") && object instanceof AspectList) {
List<AspectStack> stacks = new LinkedList<AspectStack>();
for(Aspect a : ((AspectList)object).getAspects()) {
stacks.add(new AspectStack(a, ((AspectList)object).getAmount(a)));
}
return(getListDescription(stacks));
} else if (object instanceof String) {
// Check if string specifies an oredict entry
List<ItemStack> ores = OreDictionary.getOres((String)object);
@ -75,6 +88,10 @@ public class LogHelper {
} else {
return "\"" + (String)object + "\"";
}
} else if (object instanceof List) {
return getListDescription((List)object);
} else if(object instanceof Object[]) {
return getListDescription(Arrays.asList((Object[])object));
} else if (object != null) {
return "\"" + object.toString() + "\"";
} else {

View file

@ -31,7 +31,7 @@ public class Inscriber {
@ZenMethod
public static void addRecipe(IItemStack[] imprintable, IItemStack plateA, IItemStack plateB, IItemStack out, String type) {
if(imprintable == null || out == null || (!type.equals("Press") || !type.equals("Inscribe"))) {
if(imprintable == null || out == null || (!type.equals("Press") && !type.equals("Inscribe"))) {
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", Inscriber.name));
return;
}

View file

@ -1,14 +1,17 @@
package modtweaker2.mods.railcraft;
import java.util.ArrayList;
import java.util.List;
import mods.railcraft.api.crafting.IBlastFurnaceRecipe;
import mods.railcraft.api.crafting.ICokeOvenRecipe;
import mods.railcraft.api.crafting.IRockCrusherRecipe;
import mods.railcraft.api.crafting.RailcraftCraftingManager;
import mods.railcraft.common.util.crafting.BlastFurnaceCraftingManager;
import mods.railcraft.common.util.crafting.BlastFurnaceCraftingManager.BlastFurnaceRecipe;
import mods.railcraft.common.util.crafting.CokeOvenCraftingManager.CokeOvenRecipe;
import mods.railcraft.common.util.crafting.RockCrusherCraftingManager.CrusherRecipe;
import modtweaker2.helpers.LogHelper;
import modtweaker2.helpers.ReflectionHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
@ -19,13 +22,18 @@ public class RailcraftHelper {
public static List<? extends ICokeOvenRecipe> oven = null;
public static List<? extends IRockCrusherRecipe> crusher = null;
public static List<IRecipe> rolling = null;
public static List<ItemStack> fuels = null;
static {
try {
furnace = RailcraftCraftingManager.blastFurnace.getRecipes();
oven = RailcraftCraftingManager.cokeOven.getRecipes();
crusher = RailcraftCraftingManager.rockCrusher.getRecipes();
rolling = RailcraftCraftingManager.rollingMachine.getRecipeList();
} catch (Exception e) {}
fuels = new ArrayList<ItemStack>(RailcraftCraftingManager.blastFurnace.getFuels());
ReflectionHelper.setPrivateValue(BlastFurnaceCraftingManager.class, RailcraftCraftingManager.blastFurnace, "fuels", fuels);
} catch (Exception e) { LogHelper.logError("Error in RailcraftHelper", e); }
}
private RailcraftHelper() {}

View file

@ -11,10 +11,14 @@ import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import mods.railcraft.api.crafting.IBlastFurnaceRecipe;
import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.LogHelper;
import modtweaker2.helpers.StackHelper;
import modtweaker2.mods.railcraft.RailcraftHelper;
import modtweaker2.utils.BaseListAddition;
import modtweaker2.utils.BaseListRemoval;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityFurnace;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
@ -22,9 +26,17 @@ import stanhebben.zenscript.annotations.ZenMethod;
public class BlastFurnace {
public static final String name = "Railcraft Blast Furnace";
public static final String nameFuel = "Railcraft Blast Furnace (Fuel)";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void addRecipe(IItemStack input, boolean matchDamage, boolean matchNBT, int cookTime, IItemStack output) {
if(input == null || output == null) {
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
return;
}
MineTweakerAPI.apply(new Add(RailcraftHelper.getBlastFurnaceRecipe(toStack(input), matchDamage, matchNBT, cookTime, toStack(output))));
}
@ -40,9 +52,16 @@ public class BlastFurnace {
return LogHelper.getStackDescription(recipe.getOutput());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void removeRecipe(IIngredient output) {
if(output == null) {
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
return;
}
List<IBlastFurnaceRecipe> recipes = new LinkedList<IBlastFurnaceRecipe>();
for (IBlastFurnaceRecipe r : RailcraftHelper.furnace) {
@ -69,4 +88,79 @@ public class BlastFurnace {
return LogHelper.getStackDescription(recipe.getOutput());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void addFuel(IIngredient itemInput) {
if(itemInput == null) {
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
return;
}
List<ItemStack> fuels = new LinkedList<ItemStack>();
for(IItemStack item : itemInput.getItems()) {
boolean match = false;
for(ItemStack fuel : RailcraftHelper.fuels) {
if(StackHelper.matches(item, InputHelper.toIItemStack(fuel))) {
match = true;
break;
}
}
if(!match && TileEntityFurnace.isItemFuel(InputHelper.toStack(item))) {
fuels.add(InputHelper.toStack(item));
}
}
if(!fuels.isEmpty()) {
MineTweakerAPI.apply(new AddFuels(fuels));
} else {
LogHelper.logWarning(String.format("No %s added.", nameFuel));
}
}
private static class AddFuels extends BaseListAddition<ItemStack> {
public AddFuels(List<ItemStack> fuels) {
super(BlastFurnace.nameFuel, RailcraftHelper.fuels, fuels);
}
@Override
protected String getRecipeInfo(ItemStack recipe) {
return LogHelper.getStackDescription(recipe);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
private static void removeFuel(IIngredient itemInput) {
List<ItemStack> fuels = new LinkedList<ItemStack>();
for(ItemStack fuel : RailcraftHelper.fuels) {
if(StackHelper.matches(itemInput, InputHelper.toIItemStack(fuel))) {
fuels.add(fuel);
}
}
if(!fuels.isEmpty()) {
MineTweakerAPI.apply(new RemoveFuels(fuels));
} else {
LogHelper.logWarning(String.format("No %s found for argument %s.", nameFuel, itemInput.toString()));
}
}
private static class RemoveFuels extends BaseListRemoval<ItemStack> {
public RemoveFuels(List<ItemStack> fuels) {
super(BlastFurnace.nameFuel, RailcraftHelper.fuels, fuels);
}
@Override
protected String getRecipeInfo(ItemStack recipe) {
return LogHelper.getStackDescription(recipe);
}
}
}

View file

@ -28,6 +28,8 @@ public class CokeOven {
public static final String name = "Railcraft Coke Oven";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Adds a recipe for the Coke Oven
*

View file

@ -23,6 +23,8 @@ public class RockCrusher {
public static final String name = "Railcraft Rock Crusher";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void addRecipe(IItemStack input, boolean matchDamage, boolean matchNBT, IItemStack[] output, double[] chances) {
IRockCrusherRecipe recipe = RailcraftHelper.getRockCrusherRecipe(toStack(input), matchDamage, matchNBT);

View file

@ -24,6 +24,8 @@ public class RollingMachine {
public static final String name = "Railcraft Rolling Machine";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void addShaped(IItemStack output, IIngredient[][] ingredients) {
MineTweakerAPI.apply(new Add(new ShapedOreRecipe(toStack(output), toShapedObjects(ingredients))));

View file

@ -1,16 +1,19 @@
package modtweaker2.mods.thaumcraft;
import minetweaker.MineTweakerAPI;
import modtweaker2.mods.thaumcraft.aspect.AspectBracketHandler;
import modtweaker2.mods.thaumcraft.handlers.Arcane;
import modtweaker2.mods.thaumcraft.handlers.Aspects;
import modtweaker2.mods.thaumcraft.handlers.Crucible;
import modtweaker2.mods.thaumcraft.handlers.Infusion;
import modtweaker2.mods.thaumcraft.handlers.Loot;
import modtweaker2.mods.thaumcraft.handlers.Research;
import modtweaker2.mods.thaumcraft.handlers.Test;
import modtweaker2.mods.thaumcraft.handlers.Warp;
public class Thaumcraft {
public Thaumcraft() {
MineTweakerAPI.registerBracketHandler(new AspectBracketHandler());
MineTweakerAPI.registerClass(Arcane.class);
MineTweakerAPI.registerClass(Aspects.class);
MineTweakerAPI.registerClass(Crucible.class);
@ -18,6 +21,5 @@ public class Thaumcraft {
MineTweakerAPI.registerClass(Research.class);
MineTweakerAPI.registerClass(Warp.class);
MineTweakerAPI.registerClass(Loot.class);
}
}

View file

@ -4,7 +4,12 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import minetweaker.api.item.IItemStack;
import modtweaker2.helpers.LogHelper;
import modtweaker2.helpers.ReflectionHelper;
import modtweaker2.mods.thaumcraft.aspect.AspectStack;
import modtweaker2.mods.thaumcraft.aspect.IAspectStack;
import net.minecraft.item.ItemStack;
import thaumcraft.api.ThaumcraftApi;
import thaumcraft.api.ThaumcraftApi.EntityTags;
import thaumcraft.api.aspects.Aspect;
@ -103,4 +108,30 @@ public class ThaumcraftHelper {
}
return output;
}
public static AspectStack[] toStacks(IAspectStack[] iStack) {
if (iStack == null) {
return null;
} else {
AspectStack[] output = new AspectStack[iStack.length];
for (int i = 0; i < iStack.length; i++) {
output[i] = toStack(iStack[i]);
}
return output;
}
}
public static AspectStack toStack(IAspectStack iStack) {
if (iStack == null) {
return null;
} else {
Object internal = iStack.getInternal();
if (!(internal instanceof AspectStack)) {
LogHelper.logError("Not a valid aspect stack: " + iStack);
}
return (AspectStack) internal;
}
}
}

View file

@ -0,0 +1,85 @@
package modtweaker2.mods.thaumcraft.aspect;
import java.util.List;
import minetweaker.IBracketHandler;
import minetweaker.MineTweakerAPI;
import minetweaker.annotations.BracketHandler;
import minetweaker.api.item.IngredientAny;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.expression.ExpressionCallStatic;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.type.natives.IJavaMethod;
import stanhebben.zenscript.util.ZenPosition;
import thaumcraft.api.aspects.Aspect;
@BracketHandler(priority = 100)
public class AspectBracketHandler implements IBracketHandler {
private final IZenSymbol symbolAny;
private final IJavaMethod method;
public AspectBracketHandler() {
this.symbolAny = MineTweakerAPI.getJavaStaticFieldSymbol(IngredientAny.class, "INSTANCE");
this.method = MineTweakerAPI.getJavaMethod(AspectBracketHandler.class, "getAspect", String.class);
}
public static IAspectStack getAspect(String name) {
Aspect aspect = Aspect.getAspect(name.toLowerCase());
if (aspect != null) {
return new MCAspectStack(new AspectStack(aspect, 1));
} else {
return null;
}
}
@Override
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
if (tokens.size() == 1 && tokens.get(0).getValue().equals("*")) {
return symbolAny;
}
if (tokens.size() > 2) {
if (tokens.get(0).getValue().equals("aspect") && tokens.get(1).getValue().equals(":")) {
return find(environment, tokens, 2, tokens.size());
}
}
return null;
}
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex) {
StringBuilder value = new StringBuilder();
for (int i = startIndex; i < endIndex; i++) {
Token token = tokens.get(i);
value.append(token.getValue());
}
Aspect aspect = Aspect.getAspect(value.toString().toLowerCase());
if(aspect != null) {
return new AspectReferenceSymbol(environment, value.toString());
}
return null;
}
private class AspectReferenceSymbol implements IZenSymbol {
private final IEnvironmentGlobal environment;
private final String name;
public AspectReferenceSymbol(IEnvironmentGlobal environment, String name) {
this.environment = environment;
this.name = name;
}
@Override
public IPartialExpression instance(ZenPosition position) {
return new ExpressionCallStatic(position, environment, method, new ExpressionString(position, name));
}
}
}

View file

@ -0,0 +1,44 @@
package modtweaker2.mods.thaumcraft.aspect;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
public class AspectStack {
public Aspect aspect;
public int amount;
public AspectStack(Aspect aspect, int amount) {
this.aspect = aspect;
this.amount = amount;
}
public Aspect getAspect() {
return aspect;
}
public AspectList getAspectList() {
AspectList aspectList = new AspectList();
aspectList.add(aspect, amount);
return aspectList;
}
public static AspectList join(AspectList... aspectLists) {
AspectList result = new AspectList();
for(AspectList aspectList : aspectLists) {
result.add(aspectList);
}
return result;
}
public static AspectList join(AspectStack... aspectStacks) {
AspectList result = new AspectList();
for(AspectStack stack : aspectStacks) {
result.add(stack.getAspectList());
}
return result;
}
}

View file

@ -0,0 +1,5 @@
package modtweaker2.mods.thaumcraft.aspect;
public interface IAspectDefinition {
}

View file

@ -0,0 +1,32 @@
package modtweaker2.mods.thaumcraft.aspect;
import java.util.List;
import minetweaker.api.item.IIngredient;
import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;
import stanhebben.zenscript.annotations.ZenOperator;
@ZenClass("modtweaker.aspect.IAspectStack")
public interface IAspectStack extends IIngredient {
@ZenGetter("definition")
public abstract IAspectDefinition getDefinition();
@ZenGetter("name")
public abstract String getName();
@ZenGetter("displayName")
public abstract String getDisplayName();
@ZenOperator(OperatorType.MUL)
@ZenMethod
public abstract IAspectStack amount(int amount);
@ZenMethod
public abstract IAspectStack withAmount(int amount);
public abstract List<IAspectStack> getAspects();
}

View file

@ -0,0 +1,11 @@
package modtweaker2.mods.thaumcraft.aspect;
public class MCAspectDefinition implements IAspectDefinition {
public MCAspectDefinition(AspectStack stack) {
// TODO Auto-generated constructor stub
}
}

View file

@ -0,0 +1,183 @@
package modtweaker2.mods.thaumcraft.aspect;
import java.util.Collections;
import java.util.List;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemCondition;
import minetweaker.api.item.IItemStack;
import minetweaker.api.item.IItemTransformer;
import minetweaker.api.item.IngredientOr;
import minetweaker.api.liquid.ILiquidStack;
import minetweaker.api.minecraft.MineTweakerMC;
import minetweaker.api.player.IPlayer;
import net.minecraft.item.ItemStack;
import thaumcraft.api.aspects.AspectList;
public class MCAspectStack implements IAspectStack {
private final AspectStack stack;
private final List<IAspectStack> aspects;
public MCAspectStack(AspectStack stack) {
if(stack == null) throw new IllegalArgumentException("stack cannot be null");
this.stack = stack;
this.aspects = Collections.<IAspectStack>singletonList(this);
}
@Override
public IItemStack applyTransform(IItemStack arg0, IPlayer arg1) {
return null;
}
@Override
public boolean contains(IIngredient ingredient) {
if(ingredient instanceof MCAspectStack) {
List<IAspectStack> aspects = ((MCAspectStack)ingredient).getAspects();
if((aspects == null) || (aspects.size() != 1)) {
return false;
}
return matches(aspects.get(0));
} else {
List<IItemStack> iitems = ingredient.getItems();
if ((iitems == null) || (iitems.size() != 1)) {
return false;
}
return matches((IItemStack)iitems.get(0));
}
}
@Override
public int getAmount() {
return this.stack.amount;
}
@Override
public Object getInternal() {
return this.stack;
}
@Override
public List<IItemStack> getItems() {
return null;
}
@Override
public List<IAspectStack> getAspects() {
return this.aspects;
}
@Override
public List<ILiquidStack> getLiquids() {
return Collections.emptyList();
}
@Override
public String getMark() {
return null;
}
@Override
public boolean hasTransformers() {
return false;
}
@Override
public IIngredient marked(String arg0) {
return null;
}
@Override
public boolean matches(IItemStack item) {
ItemStack internal = MineTweakerMC.getItemStack(item);
if(internal != null) {
AspectList itemAspectList = new AspectList(internal);
if(itemAspectList.aspects.keySet().contains(stack.aspect.getTag())) {
return true;
}
}
return false;
}
public boolean matches(IAspectStack aspect) {
if(aspect != null) {
Object internal = aspect.getInternal();
if(internal != null && internal instanceof AspectStack) {
if(this.stack.aspect.getTag().equals(((AspectStack)internal).aspect.getTag())) {
return true;
}
}
}
return false;
}
@Override
public boolean matches(ILiquidStack arg0) {
return false;
}
@Override
public IIngredient only(IItemCondition arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public IIngredient or(IIngredient ingredient) {
return new IngredientOr(this, ingredient);
}
@Override
public IIngredient transform(IItemTransformer arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public IAspectDefinition getDefinition() {
return new MCAspectDefinition(stack);
}
@Override
public String getName() {
return this.stack.aspect.getTag();
}
@Override
public String getDisplayName() {
return this.stack.aspect.getName();
}
@Override
public IAspectStack amount(int amount) {
return withAmount(amount);
}
@Override
public IAspectStack withAmount(int amount) {
AspectStack result = new AspectStack(this.stack.aspect, amount);
return new MCAspectStack(result);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("<aspect:").append(stack.aspect.getName()).append('>');
if(stack.amount > 1) {
sb.append(" * ").append(stack.amount);
}
return sb.toString();
}
}

View file

@ -1,7 +1,5 @@
package modtweaker2.mods.thaumcraft.commands;
import java.util.ArrayList;
import minetweaker.MineTweakerAPI;
import minetweaker.MineTweakerImplementationAPI;
import minetweaker.api.player.IPlayer;
@ -12,21 +10,15 @@ public class AspectLogger implements ICommandFunction{
@Override
public void execute(String[] arguments, IPlayer player) {
ArrayList<Aspect> aspects = new ArrayList<Aspect>();
aspects.addAll(Aspect.getPrimalAspects());
aspects.addAll(Aspect.getCompoundAspects());
System.out.println("Aspects: " + aspects.size());
for (Aspect set : aspects) {
if (!set.isPrimal()) {
System.out.println("Aspect:[ AspectName: " + set.getName() + ", description" + set.getLocalizedDescription() + ", Components:[" + set.getComponents()[0].getName() + ", " + set.getComponents()[1].getName() + "]\n");
MineTweakerAPI.logCommand("Aspect:[ AspectName: " + set.getName() + ", description" + set.getLocalizedDescription() + ", Components:[" + set.getComponents()[0].getName() + ", " + set.getComponents()[1].getName() + "]\n");
} else {
System.out.println("Aspect:[ AspectName: " + set.getName() + ", description" + set.getLocalizedDescription() + ", ]\n");
MineTweakerAPI.logCommand("Aspect:[ AspectName: " + set.getName() + ", description" + set.getLocalizedDescription() + ", ]\n");
}
}
for(Aspect aspect : Aspect.getPrimalAspects()) {
MineTweakerAPI.logCommand("<aspect:" + aspect.getName() + "> // " + aspect.getLocalizedDescription());
}
for(Aspect aspect : Aspect.getCompoundAspects()) {
MineTweakerAPI.logCommand("<aspect:" + aspect.getName() + "> // " + aspect.getLocalizedDescription() + " [<aspect:" + aspect.getComponents()[0].getName() + ">, <aspect:" + aspect.getComponents()[1].getName() + ">]");
}
if (player != null) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("List generated; see minetweaker.log in your minecraft dir"));
}