mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 05:50:08 +00:00
implement Marks
This commit is contained in:
1 parent
a04bcf5b23
commit
4b5013231c
13 files changed
+275
-8
No files matched your search
@@ -7,6 +7,8 @@ import com.dfsek.terra.api.structures.parser.exceptions.ParseException;
|
|||||||
import com.dfsek.terra.api.structures.parser.lang.Block;
|
import com.dfsek.terra.api.structures.parser.lang.Block;
|
||||||
import com.dfsek.terra.api.structures.script.builders.BlockFunctionBuilder;
|
import com.dfsek.terra.api.structures.script.builders.BlockFunctionBuilder;
|
||||||
import com.dfsek.terra.api.structures.script.builders.CheckFunctionBuilder;
|
import com.dfsek.terra.api.structures.script.builders.CheckFunctionBuilder;
|
||||||
|
import com.dfsek.terra.api.structures.script.builders.GetMarkFunctionBuilder;
|
||||||
|
import com.dfsek.terra.api.structures.script.builders.MarkFunctionBuilder;
|
||||||
import com.dfsek.terra.api.structures.script.builders.RandomFunctionBuilder;
|
import com.dfsek.terra.api.structures.script.builders.RandomFunctionBuilder;
|
||||||
import com.dfsek.terra.api.structures.script.builders.RecursionsFunctionBuilder;
|
import com.dfsek.terra.api.structures.script.builders.RecursionsFunctionBuilder;
|
||||||
import com.dfsek.terra.api.structures.script.builders.StructureFunctionBuilder;
|
import com.dfsek.terra.api.structures.script.builders.StructureFunctionBuilder;
|
||||||
@@ -34,7 +36,9 @@ public class StructureScript {
|
|||||||
.addFunction("check", new CheckFunctionBuilder(main))
|
.addFunction("check", new CheckFunctionBuilder(main))
|
||||||
.addFunction("structure", new StructureFunctionBuilder(registry, main))
|
.addFunction("structure", new StructureFunctionBuilder(registry, main))
|
||||||
.addFunction("randomInt", new RandomFunctionBuilder())
|
.addFunction("randomInt", new RandomFunctionBuilder())
|
||||||
.addFunction("recursions", new RecursionsFunctionBuilder());
|
.addFunction("recursions", new RecursionsFunctionBuilder())
|
||||||
|
.addFunction("setMark", new MarkFunctionBuilder())
|
||||||
|
.addFunction("getMark", new GetMarkFunctionBuilder());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
block = parser.parse();
|
block = parser.parse();
|
||||||
|
|||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package com.dfsek.terra.api.structures.script.builders;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.structures.parser.exceptions.ParseException;
|
||||||
|
import com.dfsek.terra.api.structures.parser.lang.Returnable;
|
||||||
|
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
|
||||||
|
import com.dfsek.terra.api.structures.script.functions.GetMarkFunction;
|
||||||
|
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GetMarkFunctionBuilder implements FunctionBuilder<GetMarkFunction> {
|
||||||
|
|
||||||
|
public GetMarkFunctionBuilder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public GetMarkFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException {
|
||||||
|
return new GetMarkFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), (Returnable<Number>) argumentList.get(2), position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int argNumber() {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Returnable.ReturnType getArgument(int position) {
|
||||||
|
switch(position) {
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
return Returnable.ReturnType.NUMBER;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
package com.dfsek.terra.api.structures.script.builders;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.structures.parser.exceptions.ParseException;
|
||||||
|
import com.dfsek.terra.api.structures.parser.lang.Returnable;
|
||||||
|
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
|
||||||
|
import com.dfsek.terra.api.structures.script.functions.MarkFunction;
|
||||||
|
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MarkFunctionBuilder implements FunctionBuilder<MarkFunction> {
|
||||||
|
|
||||||
|
public MarkFunctionBuilder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public MarkFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException {
|
||||||
|
return new MarkFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), (Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int argNumber() {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Returnable.ReturnType getArgument(int position) {
|
||||||
|
switch(position) {
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
return Returnable.ReturnType.NUMBER;
|
||||||
|
case 3:
|
||||||
|
return Returnable.ReturnType.STRING;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-3
@@ -11,7 +11,7 @@ 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.RotationUtil;
|
import com.dfsek.terra.api.structures.structure.RotationUtil;
|
||||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||||
import com.dfsek.terra.api.structures.structure.buffer.BufferedBlock;
|
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedBlock;
|
||||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||||
import net.jafama.FastMath;
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
@@ -40,8 +40,9 @@ public class BlockFunction implements Function<Void> {
|
|||||||
Vector2 xz = new Vector2(x.apply(buffer, rotation, recursions).doubleValue(), z.apply(buffer, rotation, recursions).doubleValue());
|
Vector2 xz = new Vector2(x.apply(buffer, rotation, recursions).doubleValue(), z.apply(buffer, rotation, recursions).doubleValue());
|
||||||
|
|
||||||
RotationUtil.rotateVector(xz, rotation);
|
RotationUtil.rotateVector(xz, rotation);
|
||||||
|
BlockData rot = data.clone();
|
||||||
buffer.addItem(new BufferedBlock(data), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(buffer, rotation, recursions).intValue(), FastMath.roundToInt(xz.getZ())));
|
RotationUtil.rotateBlockData(rot, rotation.inverse());
|
||||||
|
buffer.addItem(new BufferedBlock(rot), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(buffer, rotation, recursions).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
package com.dfsek.terra.api.structures.script.functions;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.math.vector.Vector2;
|
||||||
|
import com.dfsek.terra.api.math.vector.Vector3;
|
||||||
|
import com.dfsek.terra.api.structures.parser.exceptions.ParseException;
|
||||||
|
import com.dfsek.terra.api.structures.parser.lang.Returnable;
|
||||||
|
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.RotationUtil;
|
||||||
|
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||||
|
import com.dfsek.terra.api.structures.structure.buffer.items.Mark;
|
||||||
|
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||||
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
|
public class GetMarkFunction implements Function<String> {
|
||||||
|
private final Returnable<Number> x, y, z;
|
||||||
|
private final Position position;
|
||||||
|
|
||||||
|
public GetMarkFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Position position) throws ParseException {
|
||||||
|
this.position = position;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "block";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||||
|
Vector2 xz = new Vector2(x.apply(buffer, rotation, recursions).doubleValue(), z.apply(buffer, rotation, recursions).doubleValue());
|
||||||
|
|
||||||
|
RotationUtil.rotateVector(xz, rotation);
|
||||||
|
Mark mark = buffer.getMark(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(buffer, rotation, recursions).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||||
|
return mark == null ? "" : mark.getContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Position getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReturnType returnType() {
|
||||||
|
return ReturnType.VOID;
|
||||||
|
}
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package com.dfsek.terra.api.structures.script.functions;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.math.vector.Vector2;
|
||||||
|
import com.dfsek.terra.api.math.vector.Vector3;
|
||||||
|
import com.dfsek.terra.api.structures.parser.exceptions.ParseException;
|
||||||
|
import com.dfsek.terra.api.structures.parser.lang.Returnable;
|
||||||
|
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.RotationUtil;
|
||||||
|
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||||
|
import com.dfsek.terra.api.structures.structure.buffer.items.Mark;
|
||||||
|
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||||
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
|
public class MarkFunction implements Function<Void> {
|
||||||
|
private final Returnable<Number> x, y, z;
|
||||||
|
private final Position position;
|
||||||
|
private final Returnable<String> mark;
|
||||||
|
|
||||||
|
public MarkFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> mark, Position position) throws ParseException {
|
||||||
|
this.position = position;
|
||||||
|
this.mark = mark;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "block";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||||
|
Vector2 xz = new Vector2(x.apply(buffer, rotation, recursions).doubleValue(), z.apply(buffer, rotation, recursions).doubleValue());
|
||||||
|
|
||||||
|
RotationUtil.rotateVector(xz, rotation);
|
||||||
|
|
||||||
|
buffer.setMark(new Mark(mark.apply(buffer, rotation, recursions)), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(buffer, rotation, recursions).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Position getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReturnType returnType() {
|
||||||
|
return ReturnType.VOID;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,15 @@ package com.dfsek.terra.api.structures.structure.buffer;
|
|||||||
|
|
||||||
import com.dfsek.terra.api.math.vector.Location;
|
import com.dfsek.terra.api.math.vector.Location;
|
||||||
import com.dfsek.terra.api.math.vector.Vector3;
|
import com.dfsek.terra.api.math.vector.Vector3;
|
||||||
|
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedItem;
|
||||||
|
import com.dfsek.terra.api.structures.structure.buffer.items.Mark;
|
||||||
|
|
||||||
public interface Buffer {
|
public interface Buffer {
|
||||||
Buffer addItem(BufferedItem item, Vector3 location);
|
Buffer addItem(BufferedItem item, Vector3 location);
|
||||||
|
|
||||||
Location getOrigin();
|
Location getOrigin();
|
||||||
|
|
||||||
|
Mark getMark(Vector3 location);
|
||||||
|
|
||||||
|
Buffer setMark(Mark mark, Vector3 location);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.dfsek.terra.api.structures.structure.buffer;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.math.vector.Location;
|
||||||
|
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedItem;
|
||||||
|
import com.dfsek.terra.api.structures.structure.buffer.items.Mark;
|
||||||
|
import com.dfsek.terra.api.util.GlueList;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Cell implements BufferedItem {
|
||||||
|
private final List<BufferedItem> items = new GlueList<>();
|
||||||
|
private Mark mark = null;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paste(Location origin) {
|
||||||
|
items.forEach(item -> item.paste(origin));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(BufferedItem item) {
|
||||||
|
items.add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mark getMark() {
|
||||||
|
return mark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMark(Mark mark) {
|
||||||
|
this.mark = mark;
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
@@ -2,6 +2,8 @@ package com.dfsek.terra.api.structures.structure.buffer;
|
|||||||
|
|
||||||
import com.dfsek.terra.api.math.vector.Location;
|
import com.dfsek.terra.api.math.vector.Location;
|
||||||
import com.dfsek.terra.api.math.vector.Vector3;
|
import com.dfsek.terra.api.math.vector.Vector3;
|
||||||
|
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedItem;
|
||||||
|
import com.dfsek.terra.api.structures.structure.buffer.items.Mark;
|
||||||
|
|
||||||
public class IntermediateBuffer implements Buffer {
|
public class IntermediateBuffer implements Buffer {
|
||||||
private final Buffer original;
|
private final Buffer original;
|
||||||
@@ -21,4 +23,15 @@ public class IntermediateBuffer implements Buffer {
|
|||||||
public Location getOrigin() {
|
public Location getOrigin() {
|
||||||
return original.getOrigin().add(offset);
|
return original.getOrigin().add(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mark getMark(Vector3 location) {
|
||||||
|
return original.getMark(location.add(offset));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Buffer setMark(Mark mark, Vector3 location) {
|
||||||
|
original.setMark(mark, location.add(offset));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+22
-2
@@ -2,12 +2,14 @@ package com.dfsek.terra.api.structures.structure.buffer;
|
|||||||
|
|
||||||
import com.dfsek.terra.api.math.vector.Location;
|
import com.dfsek.terra.api.math.vector.Location;
|
||||||
import com.dfsek.terra.api.math.vector.Vector3;
|
import com.dfsek.terra.api.math.vector.Vector3;
|
||||||
|
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedItem;
|
||||||
|
import com.dfsek.terra.api.structures.structure.buffer.items.Mark;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class StructureBuffer implements Buffer {
|
public class StructureBuffer implements Buffer {
|
||||||
private final Map<Vector3, BufferedItem> bufferedItemMap = new HashMap<>();
|
private final Map<Vector3, Cell> bufferedItemMap = new HashMap<>();
|
||||||
private final Location origin;
|
private final Location origin;
|
||||||
|
|
||||||
public StructureBuffer(Location origin) {
|
public StructureBuffer(Location origin) {
|
||||||
@@ -22,10 +24,28 @@ public class StructureBuffer implements Buffer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Buffer addItem(BufferedItem item, Vector3 location) {
|
public Buffer addItem(BufferedItem item, Vector3 location) {
|
||||||
bufferedItemMap.put(location, item);
|
bufferedItemMap.putIfAbsent(location, new Cell());
|
||||||
|
bufferedItemMap.get(location).add(item);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mark getMark(Vector3 location) {
|
||||||
|
Cell cell = bufferedItemMap.get(location);
|
||||||
|
if(cell != null) {
|
||||||
|
return cell.getMark();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Buffer setMark(Mark mark, Vector3 location) {
|
||||||
|
bufferedItemMap.putIfAbsent(location, new Cell());
|
||||||
|
bufferedItemMap.get(location).setMark(mark);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Location getOrigin() {
|
public Location getOrigin() {
|
||||||
return origin;
|
return origin;
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.dfsek.terra.api.structures.structure.buffer;
|
package com.dfsek.terra.api.structures.structure.buffer.items;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.vector.Location;
|
import com.dfsek.terra.api.math.vector.Location;
|
||||||
import com.dfsek.terra.api.platform.block.BlockData;
|
import com.dfsek.terra.api.platform.block.BlockData;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.dfsek.terra.api.structures.structure.buffer;
|
package com.dfsek.terra.api.structures.structure.buffer.items;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.vector.Location;
|
import com.dfsek.terra.api.math.vector.Location;
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.dfsek.terra.api.structures.structure.buffer.items;
|
||||||
|
|
||||||
|
public class Mark {
|
||||||
|
private final String content;
|
||||||
|
|
||||||
|
public Mark(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user