mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-14 12:51:20 +00:00
pass random to structure gen
This commit is contained in:
@@ -5,6 +5,7 @@ import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class Block implements Item<Block.ReturnLevel> {
|
||||
private final List<Item<?>> items;
|
||||
@@ -20,9 +21,9 @@ public class Block implements Item<Block.ReturnLevel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized ReturnLevel apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
public synchronized ReturnLevel apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
for(Item<?> item : items) {
|
||||
Object result = item.apply(buffer, rotation, recursions);
|
||||
Object result = item.apply(buffer, rotation, random, recursions);
|
||||
if(result instanceof ReturnLevel) {
|
||||
ReturnLevel level = (ReturnLevel) result;
|
||||
if(!level.equals(ReturnLevel.NONE)) return level;
|
||||
|
||||
@@ -4,8 +4,10 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public interface Item<T> {
|
||||
T apply(Buffer buffer, Rotation rotation, int recursions);
|
||||
T apply(Buffer buffer, Rotation rotation, Random random, int recursions);
|
||||
|
||||
Position getPosition();
|
||||
}
|
||||
|
||||
+3
-1
@@ -5,6 +5,8 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class ConstantExpression<T> implements Returnable<T> {
|
||||
private final T constant;
|
||||
private final Position position;
|
||||
@@ -15,7 +17,7 @@ public abstract class ConstantExpression<T> implements Returnable<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public T apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
public T apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return constant;
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -6,6 +6,8 @@ import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class AbsFunction extends MathFunction {
|
||||
private final Returnable<Number> returnable;
|
||||
|
||||
@@ -20,7 +22,7 @@ public class AbsFunction extends MathFunction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
return FastMath.abs(returnable.apply(buffer, rotation, recursions).doubleValue());
|
||||
public Number apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return FastMath.abs(returnable.apply(buffer, rotation, random, recursions).doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -6,6 +6,8 @@ import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class PowFunction extends MathFunction {
|
||||
private final Returnable<Number> base;
|
||||
private final Returnable<Number> power;
|
||||
@@ -22,7 +24,7 @@ public class PowFunction extends MathFunction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
return FastMath.pow(base.apply(buffer, rotation, recursions).doubleValue(), power.apply(buffer, rotation, recursions).doubleValue());
|
||||
public Number apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return FastMath.pow(base.apply(buffer, rotation, random, recursions).doubleValue(), power.apply(buffer, rotation, random, recursions).doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -6,6 +6,8 @@ import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class SqrtFunction extends MathFunction {
|
||||
private final Returnable<Number> returnable;
|
||||
|
||||
@@ -20,7 +22,7 @@ public class SqrtFunction extends MathFunction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
return FastMath.sqrt(returnable.apply(buffer, rotation, recursions).doubleValue());
|
||||
public Number apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return FastMath.sqrt(returnable.apply(buffer, rotation, random, recursions).doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -6,6 +6,8 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BreakKeyword implements Keyword<Block.ReturnLevel> {
|
||||
private final Position position;
|
||||
|
||||
@@ -14,7 +16,7 @@ public class BreakKeyword implements Keyword<Block.ReturnLevel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return Block.ReturnLevel.BREAK;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -6,6 +6,8 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class ContinueKeyword implements Keyword<Block.ReturnLevel> {
|
||||
private final Position position;
|
||||
|
||||
@@ -14,7 +16,7 @@ public class ContinueKeyword implements Keyword<Block.ReturnLevel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return Block.ReturnLevel.CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -6,6 +6,8 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class FailKeyword implements Keyword<Block.ReturnLevel> {
|
||||
private final Position position;
|
||||
|
||||
@@ -14,7 +16,7 @@ public class FailKeyword implements Keyword<Block.ReturnLevel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return Block.ReturnLevel.FAIL;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -6,6 +6,8 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class ReturnKeyword implements Keyword<Block.ReturnLevel> {
|
||||
private final Position position;
|
||||
|
||||
@@ -14,7 +16,7 @@ public class ReturnKeyword implements Keyword<Block.ReturnLevel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return Block.ReturnLevel.RETURN;
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -8,6 +8,8 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class ForKeyword implements Keyword<Block.ReturnLevel> {
|
||||
private final Block conditional;
|
||||
private final Item<?> initializer;
|
||||
@@ -24,9 +26,9 @@ public class ForKeyword implements Keyword<Block.ReturnLevel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
for(initializer.apply(buffer, rotation, recursions); statement.apply(buffer, rotation, recursions); incrementer.apply(buffer, rotation, recursions)) {
|
||||
Block.ReturnLevel level = conditional.apply(buffer, rotation, recursions);
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
for(initializer.apply(buffer, rotation, random, recursions); statement.apply(buffer, rotation, random, recursions); incrementer.apply(buffer, rotation, random, recursions)) {
|
||||
Block.ReturnLevel level = conditional.apply(buffer, rotation, random, recursions);
|
||||
if(level.equals(Block.ReturnLevel.BREAK)) break;
|
||||
if(level.isReturnFast()) return level;
|
||||
}
|
||||
|
||||
+4
-2
@@ -7,6 +7,8 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class IfKeyword implements Keyword<Block.ReturnLevel> {
|
||||
private final Block conditional;
|
||||
private final Returnable<Boolean> statement;
|
||||
@@ -19,8 +21,8 @@ public class IfKeyword implements Keyword<Block.ReturnLevel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
if(statement.apply(buffer, rotation, recursions)) return conditional.apply(buffer, rotation, recursions);
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
if(statement.apply(buffer, rotation, random, recursions)) return conditional.apply(buffer, rotation, random, recursions);
|
||||
return Block.ReturnLevel.NONE;
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -7,6 +7,8 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class WhileKeyword implements Keyword<Block.ReturnLevel> {
|
||||
private final Block conditional;
|
||||
private final Returnable<Boolean> statement;
|
||||
@@ -19,9 +21,9 @@ public class WhileKeyword implements Keyword<Block.ReturnLevel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
while(statement.apply(buffer, rotation, recursions)) {
|
||||
Block.ReturnLevel level = conditional.apply(buffer, rotation, recursions);
|
||||
public Block.ReturnLevel apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
while(statement.apply(buffer, rotation, random, recursions)) {
|
||||
Block.ReturnLevel level = conditional.apply(buffer, rotation, random, recursions);
|
||||
if(level.equals(Block.ReturnLevel.BREAK)) break;
|
||||
if(level.isReturnFast()) return level;
|
||||
}
|
||||
|
||||
+4
-2
@@ -5,6 +5,8 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class BinaryOperation<I, O> implements Returnable<O> {
|
||||
private final Returnable<I> left;
|
||||
private final Returnable<I> right;
|
||||
@@ -24,7 +26,7 @@ public abstract class BinaryOperation<I, O> implements Returnable<O> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public O apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
return apply(left.apply(buffer, rotation, recursions), right.apply(buffer, rotation, recursions));
|
||||
public O apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return apply(left.apply(buffer, rotation, random, recursions), right.apply(buffer, rotation, random, recursions));
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -5,6 +5,8 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class UnaryOperation<T> implements Returnable<T> {
|
||||
private final Returnable<T> input;
|
||||
private final Position position;
|
||||
@@ -17,8 +19,8 @@ public abstract class UnaryOperation<T> implements Returnable<T> {
|
||||
public abstract T apply(T input);
|
||||
|
||||
@Override
|
||||
public T apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
return apply(input.apply(buffer, rotation, recursions));
|
||||
public T apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return apply(input.apply(buffer, rotation, random, recursions));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-2
@@ -6,6 +6,8 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Assignment<T> implements Item<T> {
|
||||
private final Variable<T> delegate;
|
||||
private final Returnable<T> value;
|
||||
@@ -18,8 +20,8 @@ public class Assignment<T> implements Item<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized T apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
T val = value.apply(buffer, rotation, recursions);
|
||||
public synchronized T apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
T val = value.apply(buffer, rotation, random, recursions);
|
||||
delegate.setValue(val);
|
||||
return val;
|
||||
}
|
||||
|
||||
+3
-1
@@ -5,6 +5,8 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Getter implements Returnable<Object> {
|
||||
private final Variable<?> delegate;
|
||||
|
||||
@@ -18,7 +20,7 @@ public class Getter implements Returnable<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Object apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
public synchronized Object apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return delegate.getValue();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Random;
|
||||
|
||||
public class StructureScript {
|
||||
private final Block block;
|
||||
@@ -57,15 +58,15 @@ public class StructureScript {
|
||||
* @param rotation Rotation of structure
|
||||
* @return Whether generation was successful
|
||||
*/
|
||||
public boolean execute(Location location, Rotation rotation) {
|
||||
public boolean execute(Location location, Random random, Rotation rotation) {
|
||||
StructureBuffer buffer = new StructureBuffer(location);
|
||||
Block.ReturnLevel level = block.apply(buffer, rotation, 0);
|
||||
Block.ReturnLevel level = block.apply(buffer, rotation, random, 0);
|
||||
buffer.paste();
|
||||
return !level.equals(Block.ReturnLevel.FAIL);
|
||||
}
|
||||
|
||||
public void executeInBuffer(Buffer buffer, Rotation rotation, int recursions) {
|
||||
block.apply(buffer, rotation, recursions);
|
||||
public void executeInBuffer(Buffer buffer, Random random, Rotation rotation, int recursions) {
|
||||
block.apply(buffer, rotation, random, recursions);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
||||
+5
-3
@@ -15,6 +15,8 @@ import com.dfsek.terra.api.structures.structure.buffer.items.BufferedBlock;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockFunction implements Function<Void> {
|
||||
private final BlockData data;
|
||||
private final Returnable<Number> x, y, z;
|
||||
@@ -36,13 +38,13 @@ public class BlockFunction implements Function<Void> {
|
||||
}
|
||||
|
||||
@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());
|
||||
public Void apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
Vector2 xz = new Vector2(x.apply(buffer, rotation, random, recursions).doubleValue(), z.apply(buffer, rotation, random, recursions).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, rotation);
|
||||
BlockData rot = data.clone();
|
||||
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())));
|
||||
buffer.addItem(new BufferedBlock(rot), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(buffer, rotation, random, recursions).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+9
-7
@@ -15,6 +15,8 @@ import com.dfsek.terra.api.structures.world.LandCheck;
|
||||
import com.dfsek.terra.api.structures.world.OceanCheck;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class CheckFunction implements Function<String> {
|
||||
private final TerraPlugin main;
|
||||
private final Returnable<Number> x, y, z;
|
||||
@@ -33,17 +35,17 @@ public class CheckFunction implements Function<String> {
|
||||
return "check";
|
||||
}
|
||||
|
||||
private Location getVector(Buffer buffer, Rotation rotation, int recursions) {
|
||||
Vector2 xz = new Vector2(x.apply(buffer, rotation, recursions).doubleValue(), z.apply(buffer, rotation, recursions).doubleValue());
|
||||
|
||||
@Override
|
||||
public String apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
|
||||
Vector2 xz = new Vector2(x.apply(buffer, rotation, random, recursions).doubleValue(), z.apply(buffer, rotation, random, recursions).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, rotation);
|
||||
|
||||
return buffer.getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(buffer, rotation, recursions).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||
}
|
||||
Location location = buffer.getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(buffer, rotation, random, recursions).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||
|
||||
@Override
|
||||
public String apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
return apply(getVector(buffer, rotation, recursions), buffer.getOrigin().getWorld());
|
||||
return apply(location, buffer.getOrigin().getWorld());
|
||||
}
|
||||
|
||||
private String apply(Location vector, World world) {
|
||||
|
||||
+5
-3
@@ -12,6 +12,8 @@ import com.dfsek.terra.api.structures.structure.buffer.items.Mark;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class GetMarkFunction implements Function<String> {
|
||||
private final Returnable<Number> x, y, z;
|
||||
private final Position position;
|
||||
@@ -29,11 +31,11 @@ public class GetMarkFunction implements Function<String> {
|
||||
}
|
||||
|
||||
@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());
|
||||
public String apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
Vector2 xz = new Vector2(x.apply(buffer, rotation, random, recursions).doubleValue(), z.apply(buffer, rotation, random, 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())));
|
||||
Mark mark = buffer.getMark(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(buffer, rotation, random, recursions).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||
return mark == null ? "" : mark.getContent();
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -12,6 +12,8 @@ import com.dfsek.terra.api.structures.structure.buffer.items.Mark;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class MarkFunction implements Function<Void> {
|
||||
private final Returnable<Number> x, y, z;
|
||||
private final Position position;
|
||||
@@ -31,12 +33,12 @@ public class MarkFunction implements Function<Void> {
|
||||
}
|
||||
|
||||
@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());
|
||||
public Void apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
Vector2 xz = new Vector2(x.apply(buffer, rotation, random, recursions).doubleValue(), z.apply(buffer, rotation, random, 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())));
|
||||
buffer.setMark(new Mark(mark.apply(buffer, rotation, random, recursions)), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(buffer, rotation, random, recursions).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -15,6 +15,8 @@ import com.dfsek.terra.api.structures.structure.buffer.items.BufferedPulledBlock
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class PullFunction implements Function<Void> {
|
||||
private final BlockData data;
|
||||
private final Returnable<Number> x, y, z;
|
||||
@@ -36,13 +38,13 @@ public class PullFunction implements Function<Void> {
|
||||
}
|
||||
|
||||
@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());
|
||||
public Void apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
Vector2 xz = new Vector2(x.apply(buffer, rotation, random, recursions).doubleValue(), z.apply(buffer, rotation, random, recursions).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, rotation);
|
||||
BlockData rot = data.clone();
|
||||
RotationUtil.rotateBlockData(rot, rotation.inverse());
|
||||
buffer.addItem(new BufferedPulledBlock(rot), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(buffer, rotation, recursions).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||
buffer.addItem(new BufferedPulledBlock(rot), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(buffer, rotation, random, recursions).intValue(), FastMath.roundToInt(xz.getZ())));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomFunction implements Function<Integer> {
|
||||
private final Returnable<Number> numberReturnable;
|
||||
@@ -29,8 +29,8 @@ public class RandomFunction implements Function<Integer> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
return ThreadLocalRandom.current().nextInt(numberReturnable.apply(buffer, rotation, recursions).intValue()); // TODO: deterministic random
|
||||
public Integer apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return random.nextInt(numberReturnable.apply(buffer, rotation, random, recursions).intValue()); // TODO: deterministic random
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-1
@@ -5,6 +5,8 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class RecursionsFunction implements Function<Number> {
|
||||
private final Position position;
|
||||
|
||||
@@ -23,7 +25,7 @@ public class RecursionsFunction implements Function<Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
public Number apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
return recursions;
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -15,7 +15,7 @@ import com.dfsek.terra.registry.ScriptRegistry;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.Random;
|
||||
|
||||
public class StructureFunction implements Function<Void> {
|
||||
private final ScriptRegistry registry;
|
||||
@@ -47,20 +47,20 @@ public class StructureFunction implements Function<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
public Void apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
|
||||
Vector2 xz = new Vector2(x.apply(buffer, rotation, recursions).doubleValue(), z.apply(buffer, rotation, recursions).doubleValue());
|
||||
Vector2 xz = new Vector2(x.apply(buffer, rotation, random, recursions).doubleValue(), z.apply(buffer, rotation, random, recursions).doubleValue());
|
||||
|
||||
RotationUtil.rotateVector(xz, rotation);
|
||||
|
||||
StructureScript script = registry.get(id.apply(buffer, rotation, recursions));
|
||||
StructureScript script = registry.get(id.apply(buffer, rotation, random, recursions));
|
||||
if(script == null) {
|
||||
main.getLogger().severe("No such structure " + id.apply(buffer, rotation, recursions));
|
||||
main.getLogger().severe("No such structure " + id.apply(buffer, rotation, random, recursions));
|
||||
return null;
|
||||
}
|
||||
|
||||
Rotation rotation1;
|
||||
String rotString = rotations.get(ThreadLocalRandom.current().nextInt(rotations.size())).apply(buffer, rotation, recursions);
|
||||
String rotString = rotations.get(random.nextInt(rotations.size())).apply(buffer, rotation, random, recursions);
|
||||
try {
|
||||
rotation1 = Rotation.valueOf(rotString);
|
||||
} catch(IllegalArgumentException e) {
|
||||
@@ -68,9 +68,9 @@ public class StructureFunction implements Function<Void> {
|
||||
return null;
|
||||
}
|
||||
|
||||
Vector3 offset = new Vector3(FastMath.roundToInt(xz.getX()), y.apply(buffer, rotation, recursions).intValue(), FastMath.roundToInt(xz.getZ()));
|
||||
Vector3 offset = new Vector3(FastMath.roundToInt(xz.getX()), y.apply(buffer, rotation, random, recursions).intValue(), FastMath.roundToInt(xz.getZ()));
|
||||
|
||||
script.executeInBuffer(new IntermediateBuffer(buffer, offset), rotation.rotate(rotation1), recursions + 1);
|
||||
script.executeInBuffer(new IntermediateBuffer(buffer, offset), random, rotation.rotate(rotation1), recursions + 1);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user