Started work on aspects
This commit is contained in:
parent
ec9560f9b0
commit
d052b208a0
5 changed files with 155 additions and 0 deletions
|
@ -4,6 +4,7 @@ import com.blamejared.compat.botania.Botania;
|
|||
import com.blamejared.compat.chisel.Chisel;
|
||||
import com.blamejared.compat.inspirations.Inspirations;
|
||||
import com.blamejared.compat.tconstruct.TConstruct;
|
||||
import com.blamejared.compat.thaumcraft.handlers.ThaumCraft;
|
||||
import crafttweaker.*;
|
||||
import net.minecraftforge.fml.common.*;
|
||||
import net.minecraftforge.fml.common.event.*;
|
||||
|
@ -21,6 +22,9 @@ public class ModTweaker {
|
|||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent e) {
|
||||
if(Loader.isModLoaded("thaumcraft")){
|
||||
ThaumCraft.preInit();
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package com.blamejared.compat.thaumcraft.handlers;
|
||||
|
||||
import com.blamejared.compat.thaumcraft.handlers.brackets.BracketHandlerAspect;
|
||||
import crafttweaker.zenscript.GlobalRegistry;
|
||||
|
||||
public class ThaumCraft {
|
||||
|
||||
|
||||
public static void preInit(){
|
||||
GlobalRegistry.registerBracketHandler(new BracketHandlerAspect());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.blamejared.compat.thaumcraft.handlers.aspects;
|
||||
|
||||
import crafttweaker.annotations.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
|
||||
@ZenRegister
|
||||
@ModOnly("thaumcraft")
|
||||
@ZenClass("thaumcraft.aspect.CTAspect")
|
||||
public class CTAspect {
|
||||
|
||||
private final Aspect internal;
|
||||
|
||||
public CTAspect(Aspect internal) {
|
||||
this.internal = internal;
|
||||
}
|
||||
|
||||
@ZenSetter("chatColour")
|
||||
public void setChatColour(String chatColour) {
|
||||
internal.setChatcolor(chatColour);
|
||||
}
|
||||
|
||||
@ZenGetter("chatColour")
|
||||
public String getChatColour() {
|
||||
return internal.getChatcolor();
|
||||
}
|
||||
|
||||
|
||||
public Aspect getInternal() {
|
||||
return internal;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.blamejared.compat.thaumcraft.handlers.aspects;
|
||||
|
||||
import crafttweaker.annotations.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
@ZenRegister
|
||||
@ModOnly("thaumcraft")
|
||||
@ZenClass("thaumcraft.aspect.CTAspectStack")
|
||||
public class CTAspectStack {
|
||||
|
||||
private CTAspect internal;
|
||||
private int amount;
|
||||
|
||||
public CTAspectStack(CTAspect internal, int amount) {
|
||||
this.internal = internal;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
public CTAspectStack setAmount(int amount) {
|
||||
return new CTAspectStack(internal, amount);
|
||||
}
|
||||
|
||||
@ZenGetter("internal")
|
||||
public CTAspect getInternal() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
@ZenGetter("amount")
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package com.blamejared.compat.thaumcraft.handlers.brackets;
|
||||
|
||||
import com.blamejared.compat.thaumcraft.handlers.aspects.*;
|
||||
import crafttweaker.CraftTweakerAPI;
|
||||
import crafttweaker.annotations.*;
|
||||
import crafttweaker.zenscript.IBracketHandler;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.expression.*;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.natives.IJavaMethod;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@BracketHandler(priority = 100)
|
||||
@ZenRegister
|
||||
public class BracketHandlerAspect implements IBracketHandler {
|
||||
|
||||
private static final Map<String, Aspect> aspects = new HashMap<>();
|
||||
|
||||
private final IJavaMethod method;
|
||||
|
||||
public BracketHandlerAspect() {
|
||||
method = CraftTweakerAPI.getJavaMethod(BracketHandlerAspect.class, "getAspect", String.class);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void rebuildRegistry() {
|
||||
aspects.clear();
|
||||
Aspect.aspects.forEach(aspects::put);
|
||||
|
||||
}
|
||||
|
||||
public static CTAspectStack getAspect(String name) {
|
||||
return new CTAspectStack(new CTAspect(Aspect.aspects.get(name)), 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
|
||||
|
||||
int fromIndex = 0;
|
||||
int toIndex = tokens.size();
|
||||
|
||||
if(tokens.size() > 2) {
|
||||
if(tokens.get(0).getValue().equals("aspect") && tokens.get(1).getValue().equals(":")) {
|
||||
fromIndex = 2;
|
||||
}
|
||||
}
|
||||
|
||||
return find(environment, tokens, fromIndex, toIndex);
|
||||
}
|
||||
|
||||
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> tokens, int startIndex, int endIndex) {
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
for(int i = startIndex; i < endIndex; i++) {
|
||||
Token token = tokens.get(i);
|
||||
valueBuilder.append(token.getValue());
|
||||
}
|
||||
|
||||
String name = valueBuilder.toString();
|
||||
if(!aspects.containsKey(name)) {
|
||||
rebuildRegistry();
|
||||
}
|
||||
if(aspects.containsKey(name)) {
|
||||
return position -> new ExpressionCallStatic(position, environment, method, new ExpressionString(position, valueBuilder.toString()));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue