fix Marks

This commit is contained in:
dfsek 2021-01-05 22:14:40 -07:00
parent 47cad8a30b
commit 44176f7ee6
20 changed files with 45 additions and 61 deletions

View File

@ -106,6 +106,11 @@ public class Location implements Cloneable {
return this;
}
public Location add(Location add) {
vector.add(add.toVector());
return this;
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof Location)) {

View File

@ -14,10 +14,10 @@ import com.dfsek.terra.api.structures.script.builders.CheckFunctionBuilder;
import com.dfsek.terra.api.structures.script.builders.EntityFunctionBuilder;
import com.dfsek.terra.api.structures.script.builders.GetMarkFunctionBuilder;
import com.dfsek.terra.api.structures.script.builders.LootFunctionBuilder;
import com.dfsek.terra.api.structures.script.builders.MarkFunctionBuilder;
import com.dfsek.terra.api.structures.script.builders.PullFunctionBuilder;
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.SetMarkFunctionBuilder;
import com.dfsek.terra.api.structures.script.builders.StateFunctionBuilder;
import com.dfsek.terra.api.structures.script.builders.StructureFunctionBuilder;
import com.dfsek.terra.api.structures.script.builders.UnaryNumberFunctionBuilder;
@ -58,7 +58,7 @@ public class StructureScript {
.registerFunction("structure", new StructureFunctionBuilder(registry, main))
.registerFunction("randomInt", new RandomFunctionBuilder())
.registerFunction("recursions", new RecursionsFunctionBuilder())
.registerFunction("setMark", new MarkFunctionBuilder())
.registerFunction("setMark", new SetMarkFunctionBuilder())
.registerFunction("getMark", new GetMarkFunctionBuilder())
.registerFunction("pull", new PullFunctionBuilder(main))
.registerFunction("loot", new LootFunctionBuilder(main, lootRegistry))

View File

@ -1,6 +1,5 @@
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;
@ -15,7 +14,7 @@ public class GetMarkFunctionBuilder implements FunctionBuilder<GetMarkFunction>
@SuppressWarnings("unchecked")
@Override
public GetMarkFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException {
public GetMarkFunction build(List<Returnable<?>> argumentList, Position position) {
return new GetMarkFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), (Returnable<Number>) argumentList.get(2), position);
}

View File

@ -3,20 +3,20 @@ 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.script.functions.SetMarkFunction;
import com.dfsek.terra.api.structures.tokenizer.Position;
import java.util.List;
public class MarkFunctionBuilder implements FunctionBuilder<MarkFunction> {
public class SetMarkFunctionBuilder implements FunctionBuilder<SetMarkFunction> {
public MarkFunctionBuilder() {
public SetMarkFunctionBuilder() {
}
@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);
public SetMarkFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException {
return new SetMarkFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), (Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), position);
}
@Override

View File

@ -45,7 +45,7 @@ public class UnaryStringFunctionBuilder implements FunctionBuilder<Function<Void
@Override
public Returnable.ReturnType getArgument(int position) {
if(position == 0) return Returnable.ReturnType.NUMBER;
if(position == 0) return Returnable.ReturnType.STRING;
return null;
}
}

View File

@ -35,12 +35,14 @@ public class BlockFunction implements Function<Void> {
@Override
public Void apply(ImplementationArguments implementationArguments) {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
BlockData rot = data.clone();
Vector2 xz = new Vector2(x.apply(implementationArguments).doubleValue(), z.apply(implementationArguments).doubleValue());
RotationUtil.rotateVector(xz, arguments.getRotation());
BlockData rot = data.clone();
RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse());
arguments.getBuffer().addItem(new BufferedBlock(rot, overwrite.apply(implementationArguments)), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ())));
arguments.getBuffer().addItem(new BufferedBlock(rot, overwrite.apply(implementationArguments)), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).doubleValue(), FastMath.roundToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld()));
return null;
}

View File

