mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.dfsek.terra.config.factories.CarverFactory;
|
||||
import com.dfsek.terra.config.factories.FloraFactory;
|
||||
import com.dfsek.terra.config.factories.OreFactory;
|
||||
import com.dfsek.terra.config.factories.PaletteFactory;
|
||||
import com.dfsek.terra.config.factories.StructureFactory;
|
||||
import com.dfsek.terra.config.factories.TerraFactory;
|
||||
import com.dfsek.terra.config.factories.TreeFactory;
|
||||
import com.dfsek.terra.config.files.FolderLoader;
|
||||
@@ -38,6 +39,7 @@ import com.dfsek.terra.config.templates.CarverTemplate;
|
||||
import com.dfsek.terra.config.templates.FloraTemplate;
|
||||
import com.dfsek.terra.config.templates.OreTemplate;
|
||||
import com.dfsek.terra.config.templates.PaletteTemplate;
|
||||
import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.config.templates.TreeTemplate;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import com.dfsek.terra.generation.items.ores.Ore;
|
||||
@@ -155,6 +157,7 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
.open("palettes", ".yml").then(streams -> buildAll(new PaletteFactory(), paletteRegistry, abstractConfigLoader.load(streams, PaletteTemplate::new), main)).close()
|
||||
.open("ores", ".yml").then(streams -> buildAll(new OreFactory(), oreRegistry, abstractConfigLoader.load(streams, OreTemplate::new), main)).close()
|
||||
.open("structures/trees", ".yml").then(streams -> buildAll(new TreeFactory(), treeRegistry, abstractConfigLoader.load(streams, TreeTemplate::new), main)).close()
|
||||
.open("structures/structures", ".yml").then(streams -> buildAll(new StructureFactory(), structureRegistry, abstractConfigLoader.load(streams, StructureTemplate::new), main)).close()
|
||||
.open("flora", ".yml").then(streams -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.load(streams, FloraTemplate::new), main)).close()
|
||||
.open("carving", ".yml").then(streams -> buildAll(new CarverFactory(this), carverRegistry, abstractConfigLoader.load(streams, CarverTemplate::new), main)).close()
|
||||
.open("biomes", ".yml").then(streams -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.load(streams, () -> new BiomeTemplate(this, main)), main)).close()
|
||||
@@ -242,7 +245,8 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
.registerLoader(Flora.class, floraRegistry)
|
||||
.registerLoader(Ore.class, oreRegistry)
|
||||
.registerLoader(Tree.class, treeRegistry)
|
||||
.registerLoader(StructureScript.class, scriptRegistry);
|
||||
.registerLoader(StructureScript.class, scriptRegistry)
|
||||
.registerLoader(TerraStructure.class, structureRegistry);
|
||||
}
|
||||
|
||||
public ScriptRegistry getScriptRegistry() {
|
||||
|
||||
@@ -8,6 +8,6 @@ import com.dfsek.terra.generation.items.TerraStructure;
|
||||
public class StructureFactory implements TerraFactory<StructureTemplate, TerraStructure> {
|
||||
@Override
|
||||
public TerraStructure build(StructureTemplate config, TerraPlugin main) throws LoadException {
|
||||
return new TerraStructure(null, config.getBound(), config.getY(), config.getSpawn(), config.getLoot(), config);
|
||||
return new TerraStructure(config.getStructures(), config.getBound(), config.getY(), config.getSpawn(), config.getLoot(), config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.dfsek.terra.config.templates;
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ValidatedConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ValidationException;
|
||||
import com.dfsek.terra.api.loot.LootTable;
|
||||
import com.dfsek.terra.api.math.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.structures.script.StructureScript;
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
import com.dfsek.terra.procgen.GridSpawn;
|
||||
|
||||
@@ -13,13 +15,13 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class StructureTemplate extends AbstractableTemplate {
|
||||
public class StructureTemplate extends AbstractableTemplate implements ValidatedConfigTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("files")
|
||||
@Value("script")
|
||||
@Abstractable
|
||||
private ProbabilityCollection<Void> structures;
|
||||
private StructureScript structure;
|
||||
|
||||
@Value("spawn.start")
|
||||
@Abstractable
|
||||
@@ -50,8 +52,8 @@ public class StructureTemplate extends AbstractableTemplate {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ProbabilityCollection<Void> getStructures() {
|
||||
return structures;
|
||||
public StructureScript getStructures() {
|
||||
return structure;
|
||||
}
|
||||
|
||||
public Range getY() {
|
||||
@@ -69,4 +71,10 @@ public class StructureTemplate extends AbstractableTemplate {
|
||||
public GridSpawn getSpawn() {
|
||||
return spawn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
System.out.println("added structure " + id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.dfsek.terra.generation.items;
|
||||
|
||||
import com.dfsek.terra.api.loot.LootTable;
|
||||
import com.dfsek.terra.api.math.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.structures.script.StructureScript;
|
||||
import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.procgen.GridSpawn;
|
||||
|
||||
@@ -10,15 +10,15 @@ import java.util.Map;
|
||||
|
||||
// TODO: implementation
|
||||
public class TerraStructure {
|
||||
private final ProbabilityCollection<Void> structures;
|
||||
private final StructureScript structure;
|
||||
private final Range bound;
|
||||
private final Range spawnStart;
|
||||
private final GridSpawn spawn;
|
||||
private final Map<Integer, LootTable> loot;
|
||||
private final StructureTemplate template;
|
||||
|
||||
public TerraStructure(ProbabilityCollection<Void> structures, Range bound, Range spawnStart, GridSpawn spawn, Map<Integer, LootTable> loot, StructureTemplate template) {
|
||||
this.structures = structures;
|
||||
public TerraStructure(StructureScript structures, Range bound, Range spawnStart, GridSpawn spawn, Map<Integer, LootTable> loot, StructureTemplate template) {
|
||||
this.structure = structures;
|
||||
this.bound = bound;
|
||||
this.spawnStart = spawnStart;
|
||||
this.spawn = spawn;
|
||||
@@ -30,8 +30,8 @@ public class TerraStructure {
|
||||
return template;
|
||||
}
|
||||
|
||||
public ProbabilityCollection<Void> getStructures() {
|
||||
return structures;
|
||||
public StructureScript getStructure() {
|
||||
return structure;
|
||||
}
|
||||
|
||||
public Range getBound() {
|
||||
|
||||
@@ -21,7 +21,7 @@ public class TerraTree implements Tree {
|
||||
|
||||
@Override
|
||||
public synchronized boolean plant(Location location, Random random) {
|
||||
structure.execute(location.clone().add(0, yOffset, 0), Rotation.fromDegrees(90 * random.nextInt(4)));
|
||||
structure.execute(location.clone().add(0, yOffset, 0), random, Rotation.fromDegrees(90 * random.nextInt(4)));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.profiler.ProfileFuture;
|
||||
import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.world.generation.TerraBlockPopulator;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.debug.Debug;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import com.dfsek.terra.util.PopulationUtil;
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Random;
|
||||
@@ -18,7 +29,6 @@ public class StructurePopulator implements TerraBlockPopulator {
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) {
|
||||
/*
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
try(ProfileFuture ignored = tw.getProfiler().measure("StructureTime")) {
|
||||
Random random = PopulationUtil.getRandom(chunk);
|
||||
@@ -27,42 +37,17 @@ public class StructurePopulator implements TerraBlockPopulator {
|
||||
if(!tw.isSafe()) return;
|
||||
TerraBiomeGrid grid = tw.getGrid();
|
||||
ConfigPack config = tw.getConfig();
|
||||
structure:
|
||||
for(TerraStructure conf : config.getStructures()) {
|
||||
Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world);
|
||||
|
||||
if(!(FastMath.floorDiv(spawn.getBlockX(), 16) == chunk.getX()) || !(FastMath.floorDiv(spawn.getBlockZ(), 16) == chunk.getZ()))
|
||||
continue;
|
||||
|
||||
if(!((UserDefinedBiome) grid.getBiome(spawn)).getConfig().getStructures().contains(conf))
|
||||
continue;
|
||||
Random r2 = new FastRandom(spawn.hashCode());
|
||||
Structure struc = conf.getStructures().get(r2);
|
||||
Rotation rotation = Rotation.fromDegrees(r2.nextInt(4) * 90);
|
||||
for(int y = conf.getSpawnStart().get(r2); y > 0; y--) {
|
||||
if(!conf.getBound().isInRange(y)) continue structure;
|
||||
spawn.setY(y);
|
||||
if(!struc.checkSpawns(spawn, rotation, main)) continue;
|
||||
double horizontal = struc.getStructureInfo().getMaxHorizontal();
|
||||
if(FastMath.abs((cx + 8) - spawn.getBlockX()) <= horizontal && FastMath.abs((cz + 8) - spawn.getBlockZ()) <= horizontal) {
|
||||
struc.paste(spawn, chunk, rotation, main);
|
||||
for(StructureContainedInventory i : struc.getInventories()) {
|
||||
try {
|
||||
Vector2 lootCoords = RotationUtil.rotateVector(new Vector2(i.getX() - struc.getStructureInfo().getCenterX(), i.getZ() - struc.getStructureInfo().getCenterZ()), rotation.inverse());
|
||||
Location inv = spawn.clone().add(lootCoords.getX(), i.getY(), lootCoords.getZ());
|
||||
if(FastMath.floorDiv(inv.getBlockX(), 16) != chunk.getX() || FastMath.floorDiv(inv.getBlockZ(), 16) != chunk.getZ())
|
||||
continue;
|
||||
LootTable table = conf.getLoot().get(i.getUid());
|
||||
if(table == null) continue;
|
||||
table.fillInventory(((BlockInventoryHolder) inv.getBlock().getState()).getInventory(), random);
|
||||
} catch(ClassCastException e) {
|
||||
Debug.error("Could not populate structure loot!");
|
||||
Debug.stack(e);
|
||||
}
|
||||
}
|
||||
for(Feature f : conf.getTemplate().getFeatures()) f.apply(struc, rotation, spawn, chunk); // Apply features.
|
||||
break;
|
||||
}
|
||||
}
|
||||
Debug.info("Generating structure at (" + spawn.getBlockX() + ", " + spawn.getBlockY() + ", " + spawn.getBlockZ() + ")");
|
||||
conf.getStructure().execute(spawn.setY(conf.getSpawnStart().get(random)), random, Rotation.fromDegrees(90 * random.nextInt(4)));
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,9 @@ package com.dfsek.terra.registry;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
|
||||
public class StructureRegistry extends TerraRegistry<TerraStructure> {
|
||||
@Override
|
||||
public boolean add(String name, TerraStructure value) {
|
||||
System.out.println("added structure " + name + " to registry");
|
||||
return super.add(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,6 @@ public class TreeRegistry extends TerraRegistry<Tree> {
|
||||
|
||||
@Override
|
||||
public boolean add(String name, Tree value) {
|
||||
System.out.println("Added " + name);
|
||||
return super.add(name, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class ParserTest {
|
||||
@Test
|
||||
@@ -50,9 +51,9 @@ public class ParserTest {
|
||||
long t = System.nanoTime() - l;
|
||||
System.out.println("Took " + (double) t / 1000000);
|
||||
|
||||
block.apply(null, Rotation.NONE, 0);
|
||||
block.apply(null, Rotation.NONE, new Random(), 0);
|
||||
|
||||
block.apply(null, Rotation.NONE, 0);
|
||||
block.apply(null, Rotation.NONE, new Random(), 0);
|
||||
}
|
||||
|
||||
private static class Test1 implements Function<Void> {
|
||||
@@ -67,8 +68,8 @@ public class ParserTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void apply(Buffer buffer, Rotation rotation, int recursions) {
|
||||
System.out.println("string: " + a.apply(buffer, rotation, recursions) + ", double: " + b.apply(buffer, rotation, recursions));
|
||||
public Void apply(Buffer buffer, Rotation rotation, Random random, int recursions) {
|
||||
System.out.println("string: " + a.apply(buffer, rotation, random, recursions) + ", double: " + b.apply(buffer, rotation, random, recursions));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.bukkit.command.command.structure.load;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.bukkit.BukkitWorld;
|
||||
import com.dfsek.terra.bukkit.command.DebugCommand;
|
||||
import org.bukkit.block.Sign;
|
||||
@@ -36,65 +37,11 @@ public class LoadRawCommand extends LoadCommand implements DebugCommand {
|
||||
|
||||
TerraWorld terraWorld = getMain().getWorld(new BukkitWorld(sender.getWorld()));
|
||||
long t = System.nanoTime();
|
||||
terraWorld.getConfig().getScriptRegistry().get(args[0]).execute(new Location(new BukkitWorld(sender.getWorld()), sender.getLocation().getX(), sender.getLocation().getY(), sender.getLocation().getZ()), Rotation.fromDegrees(90 * ThreadLocalRandom.current().nextInt(4)));
|
||||
terraWorld.getConfig().getScriptRegistry().get(args[0]).execute(new Location(new BukkitWorld(sender.getWorld()), sender.getLocation().getX(), sender.getLocation().getY(), sender.getLocation().getZ()), new FastRandom(), Rotation.fromDegrees(90 * ThreadLocalRandom.current().nextInt(4)));
|
||||
long l = System.nanoTime() - t;
|
||||
|
||||
sender.sendMessage("Took " + ((double) l) / 1000000 + "ms");
|
||||
|
||||
/*
|
||||
try {
|
||||
WorldHandle handle = ((TerraBukkitPlugin) getMain()).getWorldHandle();
|
||||
Structure struc = Structure.load(new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure"));
|
||||
StructureInfo info = struc.getStructureInfo();
|
||||
int centerX = info.getCenterX();
|
||||
int centerZ = info.getCenterZ();
|
||||
for(StructureContainedBlock[][] level0 : struc.getRawStructure()) {
|
||||
for(StructureContainedBlock[] level1 : level0) {
|
||||
for(StructureContainedBlock block : level1) {
|
||||
Location bLocation = sender.getLocation().add(block.getX() - centerX, block.getY(), block.getZ() - centerZ);
|
||||
if(!block.getPull().equals(StructureContainedBlock.Pull.NONE)) {
|
||||
handle.setBlockData(bLocation.getBlock(), Material.OAK_SIGN.createBlockData(), false);
|
||||
Sign sign = (Sign) bLocation.getBlock().getState();
|
||||
sign.setLine(1, "[PULL=" + block.getPull() + "_" + block.getPullOffset() + "]");
|
||||
String data = block.getBlockData().getAsString(true);
|
||||
setTerraSign(sign, data);
|
||||
sign.update();
|
||||
} else if(!block.getRequirement().equals(StructureSpawnRequirement.BLANK)) {
|
||||
handle.setBlockData(bLocation.getBlock(), Material.OAK_SIGN.createBlockData(), false);
|
||||
Sign sign = (Sign) bLocation.getBlock().getState();
|
||||
sign.setLine(1, "[SPAWN=" + block.getRequirement() + "]");
|
||||
String data = block.getBlockData().getAsString(true);
|
||||
setTerraSign(sign, data);
|
||||
sign.update();
|
||||
} else {
|
||||
handle.setBlockData(bLocation.getBlock(), block.getBlockData(), false);
|
||||
if(block.getState() != null) {
|
||||
block.getState().getState(bLocation.getBlock().getState()).update(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int y = 0; y < struc.getStructureInfo().getSizeY(); y++) {
|
||||
StructureContainedBlock block = struc.getRawStructure()[centerX][centerZ][y];
|
||||
if(block.getRequirement().equals(StructureSpawnRequirement.BLANK) && block.getPull().equals(StructureContainedBlock.Pull.NONE)) {
|
||||
Location bLocation = sender.getLocation().add(block.getX() - centerX, block.getY(), block.getZ() - centerZ);
|
||||
handle.setBlockData(bLocation.getBlock(), Material.OAK_SIGN.createBlockData(), false);
|
||||
Sign sign = (Sign) bLocation.getBlock().getState();
|
||||
sign.setLine(1, "[CENTER]");
|
||||
String data = block.getBlockData().getAsString(true);
|
||||
setTerraSign(sign, data);
|
||||
sign.update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
LangUtil.send("command.structure.invalid", sender, args[0]);
|
||||
}
|
||||
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user