mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-18 06:40:55 +00:00
Terrascript refactor
This commit is contained in:
+10
-10
@@ -12,11 +12,11 @@ import net.jafama.FastMath;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.NoiseChunkGenerator3D;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.SamplerProvider;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
@@ -25,10 +25,10 @@ import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
|
||||
public class CheckFunction implements Function<String> {
|
||||
private final Returnable<Number> x, y, z;
|
||||
private final Position position;
|
||||
private final Expression<Number> x, y, z;
|
||||
private final SourcePosition position;
|
||||
|
||||
public CheckFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Position position) {
|
||||
public CheckFunction(Expression<Number> x, Expression<Number> y, Expression<Number> z, SourcePosition position) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
@@ -37,26 +37,26 @@ public class CheckFunction implements Function<String> {
|
||||
|
||||
|
||||
@Override
|
||||
public String apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
public String invoke(ImplementationArguments implementationArguments, Scope scope) {
|
||||
|
||||
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
|
||||
|
||||
Vector2 xz = Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
|
||||
z.apply(implementationArguments, scope).doubleValue());
|
||||
Vector2 xz = Vector2.of(x.invoke(implementationArguments, scope).doubleValue(),
|
||||
z.invoke(implementationArguments, scope).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
|
||||
Vector3 location = arguments.getOrigin().toVector3Mutable().add(
|
||||
Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, scope).doubleValue(),
|
||||
Vector3.of(FastMath.roundToInt(xz.getX()), y.invoke(implementationArguments, scope).doubleValue(),
|
||||
FastMath.roundToInt(xz.getZ()))).immutable();
|
||||
|
||||
return apply(location, arguments.getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
public SourcePosition getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -9,9 +9,9 @@ package com.dfsek.terra.addon.terrascript.check;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ public class CheckFunctionBuilder implements FunctionBuilder<CheckFunction> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public CheckFunction build(List<Returnable<?>> argumentList, Position position) {
|
||||
return new CheckFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
|
||||
(Returnable<Number>) argumentList.get(2), position);
|
||||
public CheckFunction build(List<Expression<?>> argumentList, SourcePosition position) {
|
||||
return new CheckFunction((Expression<Number>) argumentList.get(0), (Expression<Number>) argumentList.get(1),
|
||||
(Expression<Number>) argumentList.get(2), position);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,9 +35,9 @@ public class CheckFunctionBuilder implements FunctionBuilder<CheckFunction> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
case 0, 1, 2 -> Expression.ReturnType.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user