@ -30,7 +30,7 @@ public class CheckBlockFunction implements Function<String> {
RotationUtil.rotateVector(xz, arguments.getRotation());
String data = arguments.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ()))).getBlock().getBlockData().getAsString();
String data = arguments.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).doubleValue(), FastMath.roundToInt(xz.getZ()))).getBlock().getBlockData().getAsString();
if(data.contains("[")) return data.substring(0, data.indexOf('[')); // Strip properties
else return data;
}

View File

@ -43,7 +43,7 @@ public class CheckFunction implements Function<String> {
RotationUtil.rotateVector(xz, arguments.getRotation());
Location location = arguments.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ())));
Location location = arguments.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).doubleValue(), FastMath.roundToInt(xz.getZ())));
return apply(location, arguments.getBuffer().getOrigin().getWorld());
}

View File

@ -37,7 +37,7 @@ public class EntityFunction implements Function<Void> {
RotationUtil.rotateVector(xz, arguments.getRotation());
arguments.getBuffer().addItem(new BufferedEntity(data), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ())));
arguments.getBuffer().addItem(new BufferedEntity(data), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld()));
return null;
}

View File

@ -7,7 +7,6 @@ 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.script.TerraImplementationArguments;
import com.dfsek.terra.api.structures.structure.RotationUtil;
import com.dfsek.terra.api.structures.structure.buffer.items.Mark;
import com.dfsek.terra.api.structures.tokenizer.Position;
import net.jafama.FastMath;
@ -28,8 +27,8 @@ public class GetMarkFunction implements Function<String> {
Vector2 xz = new Vector2(x.apply(implementationArguments).doubleValue(), z.apply(implementationArguments).doubleValue());
RotationUtil.rotateVector(xz, arguments.getRotation());
Mark mark = arguments.getBuffer().getMark(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ())));
return mark == null ? "" : mark.getContent();
String mark = arguments.getBuffer().getMark(new Vector3(FastMath.floorToInt(xz.getX()), FastMath.floorToInt(y.apply(implementationArguments).doubleValue()), FastMath.floorToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld()));
return mark == null ? "" : mark;
}
@Override
@ -39,6 +38,6 @@ public class GetMarkFunction implements Function<String> {
@Override
public ReturnType returnType() {
return ReturnType.VOID;
return ReturnType.STRING;
}
}

View File

@ -46,7 +46,7 @@ public class LootFunction implements Function<Void> {
return null;
}
arguments.getBuffer().addItem(new BufferedLootApplication(table, main), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ())));
arguments.getBuffer().addItem(new BufferedLootApplication(table, main), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld()));
return null;
}

View File

@ -38,7 +38,7 @@ public class PullFunction implements Function<Void> {
RotationUtil.rotateVector(xz, arguments.getRotation());
BlockData rot = data.clone();
RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse());
arguments.getBuffer().addItem(new BufferedPulledBlock(rot), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ())));
arguments.getBuffer().addItem(new BufferedPulledBlock(rot), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld()));
return null;
}

View File

@ -2,22 +2,20 @@ 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.ImplementationArguments;
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.script.TerraImplementationArguments;
import com.dfsek.terra.api.structures.structure.RotationUtil;
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> {
public class SetMarkFunction 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 {
public SetMarkFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> mark, Position position) {
this.position = position;
this.mark = mark;
this.x = x;
@ -32,7 +30,7 @@ public class MarkFunction implements Function<Void> {
RotationUtil.rotateVector(xz, arguments.getRotation());
arguments.getBuffer().setMark(new Mark(mark.apply(implementationArguments)), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ())));
arguments.getBuffer().setMark(mark.apply(implementationArguments), new Vector3(FastMath.floorToInt(xz.getX()), FastMath.floorToInt(y.apply(implementationArguments).doubleValue()), FastMath.floorToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld()));
return null;
}

View File

@ -33,7 +33,7 @@ public class StateFunction implements Function<Void> {
Vector2 xz = new Vector2(x.apply(implementationArguments).doubleValue(), z.apply(implementationArguments).doubleValue());
RotationUtil.rotateVector(xz, arguments.getRotation());
arguments.getBuffer().addItem(new BufferedStateManipulator(main, data.apply(implementationArguments)), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ())));
arguments.getBuffer().addItem(new BufferedStateManipulator(main, data.apply(implementationArguments)), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld()));
return null;
}

View File

@ -65,7 +65,7 @@ public class StructureFunction implements Function<Boolean> {
return null;
}
Vector3 offset = new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ()));
Vector3 offset = new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).doubleValue(), FastMath.roundToInt(xz.getZ()));
return script.executeInBuffer(new IntermediateBuffer(arguments.getBuffer(), offset), arguments.getRandom(), arguments.getRotation().rotate(rotation1), arguments.getRecursions() + 1);
}

View File

@ -1,16 +1,14 @@
package com.dfsek.terra.api.structures.structure.buffer;
import com.dfsek.terra.api.math.vector.Location;
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 {
Buffer addItem(BufferedItem item, Vector3 location);
Buffer addItem(BufferedItem item, Location location);
Location getOrigin();
Mark getMark(Vector3 location);
String getMark(Location location);
Buffer setMark(Mark mark, Vector3 location);
Buffer setMark(String mark, Location location);
}

View File

@ -2,14 +2,13 @@ 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;
private String mark = null;
@Override
@ -21,11 +20,11 @@ public class Cell implements BufferedItem {
items.add(item);
}
public Mark getMark() {
public String getMark() {
return mark;
}
public void setMark(Mark mark) {
public void setMark(String mark) {
this.mark = mark;
}
}

View File

@ -3,7 +3,6 @@ package com.dfsek.terra.api.structures.structure.buffer;
import com.dfsek.terra.api.math.vector.Location;
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 {
private final Buffer original;
@ -11,11 +10,11 @@ public class IntermediateBuffer implements Buffer {
public IntermediateBuffer(Buffer original, Vector3 offset) {
this.original = original;
this.offset = offset;
this.offset = offset.clone();
}
@Override
public Buffer addItem(BufferedItem item, Vector3 location) {
public Buffer addItem(BufferedItem item, Location location) {
return original.addItem(item, location.add(offset));
}
@ -25,12 +24,12 @@ public class IntermediateBuffer implements Buffer {
}
@Override
public Mark getMark(Vector3 location) {
public String getMark(Location location) {
return original.getMark(location.add(offset));
}
@Override
public Buffer setMark(Mark mark, Vector3 location) {
public Buffer setMark(String mark, Location location) {
original.setMark(mark, location.add(offset));
return this;
}

View File

@ -1,17 +1,15 @@
package com.dfsek.terra.api.structures.structure.buffer;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedItem;
import com.dfsek.terra.api.structures.structure.buffer.items.Mark;
import net.jafama.FastMath;
import java.util.LinkedHashMap;
import java.util.Map;
public class StructureBuffer implements Buffer {
private final Map<Vector3, Cell> bufferedItemMap = new LinkedHashMap<>();
private final Map<Location, Cell> bufferedItemMap = new LinkedHashMap<>();
private final Location origin;
private boolean succeeded;
@ -33,13 +31,13 @@ public class StructureBuffer implements Buffer {
}
@Override
public Buffer addItem(BufferedItem item, Vector3 location) {
public Buffer addItem(BufferedItem item, Location location) {
bufferedItemMap.computeIfAbsent(location, l -> new Cell()).add(item);
return this;
}
@Override
public Mark getMark(Vector3 location) {
public String getMark(Location location) {
Cell cell = bufferedItemMap.get(location);
if(cell != null) {
return cell.getMark();
@ -48,7 +46,7 @@ public class StructureBuffer implements Buffer {
}
@Override
public Buffer setMark(Mark mark, Vector3 location) {
public Buffer setMark(String mark, Location location) {
bufferedItemMap.computeIfAbsent(location, l -> new Cell()).setMark(mark);
return this;
}

View File

@ -1,13 +0,0 @@
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;
}
}