mirror of
https://github.com/GTNewHorizons/ModTweaker.git
synced 2026-11-12 00:07:57 +00:00
BracketHandler for thaumcraft aspects
This commit is contained in:
1 parent
db9b0e3c11
commit
99bd8eaa1e
10 files changed
+420
-18
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package modtweaker2.mods.thaumcraft.aspect;
|
||||
|
||||
public interface IAspectDefinition {
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package modtweaker2.mods.thaumcraft.aspect;
|
||||
|
||||
|
||||
|
||||
public class MCAspectDefinition implements IAspectDefinition {
|
||||
|
||||
public MCAspectDefinition(AspectStack stack) {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user