reimplement structure spawn command

This commit is contained in:
dfsek committed 2020-12-31 16:10:45 -07:00
1 parent aa41cc4d3d
commit 166c0f7dfb
4 files changed
+30 -17

No files matched your search

@@ -1,6 +1,5 @@
package com.dfsek.terra.api.structures.parser.lang.functions.def; 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.parser.lang.functions.Function;
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;
@@ -9,12 +8,14 @@ import com.dfsek.terra.api.structures.tokenizer.Position;
import java.util.Random; import java.util.Random;
public abstract class DefinedFunction<T> implements Function<T> { public abstract class DefinedFunction<T> implements Function<T> {
private final Block block; private final FunctionBlock<T> block;
private final String name; 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.block = block;
this.name = name; this.name = name;
this.position = position;
} }
@Override @Override
@@ -24,11 +25,11 @@ public abstract class DefinedFunction<T> implements Function<T> {
@Override @Override
public T apply(Buffer buffer, Rotation rotation, Random random, int recursions) { public T apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
return null; return block.apply(buffer, rotation, random, recursions);
} }
@Override @Override
public Position getPosition() { 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.List;
import java.util.Random; 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 List<Item<?>> items;
private final Position position; private final Position position;
private final T defaultVal; private final T defaultVal;
@@ -26,15 +26,15 @@ public class FunctionBlock<T> implements Item<Block.ReturnInfo<T>> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @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) { for(Item<?> item : items) {
Object result = item.apply(buffer, rotation, random, recursions); Object result = item.apply(buffer, rotation, random, recursions);
if(result instanceof Block.ReturnInfo) { if(result instanceof Block.ReturnInfo) {
Block.ReturnInfo<T> level = (Block.ReturnInfo<T>) result; 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 @Override
@@ -91,10 +91,12 @@ public class ConfigPack implements LoaderRegistrar {
private final ConfigLoader selfLoader = new ConfigLoader(); private final ConfigLoader selfLoader = new ConfigLoader();
private final Scope varScope = new Scope(); private final Scope varScope = new Scope();
private final CheckCache checkCache;
public ConfigPack(File folder, TerraPlugin main) throws ConfigException { public ConfigPack(File folder, TerraPlugin main) throws ConfigException {
long l = System.nanoTime(); long l = System.nanoTime();
this.checkCache = new CheckCache(main);
floraRegistry = new FloraRegistry(main); floraRegistry = new FloraRegistry(main);
paletteRegistry = new PaletteRegistry(main); paletteRegistry = new PaletteRegistry(main);
treeRegistry = new TreeRegistry(main); treeRegistry = new TreeRegistry(main);
@@ -116,6 +118,7 @@ public class ConfigPack implements LoaderRegistrar {
public ConfigPack(ZipFile file, TerraPlugin main) throws ConfigException { public ConfigPack(ZipFile file, TerraPlugin main) throws ConfigException {
long l = System.nanoTime(); long l = System.nanoTime();
this.checkCache = new CheckCache(main);
floraRegistry = new FloraRegistry(main); floraRegistry = new FloraRegistry(main);
paletteRegistry = new PaletteRegistry(main); paletteRegistry = new PaletteRegistry(main);
treeRegistry = new TreeRegistry(main); treeRegistry = new TreeRegistry(main);
@@ -149,7 +152,6 @@ public class ConfigPack implements LoaderRegistrar {
abstractConfigLoader abstractConfigLoader
.registerLoader(LootTable.class, new LootTableLoader(loader, main)); // These loaders need access to the Loader instance to get files. .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 -> { loader.open("structures/data", ".tesf").then(streams -> streams.forEach(stream -> {
StructureScript structureScript = new StructureScript(stream, main, scriptRegistry, checkCache); StructureScript structureScript = new StructureScript(stream, main, scriptRegistry, checkCache);
scriptRegistry.add(structureScript.getId(), structureScript); scriptRegistry.add(structureScript.getId(), structureScript);
@@ -258,4 +260,8 @@ public class ConfigPack implements LoaderRegistrar {
public BiomeRegistry getBiomeRegistry() { public BiomeRegistry getBiomeRegistry() {
return biomeRegistry; return biomeRegistry;
} }
public CheckCache getCheckCache() {
return checkCache;
}
} }
@@ -1,5 +1,12 @@
package com.dfsek.terra.bukkit.command.command.structure; 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.DebugCommand;
import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.command.WorldCommand;
import org.bukkit.Location; import org.bukkit.Location;
@@ -23,14 +30,13 @@ public class SpawnCommand extends WorldCommand implements DebugCommand {
int x = p.getBlockX(); int x = p.getBlockX();
int y = p.getBlockY(); int y = p.getBlockY();
int z = p.getBlockZ(); int z = p.getBlockZ();
/* Position dummy = new Position(0, 0);
boolean air = StructureSpawnRequirement.AIR.getInstance(world, (TerraBukkitPlugin) getMain()).matches(x, y, z); com.dfsek.terra.api.platform.world.World w = new BukkitWorld(world);
boolean ground = StructureSpawnRequirement.LAND.getInstance(world, (TerraBukkitPlugin) getMain()).matches(x, y, z); 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(
boolean sea = StructureSpawnRequirement.OCEAN.getInstance(world, (TerraBukkitPlugin) getMain()).matches(x, y, z); 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; return true;
} }