mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-24 00:56:38 +00:00
Reformat code
This commit is contained in:
@@ -338,9 +338,9 @@ public class Parser {
|
||||
|
||||
Returnable<?> value = parseExpression(tokens, true, scopeBuilder);
|
||||
ParserUtil.checkReturnType(value, returnType);
|
||||
|
||||
|
||||
String id = identifier.getContent();
|
||||
|
||||
|
||||
return switch(value.returnType()) {
|
||||
case NUMBER -> new NumAssignmentNode((Returnable<Number>) value, identifier.getPosition(), scopeBuilder.num(id));
|
||||
case STRING -> new StrAssignmentNode((Returnable<String>) value, identifier.getPosition(), scopeBuilder.str(id));
|
||||
|
||||
@@ -7,12 +7,12 @@ import com.dfsek.terra.addons.terrascript.parser.lang.Scope.ScopeBuilder;
|
||||
public class Executable {
|
||||
private final Block script;
|
||||
private final ThreadLocal<Scope> scope;
|
||||
|
||||
|
||||
public Executable(Block script, ScopeBuilder scopeBuilder) {
|
||||
this.script = script;
|
||||
this.scope = ThreadLocal.withInitial(scopeBuilder::build);
|
||||
}
|
||||
|
||||
|
||||
public boolean execute(ImplementationArguments arguments) {
|
||||
return script.apply(arguments, scope.get()).getLevel() != Block.ReturnLevel.FAIL;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class Scope {
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public int num(String id) {
|
||||
int num = numSize;
|
||||
indices.put(check(id), Pair.of(num, ReturnType.NUMBER));
|
||||
@@ -105,14 +105,14 @@ public class Scope {
|
||||
parent.updateBoolSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateNumSize(int size) {
|
||||
this.numSize = Math.max(numSize, size);
|
||||
if(parent != null) {
|
||||
parent.updateNumSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateStrSize(int size) {
|
||||
this.strSize = Math.max(strSize, size);
|
||||
if(parent != null) {
|
||||
|
||||
@@ -14,7 +14,7 @@ import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
public class BooleanConstant extends ConstantExpression<Boolean> {
|
||||
private final boolean constant;
|
||||
|
||||
|
||||
public BooleanConstant(Boolean constant, Position position) {
|
||||
super(constant, position);
|
||||
this.constant = constant;
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
public class NumericConstant extends ConstantExpression<Number> {
|
||||
private final double constant;
|
||||
|
||||
|
||||
public NumericConstant(Number constant, Position position) {
|
||||
super(constant, position);
|
||||
this.constant = constant.doubleValue();
|
||||
|
||||
@@ -19,12 +19,12 @@ public interface Function<T> extends Returnable<T> {
|
||||
public ReturnType returnType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return null;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class BooleanOrOperation extends BinaryOperation<Boolean, Boolean> {
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyBoolean(implementationArguments, scope) || right.applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.BOOLEAN;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ModuloOperation extends BinaryOperation<Number, Number> {
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) % right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class MultiplicationOperation extends BinaryOperation<Number, Number> {
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) * right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class NumberAdditionOperation extends BinaryOperation<Number, Number> {
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) + right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class SubtractionOperation extends BinaryOperation<Number, Number> {
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) - right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class EqualsStatement extends BinaryOperation<Object, Boolean> {
|
||||
if(leftValue instanceof Number l && rightValue instanceof Number r) {
|
||||
return Math.abs(l.doubleValue() - r.doubleValue()) <= EPSILON;
|
||||
}
|
||||
|
||||
|
||||
return leftValue.equals(rightValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class LessThanOrEqualsStatement extends BinaryOperation<Number, Boolean>
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) <= right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType returnType() {
|
||||
return Returnable.ReturnType.BOOLEAN;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class LessThanStatement extends BinaryOperation<Number, Boolean> {
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) < right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType returnType() {
|
||||
return Returnable.ReturnType.BOOLEAN;
|
||||
|
||||
@@ -7,36 +7,11 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.Parser;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Executable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.BinaryNumberFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.BiomeFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.BlockFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.CheckBlockFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.EntityFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.GetMarkFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.LootFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.PullFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.RandomFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.RecursionsFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.SetMarkFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.StateFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.StructureFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.UnaryBooleanFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.UnaryNumberFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.UnaryStringFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.ZeroArgFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.*;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.registry.key.Keyed;
|
||||
@@ -48,6 +23,15 @@ import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class StructureScript implements Structure, Keyed<StructureScript> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(StructureScript.class);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class LootFunction implements Function<Void> {
|
||||
y.apply(implementationArguments, scope)
|
||||
.intValue(),
|
||||
(int) Math.round(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
|
||||
|
||||
|
||||
try {
|
||||
BlockEntity data = arguments.getWorld().getBlockEntity(apply);
|
||||
if(!(data instanceof Container container)) {
|
||||
@@ -77,12 +77,12 @@ public class LootFunction implements Function<Void> {
|
||||
apply, data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
LootPopulateEvent event = new LootPopulateEvent(container, table,
|
||||
arguments.getWorld().getPack(), script);
|
||||
platform.getEventManager().callEvent(event);
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
|
||||
event.getTable().fillInventory(container.getInventory(),
|
||||
new Random(apply.hashCode()));
|
||||
data.update(false);
|
||||
|
||||
@@ -7,9 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
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.Scope;
|
||||
@@ -21,6 +18,9 @@ import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class StateFunction implements Function<Void> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(StateFunction.class);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
schema-version: 1
|
||||
contributors:
|
||||
- Terra contributors
|
||||
- Terra contributors
|
||||
id: structure-terrascript-loader
|
||||
version: @VERSION@
|
||||
entrypoints:
|
||||
- "com.dfsek.terra.addons.terrascript.TerraScriptAddon"
|
||||
- "com.dfsek.terra.addons.terrascript.TerraScriptAddon"
|
||||
website:
|
||||
issues: https://github.com/PolyhedralDev/Terra/issues
|
||||
source: https://github.com/PolyhedralDev/Terra
|
||||
docs: https://terra.polydev.org
|
||||
issues: https://github.com/PolyhedralDev/Terra/issues
|
||||
source: https://github.com/PolyhedralDev/Terra
|
||||
docs: https://terra.polydev.org
|
||||
license: MIT License
|
||||
Reference in New Issue
Block a user