mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-04 00:45:57 +00:00
fix StructureScript#test
This commit is contained in:
parent
26504d6d83
commit
aec1d671fa
@ -20,9 +20,11 @@ import com.dfsek.terra.api.structures.script.builders.RandomFunctionBuilder;
|
|||||||
import com.dfsek.terra.api.structures.script.builders.RecursionsFunctionBuilder;
|
import com.dfsek.terra.api.structures.script.builders.RecursionsFunctionBuilder;
|
||||||
import com.dfsek.terra.api.structures.script.builders.StructureFunctionBuilder;
|
import com.dfsek.terra.api.structures.script.builders.StructureFunctionBuilder;
|
||||||
import com.dfsek.terra.api.structures.script.builders.UnaryNumberFunctionBuilder;
|
import com.dfsek.terra.api.structures.script.builders.UnaryNumberFunctionBuilder;
|
||||||
|
import com.dfsek.terra.api.structures.script.builders.UnaryStringFunctionBuilder;
|
||||||
import com.dfsek.terra.api.structures.structure.Rotation;
|
import com.dfsek.terra.api.structures.structure.Rotation;
|
||||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||||
import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer;
|
import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer;
|
||||||
|
import com.dfsek.terra.debug.Debug;
|
||||||
import com.dfsek.terra.generation.math.SamplerCache;
|
import com.dfsek.terra.generation.math.SamplerCache;
|
||||||
import com.dfsek.terra.registry.LootRegistry;
|
import com.dfsek.terra.registry.LootRegistry;
|
||||||
import com.dfsek.terra.registry.ScriptRegistry;
|
import com.dfsek.terra.registry.ScriptRegistry;
|
||||||
@ -38,6 +40,7 @@ import java.util.Random;
|
|||||||
public class StructureScript {
|
public class StructureScript {
|
||||||
private final Block block;
|
private final Block block;
|
||||||
private final String id;
|
private final String id;
|
||||||
|
String tempID;
|
||||||
private final LinkedHashMap<Location, StructureBuffer> cache;
|
private final LinkedHashMap<Location, StructureBuffer> cache;
|
||||||
|
|
||||||
public StructureScript(InputStream inputStream, TerraPlugin main, ScriptRegistry registry, LootRegistry lootRegistry, SamplerCache cache) throws ParseException {
|
public StructureScript(InputStream inputStream, TerraPlugin main, ScriptRegistry registry, LootRegistry lootRegistry, SamplerCache cache) throws ParseException {
|
||||||
@ -47,6 +50,7 @@ public class StructureScript {
|
|||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.registerFunction("block", new BlockFunctionBuilder(main))
|
parser.registerFunction("block", new BlockFunctionBuilder(main))
|
||||||
.registerFunction("check", new CheckFunctionBuilder(main, cache))
|
.registerFunction("check", new CheckFunctionBuilder(main, cache))
|
||||||
.registerFunction("structure", new StructureFunctionBuilder(registry, main))
|
.registerFunction("structure", new StructureFunctionBuilder(registry, main))
|
||||||
@ -59,6 +63,7 @@ public class StructureScript {
|
|||||||
.registerFunction("entity", new EntityFunctionBuilder(main))
|
.registerFunction("entity", new EntityFunctionBuilder(main))
|
||||||
.registerFunction("getBiome", new BiomeFunctionBuilder(main))
|
.registerFunction("getBiome", new BiomeFunctionBuilder(main))
|
||||||
.registerFunction("getBlock", new CheckBlockFunctionBuilder())
|
.registerFunction("getBlock", new CheckBlockFunctionBuilder())
|
||||||
|
.registerFunction("print", new UnaryStringFunctionBuilder(string -> Debug.info("[" + tempID + "] " + string)))
|
||||||
.registerFunction("abs", new UnaryNumberFunctionBuilder(number -> FastMath.abs(number.doubleValue())))
|
.registerFunction("abs", new UnaryNumberFunctionBuilder(number -> FastMath.abs(number.doubleValue())))
|
||||||
.registerFunction("pow", new BinaryNumberFunctionBuilder((number, number2) -> FastMath.pow(number.doubleValue(), number2.doubleValue())))
|
.registerFunction("pow", new BinaryNumberFunctionBuilder((number, number2) -> FastMath.pow(number.doubleValue(), number2.doubleValue())))
|
||||||
.registerFunction("sqrt", new UnaryNumberFunctionBuilder(number -> FastMath.sqrt(number.doubleValue())))
|
.registerFunction("sqrt", new UnaryNumberFunctionBuilder(number -> FastMath.sqrt(number.doubleValue())))
|
||||||
@ -71,6 +76,7 @@ public class StructureScript {
|
|||||||
|
|
||||||
block = parser.parse();
|
block = parser.parse();
|
||||||
this.id = parser.getID();
|
this.id = parser.getID();
|
||||||
|
tempID = id;
|
||||||
this.cache = new LinkedHashMap<Location, StructureBuffer>() {
|
this.cache = new LinkedHashMap<Location, StructureBuffer>() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean removeEldestEntry(Map.Entry<Location, StructureBuffer> eldest) {
|
protected boolean removeEldestEntry(Map.Entry<Location, StructureBuffer> eldest) {
|
||||||
@ -106,7 +112,8 @@ public class StructureScript {
|
|||||||
|
|
||||||
public boolean test(Location location, Random random, Rotation rotation) {
|
public boolean test(Location location, Random random, Rotation rotation) {
|
||||||
StructureBuffer buffer = new StructureBuffer(location);
|
StructureBuffer buffer = new StructureBuffer(location);
|
||||||
return !block.apply(new TerraImplementationArguments(buffer, rotation, random, 0)).getLevel().equals(Block.ReturnLevel.FAIL);
|
block.apply(new TerraImplementationArguments(buffer, rotation, random, 0));
|
||||||
|
return buffer.succeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean executeInBuffer(Buffer buffer, Random random, Rotation rotation, int recursions) {
|
public boolean executeInBuffer(Buffer buffer, Random random, Rotation rotation, int recursions) {
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
package com.dfsek.terra.api.structures.script.builders;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.structures.parser.lang.ImplementationArguments;
|
||||||
|
import com.dfsek.terra.api.structures.parser.lang.Returnable;
|
||||||
|
import com.dfsek.terra.api.structures.parser.lang.functions.Function;
|
||||||
|
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
|
||||||
|
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UnaryStringFunctionBuilder implements FunctionBuilder<Function<Void>> {
|
||||||
|
|
||||||
|
private final java.util.function.Consumer<String> function;
|
||||||
|
|
||||||
|
public UnaryStringFunctionBuilder(java.util.function.Consumer<String> function) {
|
||||||
|
this.function = function;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Function<Void> build(List<Returnable<?>> argumentList, Position position) {
|
||||||
|
return new Function<Void>() {
|
||||||
|
@Override
|
||||||
|
public ReturnType returnType() {
|
||||||
|
return ReturnType.VOID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public Void apply(ImplementationArguments implementationArguments) {
|
||||||
|
function.accept(((Returnable<String>) argumentList.get(0)).apply(implementationArguments));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Position getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int argNumber() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Returnable.ReturnType getArgument(int position) {
|
||||||
|
if(position == 0) return Returnable.ReturnType.NUMBER;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ dump-default: true
|
|||||||
biome-search-resolution: 4
|
biome-search-resolution: 4
|
||||||
cache:
|
cache:
|
||||||
carver: 512
|
carver: 512
|
||||||
structure: 128
|
structure: 32
|
||||||
sampler: 512
|
sampler: 512
|
||||||
master-disable:
|
master-disable:
|
||||||
caves: false
|
caves: false
|
Loading…
x
Reference in New Issue
Block a user