mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
reimplement structure spawn command
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.dfsek.terra.api.structures.parser.lang.functions.def;
|
||||
|
||||
import com.dfsek.terra.api.structures.parser.lang.Block;
|
||||
import com.dfsek.terra.api.structures.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
@@ -9,12 +8,14 @@ import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class DefinedFunction<T> implements Function<T> {
|
||||
private final Block block;
|
||||
private final FunctionBlock<T> block;
|
||||
private final String name;
|
||||
private final Position position;
|
||||
|
||||
protected DefinedFunction(Block block, String name) {
|
||||
protected DefinedFunction(FunctionBlock<T> block, String name, Position position) {
|
||||
this.block = block;
|
||||
this.name = name;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -24,11 +25,11 @@ public abstract class DefinedFunction<T> implements Function<T> {
|
||||
|
||||
@Override
|
||||
public T apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return null;
|
||||
return block.apply(buffer, rotation, random, recursions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return null;
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class FunctionBlock<T> implements Item<Block.ReturnInfo<T>> {
|
||||
public class FunctionBlock<T> implements Item<T> {
|
||||
private final List<Item<?>> items;
|
||||
private final Position position;
|
||||
private final T defaultVal;
|
||||
@@ -26,15 +26,15 @@ public class FunctionBlock<T> implements Item<Block.ReturnInfo<T>> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public synchronized Block.ReturnInfo<T> apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
public synchronized T apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
for(Item<?> item : items) {
|
||||
Object result = item.apply(buffer, rotation, random, recursions);
|
||||
if(result instanceof Block.ReturnInfo) {
|
||||
Block.ReturnInfo<T> level = (Block.ReturnInfo<T>) result;
|
||||
if(!level.getLevel().equals(Block.ReturnLevel.NONE)) return level;
|
||||
if(level.getLevel().equals(Block.ReturnLevel.RETURN)) return level.getData();
|
||||
}
|
||||
}
|
||||
return new Block.ReturnInfo<>(Block.ReturnLevel.NONE, defaultVal);
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -91,10 +91,12 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
private final ConfigLoader selfLoader = new ConfigLoader();
|
||||
private final Scope varScope = new Scope();
|
||||
|
||||
private final CheckCache checkCache;
|
||||
|
||||
|
||||
public ConfigPack(File folder, TerraPlugin main) throws ConfigException {
|
||||
long l = System.nanoTime();
|
||||
this.checkCache = new CheckCache(main);
|
||||
floraRegistry = new FloraRegistry(main);
|
||||
paletteRegistry = new PaletteRegistry(main);
|
||||
treeRegistry = new TreeRegistry(main);
|
||||
@@ -116,6 +118,7 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
|
||||
public ConfigPack(ZipFile file, TerraPlugin main) throws ConfigException {
|
||||
long l = System.nanoTime();
|
||||
this.checkCache = new CheckCache(main);
|
||||
floraRegistry = new FloraRegistry(main);
|
||||
paletteRegistry = new PaletteRegistry(main);
|
||||
treeRegistry = new TreeRegistry(main);
|
||||
@@ -149,7 +152,6 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
abstractConfigLoader
|
||||
.registerLoader(LootTable.class, new LootTableLoader(loader, main)); // These loaders need access to the Loader instance to get files.
|
||||
|
||||
CheckCache checkCache = new CheckCache(main);
|
||||
loader.open("structures/data", ".tesf").then(streams -> streams.forEach(stream -> {
|
||||
StructureScript structureScript = new StructureScript(stream, main, scriptRegistry, checkCache);
|
||||
scriptRegistry.add(structureScript.getId(), structureScript);
|
||||
@@ -258,4 +260,8 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
public BiomeRegistry getBiomeRegistry() {
|
||||
return biomeRegistry;
|
||||
}
|
||||
|
||||
public CheckCache getCheckCache() {
|
||||
return checkCache;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package com.dfsek.terra.bukkit.command.command.structure;
|
||||
|
||||
import com.dfsek.terra.api.structures.parser.lang.constants.NumericConstant;
|
||||
import com.dfsek.terra.api.structures.script.functions.CheckFunction;
|
||||
import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.bukkit.BukkitWorld;
|
||||
import com.dfsek.terra.bukkit.command.DebugCommand;
|
||||
import com.dfsek.terra.bukkit.command.WorldCommand;
|
||||
import org.bukkit.Location;
|
||||
@@ -23,14 +30,13 @@ public class SpawnCommand extends WorldCommand implements DebugCommand {
|
||||
int x = p.getBlockX();
|
||||
int y = p.getBlockY();
|
||||
int z = p.getBlockZ();
|
||||
/*
|
||||
boolean air = StructureSpawnRequirement.AIR.getInstance(world, (TerraBukkitPlugin) getMain()).matches(x, y, z);
|
||||
boolean ground = StructureSpawnRequirement.LAND.getInstance(world, (TerraBukkitPlugin) getMain()).matches(x, y, z);
|
||||
boolean sea = StructureSpawnRequirement.OCEAN.getInstance(world, (TerraBukkitPlugin) getMain()).matches(x, y, z);
|
||||
Position dummy = new Position(0, 0);
|
||||
com.dfsek.terra.api.platform.world.World w = new BukkitWorld(world);
|
||||
String check = new CheckFunction(getMain(), new NumericConstant(0, dummy), new NumericConstant(0, dummy), new NumericConstant(0, dummy), getMain().getWorld(w).getConfig().getCheckCache(), dummy).apply(new StructureBuffer(
|
||||
new com.dfsek.terra.api.math.vector.Location(w, x, y, z)
|
||||
), Rotation.NONE, new FastRandom(), 0);
|
||||
|
||||
sender.sendMessage("AIR: " + air + "\nLAND: " + ground + "\nOCEAN: " + sea);
|
||||
|
||||
*/
|
||||
sender.sendMessage("Found: " + check);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user