World util fix
This commit is contained in:
parent
b933b0e522
commit
ffa5d2f816
6 changed files with 164 additions and 10 deletions
|
@ -33,6 +33,29 @@ public class SplineHelper {
|
|||
return spline;
|
||||
}
|
||||
|
||||
public static List<Vector3f> smoothSpline(List<Vector3f> spline, int segmentPoints) {
|
||||
List<Vector3f> result = Lists.newArrayList();
|
||||
Vector3f start = spline.get(0);
|
||||
for (int i = 1; i < spline.size(); i++) {
|
||||
Vector3f end = spline.get(i);
|
||||
for (int j = 0; j < segmentPoints; j++) {
|
||||
float delta = (float) j / segmentPoints;
|
||||
delta = 0.5F - 0.5F * MathHelper.cos(delta * 3.14159F);
|
||||
result.add(lerp(start, end, delta));
|
||||
}
|
||||
start = end;
|
||||
}
|
||||
result.add(start);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Vector3f lerp(Vector3f start, Vector3f end, float delta) {
|
||||
float x = MathHelper.lerp(delta, start.getX(), end.getX());
|
||||
float y = MathHelper.lerp(delta, start.getY(), end.getY());
|
||||
float z = MathHelper.lerp(delta, start.getZ(), end.getZ());
|
||||
return new Vector3f(x, y, z);
|
||||
}
|
||||
|
||||
public static void offsetParts(List<Vector3f> spline, Random random, float dx, float dy, float dz) {
|
||||
int count = spline.size();
|
||||
for (int i = 1; i < count; i++) {
|
||||
|
|
|
@ -15,7 +15,7 @@ public class WorldDataUtil {
|
|||
saveFile = file;
|
||||
if (file.exists()) {
|
||||
try {
|
||||
root = NbtIo.read(file);
|
||||
root = NbtIo.readCompressed(file);
|
||||
}
|
||||
catch (IOException e) {
|
||||
BetterEnd.LOGGER.error("World data loading failed", e);
|
||||
|
@ -48,7 +48,7 @@ public class WorldDataUtil {
|
|||
|
||||
public static void saveFile() {
|
||||
try {
|
||||
NbtIo.write(root, saveFile);
|
||||
NbtIo.writeCompressed(root, saveFile);
|
||||
}
|
||||
catch (IOException e) {
|
||||
BetterEnd.LOGGER.error("World data saving failed", e);
|
||||
|
|
|
@ -273,4 +273,38 @@ public abstract class SDF {
|
|||
world.setBlock(info.getPos(), info.getState());
|
||||
});
|
||||
}
|
||||
|
||||
public Set<BlockPos> getPositions(ServerWorldAccess world, BlockPos start) {
|
||||
Set<BlockPos> blocks = Sets.newHashSet();
|
||||
Set<BlockPos> ends = Sets.newHashSet();
|
||||
Set<BlockPos> add = Sets.newHashSet();
|
||||
ends.add(new BlockPos(0, 0, 0));
|
||||
boolean run = true;
|
||||
|
||||
Mutable bPos = new Mutable();
|
||||
|
||||
while (run) {
|
||||
for (BlockPos center: ends) {
|
||||
for (Direction dir: Direction.values()) {
|
||||
bPos.set(center).move(dir);
|
||||
BlockPos wpos = bPos.add(start);
|
||||
BlockState state = world.getBlockState(wpos);
|
||||
if (!blocks.contains(wpos) && canReplace.apply(state)) {
|
||||
if (this.getDistance(bPos.getX(), bPos.getY(), bPos.getZ()) < 0) {
|
||||
add.add(bPos.toImmutable());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ends.forEach((end) -> blocks.add(end.add(start)));
|
||||
ends.clear();
|
||||
ends.addAll(add);
|
||||
add.clear();
|
||||
|
||||
run &= !ends.isEmpty();
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue