mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-11 02:06:07 +00:00
replace implementation arguments with context
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package com.dfsek.terra.addons.terrascript.api;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.api.ImplementationArguments;
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
import com.dfsek.terra.api.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structure.rotation.Rotation;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class TerraImplementationArguments implements ImplementationArguments {
|
||||
public class TerraProperties implements Properties {
|
||||
private final Buffer buffer;
|
||||
private final Rotation rotation;
|
||||
private final Random random;
|
||||
@@ -15,7 +16,7 @@ public class TerraImplementationArguments implements ImplementationArguments {
|
||||
private final int recursions;
|
||||
private boolean waterlog = false;
|
||||
|
||||
public TerraImplementationArguments(Buffer buffer, Rotation rotation, Random random, World world, int recursions) {
|
||||
public TerraProperties(Buffer buffer, Rotation rotation, Random random, World world, int recursions) {
|
||||
this.buffer = buffer;
|
||||
this.rotation = rotation;
|
||||
this.random = random;
|
||||
@@ -30,7 +30,7 @@ public class BinaryNumberFunctionBuilder implements FunctionBuilder<Function<Num
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Number apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
return function.apply(((Returnable<Number>) argumentList.get(0)).apply(, implementationArguments, variableMap), ((Returnable<Number>) argumentList.get(1)).apply(, implementationArguments, variableMap));
|
||||
return function.apply(((Returnable<Number>) argumentList.get(0)).apply(context, variableMap), ((Returnable<Number>) argumentList.get(1)).apply(context, variableMap));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.dfsek.terra.addons.terrascript.api.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.api.Position;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
|
||||
import java.util.List;
|
||||
@@ -14,9 +14,9 @@ import java.util.function.BiConsumer;
|
||||
|
||||
public class UnaryBooleanFunctionBuilder implements FunctionBuilder<Function<Void>> {
|
||||
|
||||
private final BiConsumer<Boolean, TerraImplementationArguments> function;
|
||||
private final BiConsumer<Boolean, TerraProperties> function;
|
||||
|
||||
public UnaryBooleanFunctionBuilder(BiConsumer<Boolean, TerraImplementationArguments> function) {
|
||||
public UnaryBooleanFunctionBuilder(BiConsumer<Boolean, TerraProperties> function) {
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class UnaryBooleanFunctionBuilder implements FunctionBuilder<Function<Voi
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Void apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
function.accept(((Returnable<Boolean>) argumentList.get(0)).apply(, implementationArguments, variableMap), (TerraImplementationArguments) implementationArguments);
|
||||
function.accept(((Returnable<Boolean>) argumentList.get(0)).apply(context, variableMap), context.get(TerraProperties.class));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class UnaryNumberFunctionBuilder implements FunctionBuilder<Function<Numb
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Number apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
return function.apply(((Returnable<Number>) argumentList.get(0)).apply(, implementationArguments, variableMap));
|
||||
return function.apply(((Returnable<Number>) argumentList.get(0)).apply(context, variableMap));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,7 +29,7 @@ public class UnaryStringFunctionBuilder implements FunctionBuilder<Function<Void
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Void apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
function.accept(((Returnable<String>) argumentList.get(0)).apply(, implementationArguments, variableMap));
|
||||
function.accept(((Returnable<String>) argumentList.get(0)).apply(context, variableMap));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,17 @@ import com.dfsek.terra.addons.terrascript.api.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.api.Position;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ZeroArgFunctionBuilder<T> implements FunctionBuilder<Function<T>> {
|
||||
private final java.util.function.Function<TerraImplementationArguments, T> function;
|
||||
private final java.util.function.Function<TerraProperties, T> function;
|
||||
private final Returnable.ReturnType type;
|
||||
|
||||
public ZeroArgFunctionBuilder(java.util.function.Function<TerraImplementationArguments, T> function, Returnable.ReturnType type) {
|
||||
public ZeroArgFunctionBuilder(java.util.function.Function<TerraProperties, T> function, Returnable.ReturnType type) {
|
||||
this.function = function;
|
||||
this.type = type;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class ZeroArgFunctionBuilder<T> implements FunctionBuilder<Function<T>> {
|
||||
|
||||
@Override
|
||||
public T apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
return function.apply((TerraImplementationArguments) implementationArguments);
|
||||
return function.apply(context.get(TerraProperties.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,9 +2,9 @@ package com.dfsek.terra.addons.terrascript.functions;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.api.Function;
|
||||
import com.dfsek.terra.addons.terrascript.api.Position;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
@@ -32,15 +32,14 @@ public class BiomeFunction implements Function<String> {
|
||||
|
||||
@Override
|
||||
public String apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
TerraProperties properties = context.get(TerraProperties.class);
|
||||
Vector2 xz = new Vector2(x.apply(context, variableMap).doubleValue(), z.apply(context, variableMap).doubleValue());
|
||||
|
||||
Vector2 xz = new Vector2(x.apply(, implementationArguments, variableMap).doubleValue(), z.apply(, implementationArguments, variableMap).doubleValue());
|
||||
RotationUtil.rotateVector(xz, properties.getRotation());
|
||||
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
BiomeProvider grid = properties.getWorld().getBiomeProvider();
|
||||
|
||||
BiomeProvider grid = arguments.getWorld().getBiomeProvider();
|
||||
|
||||
return grid.getBiome(arguments.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(, implementationArguments, variableMap).intValue(), FastMath.roundToInt(xz.getZ()))), arguments.getWorld().getSeed()).getID();
|
||||
return grid.getBiome(properties.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(context, variableMap).intValue(), FastMath.roundToInt(xz.getZ()))), properties.getWorld().getSeed()).getID();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.dfsek.terra.addons.terrascript.api.lang.ConstantExpression;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.buffer.items.BufferedBlock;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
@@ -37,25 +37,25 @@ public class BlockFunction implements Function<Void> {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
void setBlock(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap, TerraImplementationArguments arguments, BlockState rot) {
|
||||
Vector2 xz = new Vector2(x.apply(, implementationArguments, variableMap).doubleValue(), z.apply(, implementationArguments, variableMap).doubleValue());
|
||||
void setBlock(Context context, Map<String, Variable<?>> variableMap, TerraProperties arguments, BlockState rot) {
|
||||
Vector2 xz = new Vector2(x.apply(context, variableMap).doubleValue(), z.apply(context, variableMap).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
|
||||
RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse());
|
||||
arguments.getBuffer().addItem(new BufferedBlock(rot, overwrite.apply(, implementationArguments, variableMap), main, arguments.isWaterlog()), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(, implementationArguments, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ())));
|
||||
arguments.getBuffer().addItem(new BufferedBlock(rot, overwrite.apply(context, variableMap), main, arguments.isWaterlog()), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(context, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
BlockState rot = getBlockState(implementationArguments, variableMap).clone();
|
||||
setBlock(implementationArguments, variableMap, arguments, rot);
|
||||
TerraProperties arguments = context.get(TerraProperties.class);
|
||||
BlockState rot = getBlockState(context, variableMap).clone();
|
||||
setBlock(context, variableMap, arguments, rot);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected BlockState getBlockState(ImplementationArguments arguments, Map<String, Variable<?>> variableMap) {
|
||||
return data.computeIfAbsent(blockData.apply(, arguments, variableMap), main.getWorldHandle()::createBlockData);
|
||||
protected BlockState getBlockState(Context context, Map<String, Variable<?>> variableMap) {
|
||||
return data.computeIfAbsent(blockData.apply(context, variableMap), main.getWorldHandle()::createBlockData);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,7 +77,7 @@ public class BlockFunction implements Function<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState getBlockState(ImplementationArguments arguments, Map<String, Variable<?>> variableMap) {
|
||||
protected BlockState getBlockState(Context arguments, Map<String, Variable<?>> variableMap) {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.dfsek.terra.addons.terrascript.api.Function;
|
||||
import com.dfsek.terra.addons.terrascript.api.Position;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.vector.Vector2;
|
||||
@@ -27,13 +27,13 @@ public class CheckBlockFunction implements Function<String> {
|
||||
|
||||
@Override
|
||||
public String apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
TerraProperties properties = context.get(TerraProperties.class);
|
||||
|
||||
Vector2 xz = new Vector2(x.apply(, implementationArguments, variableMap).doubleValue(), z.apply(, implementationArguments, variableMap).doubleValue());
|
||||
Vector2 xz = new Vector2(x.apply(context, variableMap).doubleValue(), z.apply(context, variableMap).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
RotationUtil.rotateVector(xz, properties.getRotation());
|
||||
|
||||
String data = arguments.getWorld().getBlockData(arguments.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(, implementationArguments, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ())))).getAsString();
|
||||
String data = properties.getWorld().getBlockData(properties.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(context, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ())))).getAsString();
|
||||
if(data.contains("[")) return data.substring(0, data.indexOf('[')); // Strip properties
|
||||
else return data;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.dfsek.terra.addons.terrascript.api.Function;
|
||||
import com.dfsek.terra.addons.terrascript.api.Position;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
@@ -34,14 +34,14 @@ public class CheckFunction implements Function<String> {
|
||||
public String apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
|
||||
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
TerraProperties arguments = context.get(TerraProperties.class);
|
||||
|
||||
|
||||
Vector2 xz = new Vector2(x.apply(, implementationArguments, variableMap).doubleValue(), z.apply(, implementationArguments, variableMap).doubleValue());
|
||||
Vector2 xz = new Vector2(x.apply(context, variableMap).doubleValue(), z.apply(context, variableMap).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
|
||||
Vector3 location = arguments.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(, implementationArguments, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ())));
|
||||
Vector3 location = arguments.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(context, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ())));
|
||||
|
||||
return apply(location, arguments.getWorld());
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.dfsek.terra.addons.terrascript.api.lang.ConstantExpression;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.buffer.items.BufferedEntity;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
@@ -36,12 +36,12 @@ public class EntityFunction implements Function<Void> {
|
||||
|
||||
@Override
|
||||
public Void apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
Vector2 xz = new Vector2(x.apply(, implementationArguments, variableMap).doubleValue(), z.apply(, implementationArguments, variableMap).doubleValue());
|
||||
TerraProperties arguments = context.get(TerraProperties.class);
|
||||
Vector2 xz = new Vector2(x.apply(context, variableMap).doubleValue(), z.apply(context, variableMap).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
|
||||
arguments.getBuffer().addItem(new BufferedEntity(data, main), new Vector3(xz.getX(), y.apply(, implementationArguments, variableMap).doubleValue(), xz.getZ()));
|
||||
arguments.getBuffer().addItem(new BufferedEntity(data, main), new Vector3(xz.getX(), y.apply(context, variableMap).doubleValue(), xz.getZ()));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.dfsek.terra.addons.terrascript.api.Function;
|
||||
import com.dfsek.terra.addons.terrascript.api.Position;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.vector.Vector2;
|
||||
@@ -26,11 +26,11 @@ public class GetMarkFunction implements Function<String> {
|
||||
|
||||
@Override
|
||||
public String apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
Vector2 xz = new Vector2(x.apply(, implementationArguments, variableMap).doubleValue(), z.apply(, implementationArguments, variableMap).doubleValue());
|
||||
TerraProperties arguments = context.get(TerraProperties.class);
|
||||
Vector2 xz = new Vector2(x.apply(context, variableMap).doubleValue(), z.apply(context, variableMap).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
String mark = arguments.getBuffer().getMark(new Vector3(FastMath.floorToInt(xz.getX()), FastMath.floorToInt(y.apply(, implementationArguments, variableMap).doubleValue()), FastMath.floorToInt(xz.getZ())));
|
||||
String mark = arguments.getBuffer().getMark(new Vector3(FastMath.floorToInt(xz.getX()), FastMath.floorToInt(y.apply(context, variableMap).doubleValue()), FastMath.floorToInt(xz.getZ())));
|
||||
return mark == null ? "" : mark;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.dfsek.terra.addons.terrascript.api.StructureScript;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.buffer.items.BufferedLootApplication;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
@@ -39,12 +39,12 @@ public class LootFunction implements Function<Void> {
|
||||
|
||||
@Override
|
||||
public Void apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
Vector2 xz = new Vector2(x.apply(, implementationArguments, variableMap).doubleValue(), z.apply(, implementationArguments, variableMap).doubleValue());
|
||||
TerraProperties arguments = context.get(TerraProperties.class);
|
||||
Vector2 xz = new Vector2(x.apply(context, variableMap).doubleValue(), z.apply(context, variableMap).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
|
||||
String id = data.apply(, implementationArguments, variableMap);
|
||||
String id = data.apply(context, variableMap);
|
||||
LootTable table = registry.get(id);
|
||||
|
||||
if(table == null) {
|
||||
@@ -52,7 +52,7 @@ public class LootFunction implements Function<Void> {
|
||||
return null;
|
||||
}
|
||||
|
||||
arguments.getBuffer().addItem(new BufferedLootApplication(table, main, script), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(, implementationArguments, variableMap).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||
arguments.getBuffer().addItem(new BufferedLootApplication(table, main, script), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(context, variableMap).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.dfsek.terra.addons.terrascript.api.lang.ConstantExpression;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.buffer.items.BufferedPulledBlock;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
@@ -35,13 +35,13 @@ public class PullFunction implements Function<Void> {
|
||||
|
||||
@Override
|
||||
public Void apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
Vector2 xz = new Vector2(x.apply(, implementationArguments, variableMap).doubleValue(), z.apply(, implementationArguments, variableMap).doubleValue());
|
||||
TerraProperties arguments = context.get(TerraProperties.class);
|
||||
Vector2 xz = new Vector2(x.apply(context, variableMap).doubleValue(), z.apply(context, variableMap).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
BlockState rot = data.clone();
|
||||
RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse());
|
||||
arguments.getBuffer().addItem(new BufferedPulledBlock(rot), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(, implementationArguments, variableMap).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||
arguments.getBuffer().addItem(new BufferedPulledBlock(rot), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(context, variableMap).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.dfsek.terra.addons.terrascript.api.Function;
|
||||
import com.dfsek.terra.addons.terrascript.api.Position;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -26,7 +26,7 @@ public class RandomFunction implements Function<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
return ((TerraImplementationArguments) implementationArguments).getRandom().nextInt(numberReturnable.apply(, implementationArguments, variableMap).intValue());
|
||||
return context.get(TerraProperties.class).getRandom().nextInt(numberReturnable.apply(context, variableMap).intValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.dfsek.terra.addons.terrascript.functions;
|
||||
import com.dfsek.terra.addons.terrascript.api.Function;
|
||||
import com.dfsek.terra.addons.terrascript.api.Position;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -22,7 +22,7 @@ public class RecursionsFunction implements Function<Number> {
|
||||
|
||||
@Override
|
||||
public Number apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
return ((TerraImplementationArguments) implementationArguments).getRecursions();
|
||||
return context.get(TerraProperties.class).getRecursions();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.dfsek.terra.addons.terrascript.api.Function;
|
||||
import com.dfsek.terra.addons.terrascript.api.Position;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.vector.Vector2;
|
||||
@@ -28,12 +28,12 @@ public class SetMarkFunction implements Function<Void> {
|
||||
|
||||
@Override
|
||||
public Void apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
Vector2 xz = new Vector2(x.apply(, implementationArguments, variableMap).doubleValue(), z.apply(, implementationArguments, variableMap).doubleValue());
|
||||
TerraProperties arguments = context.get(TerraProperties.class);
|
||||
Vector2 xz = new Vector2(x.apply(context, variableMap).doubleValue(), z.apply(context, variableMap).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
|
||||
arguments.getBuffer().setMark(mark.apply(, implementationArguments, variableMap), new Vector3(FastMath.floorToInt(xz.getX()), FastMath.floorToInt(y.apply(, implementationArguments, variableMap).doubleValue()), FastMath.floorToInt(xz.getZ())));
|
||||
arguments.getBuffer().setMark(mark.apply(context, variableMap), new Vector3(FastMath.floorToInt(xz.getX()), FastMath.floorToInt(y.apply(context, variableMap).doubleValue()), FastMath.floorToInt(xz.getZ())));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.dfsek.terra.addons.terrascript.api.Position;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.buffer.items.BufferedStateManipulator;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
@@ -32,11 +32,11 @@ public class StateFunction implements Function<Void> {
|
||||
|
||||
@Override
|
||||
public Void apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
Vector2 xz = new Vector2(x.apply(, implementationArguments, variableMap).doubleValue(), z.apply(, implementationArguments, variableMap).doubleValue());
|
||||
TerraProperties arguments = context.get(TerraProperties.class);
|
||||
Vector2 xz = new Vector2(x.apply(context, variableMap).doubleValue(), z.apply(context, variableMap).doubleValue());
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
|
||||
arguments.getBuffer().addItem(new BufferedStateManipulator(main, data.apply(, implementationArguments, variableMap)), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(, implementationArguments, variableMap).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||
arguments.getBuffer().addItem(new BufferedStateManipulator(main, data.apply(context, variableMap)), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(context, variableMap).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.dfsek.terra.addons.terrascript.api.Position;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.api.lang.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.api.buffer.IntermediateBuffer;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
@@ -45,16 +45,16 @@ public class StructureFunction implements Function<Boolean> {
|
||||
|
||||
@Override
|
||||
public Boolean apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
TerraProperties arguments = context.get(TerraProperties.class);
|
||||
|
||||
if(arguments.getRecursions() > main.getTerraConfig().getMaxRecursion())
|
||||
throw new RuntimeException("Structure recursion too deep: " + arguments.getRecursions());
|
||||
|
||||
Vector2 xz = new Vector2(x.apply(, implementationArguments, variableMap).doubleValue(), z.apply(, implementationArguments, variableMap).doubleValue());
|
||||
Vector2 xz = new Vector2(x.apply(context, variableMap).doubleValue(), z.apply(context, variableMap).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
|
||||
String app = id.apply(, implementationArguments, variableMap);
|
||||
String app = id.apply(context, variableMap);
|
||||
Structure script = registry.get(app);
|
||||
if(script == null) {
|
||||
main.logger().severe("No such structure " + app);
|
||||
@@ -62,7 +62,7 @@ public class StructureFunction implements Function<Boolean> {
|
||||
}
|
||||
|
||||
Rotation rotation1;
|
||||
String rotString = rotations.get(arguments.getRandom().nextInt(rotations.size())).apply(, implementationArguments, variableMap);
|
||||
String rotString = rotations.get(arguments.getRandom().nextInt(rotations.size())).apply(context, variableMap);
|
||||
try {
|
||||
rotation1 = Rotation.valueOf(rotString);
|
||||
} catch(IllegalArgumentException e) {
|
||||
@@ -70,7 +70,7 @@ public class StructureFunction implements Function<Boolean> {
|
||||
return null;
|
||||
}
|
||||
|
||||
Vector3 offset = new Vector3(FastMath.roundToInt(xz.getX()), y.apply(, implementationArguments, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ()));
|
||||
Vector3 offset = new Vector3(FastMath.roundToInt(xz.getX()), y.apply(context, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ()));
|
||||
|
||||
return script.generate(new IntermediateBuffer(arguments.getBuffer(), offset), arguments.getWorld(), arguments.getRandom(), arguments.getRotation().rotate(rotation1), arguments.getRecursions() + 1);
|
||||
}
|
||||
|
||||
@@ -23,15 +23,15 @@ public class Block implements Item<Block.ReturnInfo<?>> {
|
||||
return items;
|
||||
}
|
||||
|
||||
public ReturnInfo<?> apply(ImplementationArguments implementationArguments) {
|
||||
return apply(, implementationArguments, new HashMap<>());
|
||||
public ReturnInfo<?> apply(Context context) {
|
||||
return apply(context, new HashMap<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnInfo<?> apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
Map<String, Variable<?>> scope = new HashMap<>(variableMap);
|
||||
for(Item<?> item : items) {
|
||||
Object result = item.apply(, implementationArguments, scope);
|
||||
Object result = item.apply(context, scope);
|
||||
if(result instanceof ReturnInfo) {
|
||||
ReturnInfo<?> level = (ReturnInfo<?>) result;
|
||||
if(!level.getLevel().equals(ReturnLevel.NONE)) return level;
|
||||
|
||||
@@ -27,8 +27,8 @@ public class ForKeyword implements Keyword<Block.ReturnInfo<?>> {
|
||||
|
||||
@Override
|
||||
public Block.ReturnInfo<?> apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
for(initializer.apply(, implementationArguments, variableMap); statement.apply(, implementationArguments, variableMap); incrementer.apply(, implementationArguments, variableMap)) {
|
||||
Block.ReturnInfo<?> level = conditional.apply(, implementationArguments, variableMap);
|
||||
for(initializer.apply(context, variableMap); statement.apply(context, variableMap); incrementer.apply(context, variableMap)) {
|
||||
Block.ReturnInfo<?> level = conditional.apply(context, variableMap);
|
||||
if(level.getLevel().equals(Block.ReturnLevel.BREAK)) break;
|
||||
if(level.getLevel().isReturnFast()) return level;
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ public class IfKeyword implements Keyword<Block.ReturnInfo<?>> {
|
||||
|
||||
@Override
|
||||
public Block.ReturnInfo<?> apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
if(statement.apply(, implementationArguments, variableMap)) return conditional.apply(, implementationArguments, variableMap);
|
||||
if(statement.apply(context, variableMap)) return conditional.apply(context, variableMap);
|
||||
else {
|
||||
for(Pair<Returnable<Boolean>, Block> pair : elseIf) {
|
||||
if(pair.getLeft().apply(, implementationArguments, variableMap)) {
|
||||
return pair.getRight().apply(, implementationArguments, variableMap);
|
||||
if(pair.getLeft().apply(context, variableMap)) {
|
||||
return pair.getRight().apply(context, variableMap);
|
||||
}
|
||||
}
|
||||
if(elseBlock != null) return elseBlock.apply(, implementationArguments, variableMap);
|
||||
if(elseBlock != null) return elseBlock.apply(context, variableMap);
|
||||
}
|
||||
return new Block.ReturnInfo<>(Block.ReturnLevel.NONE, null);
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ public class WhileKeyword implements Keyword<Block.ReturnInfo<?>> {
|
||||
|
||||
@Override
|
||||
public Block.ReturnInfo<?> apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
while(statement.apply(, implementationArguments, variableMap)) {
|
||||
Block.ReturnInfo<?> level = conditional.apply(, implementationArguments, variableMap);
|
||||
while(statement.apply(context, variableMap)) {
|
||||
Block.ReturnInfo<?> level = conditional.apply(context, variableMap);
|
||||
if(level.getLevel().equals(Block.ReturnLevel.BREAK)) break;
|
||||
if(level.getLevel().isReturnFast()) return level;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,6 @@ public abstract class BinaryOperation<I, O> implements Returnable<O> {
|
||||
|
||||
@Override
|
||||
public O apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
return apply(left.apply(, implementationArguments, variableMap), right.apply(, implementationArguments, variableMap));
|
||||
return apply(left.apply(context, variableMap), right.apply(context, variableMap));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public abstract class UnaryOperation<T> implements Returnable<T> {
|
||||
|
||||
@Override
|
||||
public T apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
return apply(input.apply(, implementationArguments, variableMap));
|
||||
return apply(input.apply(context, variableMap));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,8 +21,8 @@ public class Assignment<T> implements Item<T> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public synchronized T apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
T val = value.apply(, implementationArguments, variableMap);
|
||||
public T apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
T val = value.apply(context, variableMap);
|
||||
((Variable<T>) variableMap.get(identifier)).setValue(val);
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Declaration<T> implements Item<T> {
|
||||
|
||||
@Override
|
||||
public T apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
T result = value.apply(, implementationArguments, variableMap);
|
||||
T result = value.apply(context, variableMap);
|
||||
switch(type) {
|
||||
case NUMBER:
|
||||
variableMap.put(identifier, new NumberVariable((Number) result, position));
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.dfsek.terra.addons.terrascript.script;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.api.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.api.StructureScript;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.addons.terrascript.api.buffer.DirectBuffer;
|
||||
import com.dfsek.terra.addons.terrascript.api.buffer.StructureBuffer;
|
||||
import com.dfsek.terra.addons.terrascript.api.exception.ParseException;
|
||||
@@ -10,6 +10,7 @@ import com.dfsek.terra.addons.terrascript.parser.Parser;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structure.LootTable;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
@@ -75,7 +76,7 @@ public class StructureScriptImpl implements StructureScript {
|
||||
try {
|
||||
return cache.get(location, () -> {
|
||||
StructureBuffer buf = new StructureBuffer(location);
|
||||
buf.setSucceeded(applyBlock(new TerraImplementationArguments(buf, rotation, random, world, 0)));
|
||||
buf.setSucceeded(applyBlock(new TerraProperties(buf, rotation, random, world, 0)));
|
||||
return buf;
|
||||
});
|
||||
} catch(ExecutionException e) {
|
||||
@@ -87,7 +88,7 @@ public class StructureScriptImpl implements StructureScript {
|
||||
@SuppressWarnings("try")
|
||||
public boolean generate(Buffer buffer, World world, Random random, Rotation rotation, int recursions) {
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_recursive:" + id)) {
|
||||
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, world, recursions));
|
||||
return applyBlock(new TerraProperties(buffer, rotation, random, world, recursions));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +97,7 @@ public class StructureScriptImpl implements StructureScript {
|
||||
public boolean generate(Vector3 location, World world, Random random, Rotation rotation) {
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_direct:" + id)) {
|
||||
DirectBuffer buffer = new DirectBuffer(location, world);
|
||||
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, world, 0));
|
||||
return applyBlock(new TerraProperties(buffer, rotation, random, world, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,9 +106,11 @@ public class StructureScriptImpl implements StructureScript {
|
||||
return id;
|
||||
}
|
||||
|
||||
private boolean applyBlock(TerraImplementationArguments arguments) {
|
||||
private boolean applyBlock(TerraProperties arguments) {
|
||||
try {
|
||||
return block.apply(arguments).getLevel() != Block.ReturnLevel.FAIL;
|
||||
Context context = new Context();
|
||||
context.put(arguments);
|
||||
return block.apply(context).getLevel() != Block.ReturnLevel.FAIL;
|
||||
} catch(RuntimeException e) {
|
||||
main.logger().severe("Failed to generate structure at " + arguments.getBuffer().getOrigin() + ": " + e.getMessage());
|
||||
main.getDebugLogger().stack(e);
|
||||
|
||||
@@ -54,9 +54,9 @@ public class ParserTest {
|
||||
long t = System.nanoTime() - l;
|
||||
System.out.println("Took " + (double) t / 1000000);
|
||||
|
||||
block.apply(, null, new HashMap<>());
|
||||
block.apply(null, new HashMap<>());
|
||||
|
||||
block.apply(, null, new HashMap<>());
|
||||
block.apply(null, new HashMap<>());
|
||||
}
|
||||
|
||||
private static class Test1 implements Function<Void> {
|
||||
@@ -72,7 +72,7 @@ public class ParserTest {
|
||||
|
||||
@Override
|
||||
public Void apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
System.out.println("string: " + a.apply(, implementationArguments, variableMap) + ", double: " + b.apply(, implementationArguments, variableMap));
|
||||
System.out.println("string: " + a.apply(context, variableMap) + ", double: " + b.apply(context, variableMap));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user