Lakugrove structure

This commit is contained in:
paulevsGitch 2020-10-28 00:23:06 +03:00
parent 0f9edccc4e
commit 91b40a3ae6
17 changed files with 301 additions and 64 deletions

View file

@ -135,4 +135,66 @@ public class SplineHelper {
return false;
}
}
public static boolean canGenerate(List<Vector3f> spline, float scale, BlockPos start, StructureWorldAccess world, Function<BlockState, Boolean> canReplace) {
int count = spline.size();
Vector3f vec = spline.get(0);
Mutable mut = new Mutable();
float x1 = start.getX() + vec.getX() * scale;
float y1 = start.getY() + vec.getY() * scale;
float z1 = start.getZ() + vec.getZ() * scale;
for (int i = 1; i < count; i++) {
vec = spline.get(i);
float x2 = start.getX() + vec.getX() * scale;
float y2 = start.getY() + vec.getY() * scale;
float z2 = start.getZ() + vec.getZ() * scale;
for (float py = y1; py < y2; py += 3) {
if (py - start.getY() < 10) continue;
float lerp = (py - y1) / (y2 - y1);
float x = MathHelper.lerp(lerp, x1, x2);
float z = MathHelper.lerp(lerp, z1, z2);
mut.set(x, py, z);
if (!canReplace.apply(world.getBlockState(mut))) {
return false;
}
}
x1 = x2;
y1 = y2;
z1 = z2;
}
return true;
}
public static boolean canGenerate(List<Vector3f> spline, BlockPos start, StructureWorldAccess world, Function<BlockState, Boolean> canReplace) {
int count = spline.size();
Vector3f vec = spline.get(0);
Mutable mut = new Mutable();
float x1 = start.getX() + vec.getX();
float y1 = start.getY() + vec.getY();
float z1 = start.getZ() + vec.getZ();
for (int i = 1; i < count; i++) {
vec = spline.get(i);
float x2 = start.getX() + vec.getX();
float y2 = start.getY() + vec.getY();
float z2 = start.getZ() + vec.getZ();
for (float py = y1; py < y2; py += 3) {
if (py - start.getY() < 10) continue;
float lerp = (py - y1) / (y2 - y1);
float x = MathHelper.lerp(lerp, x1, x2);
float z = MathHelper.lerp(lerp, z1, z2);
mut.set(x, py, z);
if (!canReplace.apply(world.getBlockState(mut))) {
return false;
}
}
x1 = x2;
y1 = y2;
z1 = z2;
}
return true;
}
}

View file

@ -13,6 +13,7 @@ import com.google.common.collect.Sets;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.world.ServerWorldAccess;
import ru.betterend.util.BlocksHelper;
@ -155,6 +156,102 @@ public abstract class SDF {
}
}
public void fillArea(ServerWorldAccess world, BlockPos center, Box box) {
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();
Mutable mut = new Mutable();
for (int y = (int) box.minY; y <= box.maxY; y++) {
mut.setY(y);
for (int x = (int) box.minX; x <= box.maxX; x++) {
mut.setX(x);
for (int z = (int) box.minZ; z <= box.maxZ; z++) {
mut.setZ(z);
if (canReplace.apply(world.getBlockState(mut))) {
BlockPos fpos = mut.subtract(center);
if (this.getDistance(fpos.getX(), fpos.getY(), fpos.getZ()) < 0) {
PosInfo.create(mapWorld, addInfo, mut.toImmutable()).setState(getBlockState(mut));
}
}
}
}
}
List<PosInfo> infos = new ArrayList<PosInfo>(mapWorld.values());
if (infos.size() > 0) {
Collections.sort(infos);
infos.forEach((info) -> {
BlockState state = postProcess.apply(info);
BlocksHelper.setWithoutUpdate(world, info.getPos(), state);
});
infos.clear();
infos.addAll(addInfo.values());
Collections.sort(infos);
infos.forEach((info) -> {
if (canReplace.apply(world.getBlockState(info.getPos()))) {
BlockState state = postProcess.apply(info);
BlocksHelper.setWithoutUpdate(world, info.getPos(), state);
}
});
}
}
public void fillRecursiveIgnore(ServerWorldAccess world, BlockPos start, Function<BlockState, Boolean> ignore) {
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();
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);
boolean ign = ignore.apply(state);
if (!blocks.contains(bPos) && (ign || canReplace.apply(state))) {
if (this.getDistance(bPos.getX(), bPos.getY(), bPos.getZ()) < 0) {
PosInfo.create(mapWorld, addInfo, wpos).setState(ign ? state : getBlockState(bPos));
add.add(bPos.toImmutable());
}
}
}
}
blocks.addAll(ends);
ends.clear();
ends.addAll(add);
add.clear();
run &= !ends.isEmpty();
}
List<PosInfo> infos = new ArrayList<PosInfo>(mapWorld.values());
if (infos.size() > 0) {
Collections.sort(infos);
infos.forEach((info) -> {
BlockState state = postProcess.apply(info);
BlocksHelper.setWithoutUpdate(world, info.getPos(), state);
});
infos.clear();
infos.addAll(addInfo.values());
Collections.sort(infos);
infos.forEach((info) -> {
if (canReplace.apply(world.getBlockState(info.getPos()))) {
BlockState state = postProcess.apply(info);
BlocksHelper.setWithoutUpdate(world, info.getPos(), state);
}
});
}
}
public void fillRecursive(StructureWorld world, BlockPos start) {
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();