mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-08 16:56:07 +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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user