mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-22 16:18:32 +00:00
clean up Structure API
This commit is contained in:
@@ -46,14 +46,11 @@ import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structure.LootTable;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structure.buffer.buffers.DirectBuffer;
|
||||
import com.dfsek.terra.api.structure.buffer.buffers.StructureBuffer;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
|
||||
|
||||
public class StructureScript implements Structure {
|
||||
@@ -132,24 +129,6 @@ public class StructureScript implements Structure {
|
||||
this.cache = CacheBuilder.newBuilder().maximumSize(platform.getTerraConfig().getStructureCache()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("try")
|
||||
public boolean generate(Vector3 location, WritableWorld world, Chunk chunk, Random random, Rotation rotation) {
|
||||
try(ProfileFrame ignore = platform.getProfiler().profile("terrascript_chunk:" + id)) {
|
||||
StructureBuffer buffer = computeBuffer(location, world, random, rotation);
|
||||
buffer.paste(location, chunk);
|
||||
return buffer.succeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("try")
|
||||
public boolean generate(Buffer buffer, WritableWorld world, Random random, Rotation rotation, int recursions) {
|
||||
try(ProfileFrame ignore = platform.getProfiler().profile("terrascript_recursive:" + id)) {
|
||||
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, world, recursions));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("try")
|
||||
public boolean generate(Vector3 location, WritableWorld world, Random random, Rotation rotation) {
|
||||
@@ -159,11 +138,10 @@ public class StructureScript implements Structure {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("try")
|
||||
public boolean test(Vector3 location, ServerWorld world, Random random, Rotation rotation) {
|
||||
try(ProfileFrame ignore = platform.getProfiler().profile("terrascript_test:" + id)) {
|
||||
StructureBuffer buffer = computeBuffer(location, world, random, rotation);
|
||||
return buffer.succeeded();
|
||||
public boolean generate(Vector3 location, WritableWorld world, Random random, Rotation rotation, int recursions) {
|
||||
try(ProfileFrame ignore = platform.getProfiler().profile("terrascript_direct:" + id)) {
|
||||
DirectBuffer buffer = new DirectBuffer(location, world);
|
||||
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, world, recursions));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.script.StructureScript;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -38,7 +40,7 @@ public class StructureFunction implements Function<Boolean> {
|
||||
private final Position position;
|
||||
private final Platform platform;
|
||||
private final List<Returnable<String>> rotations;
|
||||
|
||||
|
||||
public StructureFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> id,
|
||||
List<Returnable<String>> rotations, Registry<Structure> registry, Position position, Platform platform) {
|
||||
this.registry = registry;
|
||||
@@ -76,14 +78,25 @@ public class StructureFunction implements Function<Boolean> {
|
||||
rotation1 = Rotation.valueOf(rotString);
|
||||
} catch(IllegalArgumentException e) {
|
||||
LOGGER.warn("Invalid rotation {}", rotString);
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3 offset = new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, 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);
|
||||
|
||||
if(script instanceof StructureScript structureScript) {
|
||||
return structureScript.generate(arguments.getBuffer().getOrigin(),
|
||||
arguments.getWorld()
|
||||
.buffer(FastMath.roundToInt(xz.getX()),
|
||||
y.apply(implementationArguments, variableMap).intValue(),
|
||||
FastMath.roundToInt(xz.getZ())),
|
||||
arguments.getRandom(),
|
||||
arguments.getRotation().rotate(rotation1), arguments.getRecursions() + 1);
|
||||
}
|
||||
return script.generate(arguments.getBuffer().getOrigin(),
|
||||
arguments.getWorld()
|
||||
.buffer(FastMath.roundToInt(xz.getX()),
|
||||
y.apply(implementationArguments, variableMap).intValue(),
|
||||
FastMath.roundToInt(xz.getZ())),
|
||||
arguments.getRandom(),
|
||||
arguments.getRotation().rotate(rotation1));
|
||||
}).orElseGet(() -> {
|
||||
LOGGER.error("No such structure {}", app);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user