mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-14 12:51:20 +00:00
reimplement structure spawn command
This commit is contained in:
+6
-5
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user