Add missing brackethandler for crafttweaker

This commit is contained in:
Tom Elfring committed 2017-08-19 17:52:50 +02:00
1 parent 6c6e9e22db
commit 29e31e5b1b
8 files changed
+131 -7

No files matched your search

@@ -0,0 +1,104 @@
package mekanism.common.integration.crafttweaker.gas;
import crafttweaker.CraftTweakerAPI;
import crafttweaker.annotations.BracketHandler;
import crafttweaker.annotations.ModOnly;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IngredientAny;
import crafttweaker.zenscript.IBracketHandler;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
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 java.util.List;
@BracketHandler(priority = 100)
@ModOnly("mtlib")
@ZenRegister
public class GasBracketHandler implements IBracketHandler
{
private final IZenSymbol symbolAny;
private final IJavaMethod method;
public GasBracketHandler()
{
this.symbolAny = CraftTweakerAPI.getJavaStaticFieldSymbol(IngredientAny.class, "INSTANCE");
this.method = CraftTweakerAPI.getJavaMethod(GasBracketHandler.class, "getGas", String.class);
}
@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("gas") && 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 valueBuilder = new StringBuilder();
for (int i = startIndex; i < endIndex; i++)
{
Token token = tokens.get(i);
valueBuilder.append(token.getValue());
}
Gas gas = GasRegistry.getGas(valueBuilder.toString());
if (gas != null)
{
return new GasReferenceSymbol(environment, valueBuilder.toString());
}
return null;
}
private class GasReferenceSymbol implements IZenSymbol
{
private final IEnvironmentGlobal environment;
private final String name;
public GasReferenceSymbol(IEnvironmentGlobal environment, String name)
{
this.environment = environment;
this.name = name;
}
@Override
public IPartialExpression instance(ZenPosition zenPosition)
{
return new ExpressionCallStatic(zenPosition, environment, method, new ExpressionString(zenPosition, name));
}
}
public static IGasStack getGas(String name)
{
Gas gas = GasRegistry.getGas(name);
if (gas != null)
{
return new CraftTweakerGasStack(new GasStack(gas, 1));
}
else
{
return null;
}
}
}
@@ -1,11 +1,15 @@
package mekanism.common.integration.crafttweaker.gas;
import crafttweaker.annotations.ModOnly;
import crafttweaker.annotations.ZenRegister;
import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenOperator;
@ZenClass("mod.mekanism.gas.IGasDefinition")
@ModOnly("mtlib")
@ZenRegister
public interface IGasDefinition
{
@ZenOperator(OperatorType.MUL)
@@ -1,5 +1,7 @@
package mekanism.common.integration.crafttweaker.gas;
import crafttweaker.annotations.ModOnly;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IIngredient;
import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.annotations.ZenClass;
@@ -8,6 +10,8 @@ import stanhebben.zenscript.annotations.ZenMethod;
import stanhebben.zenscript.annotations.ZenOperator;
@ZenClass("mod.mekanism.gas.IGasStack")
@ModOnly("mtlib")
@ZenRegister
public interface IGasStack extends IIngredient
{
@ZenGetter("definition")
@@ -26,7 +26,7 @@ import stanhebben.zenscript.annotations.ZenMethod;
import java.util.HashMap;
import java.util.Map;
@ZenClass("mods.mekanism.crystallizer")
@ZenClass("mods.mekanism.chemical.crystallizer")
@ModOnly("mtlib")
@ZenRegister
public class ChemicalCrystallizer
@@ -3,6 +3,8 @@ package mekanism.common.integration.crafttweaker.handlers;
import com.blamejared.mtlib.helpers.InputHelper;
import com.blamejared.mtlib.helpers.LogHelper;
import com.blamejared.mtlib.helpers.StackHelper;
import crafttweaker.annotations.ModOnly;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IIngredient;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.item.IngredientAny;
@@ -25,6 +27,8 @@ import java.util.HashMap;
import java.util.Map;
@ZenClass("mods.mekanism.chemical.oxidizer")
@ModOnly("mtlib")
@ZenRegister
public class ChemicalOxidizer
{
public static final String NAME = "Mekanism Chemical Oxidizer";
@@ -45,18 +45,18 @@ public class Enrichment
}
@ZenMethod
public static void removeRecipe(IIngredient itemOutput, @Optional IIngredient itemInput)
public static void removeRecipe(IIngredient itemInput, @Optional IIngredient itemOutput)
{
if (itemOutput == null)
if (itemInput == null)
{
LogHelper.logError(String.format("Required parameters missing for %s recipe.", NAME));
}
if (itemInput == null)
itemInput = IngredientAny.INSTANCE;
if (itemOutput == null)
itemOutput = IngredientAny.INSTANCE;
CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.ENRICHMENT_CHAMBER.get(), itemOutput, itemInput));
CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(NAME, RecipeHandler.Recipe.ENRICHMENT_CHAMBER.get(), itemInput, itemOutput));
}
private static class Remove extends RemoveMekanismRecipe
@@ -64,7 +64,7 @@ public class Enrichment
private IIngredient itemOutput;
private IIngredient itemInput;
public Remove(String name, Map<MachineInput, MachineRecipe> map, IIngredient itemOutput, IIngredient itemInput)
public Remove(String name, Map<MachineInput, MachineRecipe> map, IIngredient itemInput, IIngredient itemOutput)
{
super(name, map);
this.itemOutput = itemOutput;
@@ -1,6 +1,8 @@
package mekanism.common.integration.crafttweaker.handlers;
import com.blamejared.mtlib.helpers.LogHelper;
import crafttweaker.annotations.ModOnly;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IIngredient;
import crafttweaker.api.item.IngredientAny;
import mekanism.common.integration.crafttweaker.CrafttweakerIntegration;
@@ -22,6 +24,8 @@ import java.util.HashMap;
import java.util.Map;
@ZenClass("mods.mekanism.solarneutronactivator")
@ModOnly("mtlib")
@ZenRegister
public class SolarNeutronActivator
{
public static final String NAME = "Mekanism Solar Neutron Activator";
@@ -3,6 +3,8 @@ package mekanism.common.integration.crafttweaker.handlers;
import com.blamejared.mtlib.helpers.InputHelper;
import com.blamejared.mtlib.helpers.LogHelper;
import com.blamejared.mtlib.helpers.StackHelper;
import crafttweaker.annotations.ModOnly;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IIngredient;
import crafttweaker.api.item.IngredientAny;
import crafttweaker.api.liquid.ILiquidStack;
@@ -22,6 +24,8 @@ import java.util.HashMap;
import java.util.Map;
@ZenClass("mods.mekanism.thermalevaporation")
@ModOnly("mtlib")
@ZenRegister
public class ThermalEvaporation
{
public static final String NAME = "Mekanism Solar Evaporation";