SDF, tags registry
This commit is contained in:
parent
9ccd0d987b
commit
cf8955ea4b
14 changed files with 214 additions and 3 deletions
|
@ -42,6 +42,10 @@ public class BlocksHelper {
|
|||
public static void setWithoutUpdate(WorldAccess world, BlockPos pos, BlockState state) {
|
||||
world.setBlockState(pos, state, SET_SILENT);
|
||||
}
|
||||
|
||||
public static void setWithoutUpdate(WorldAccess world, BlockPos pos, Block block) {
|
||||
world.setBlockState(pos, block.getDefaultState(), SET_SILENT);
|
||||
}
|
||||
|
||||
public static int upRay(WorldAccess world, BlockPos pos, int maxDist) {
|
||||
int length = 0;
|
||||
|
|
|
@ -1,5 +1,83 @@
|
|||
package ru.betterend.util.sdf;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
|
||||
public interface ISDF {
|
||||
public float getDistance(float x, float y, float z);
|
||||
|
||||
default void fillRecursive(ServerWorldAccess world, BlockPos start, Function<BlockState, Boolean> canReplace, int dx, int dy, int dz) {
|
||||
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;
|
||||
|
||||
while (run) {
|
||||
for (BlockPos center: ends) {
|
||||
for (Direction dir: Direction.values()) {
|
||||
BlockPos pos = center.offset(dir);
|
||||
BlockPos wpos = pos.add(start);
|
||||
|
||||
run &= Math.abs(pos.getX()) < dx;
|
||||
run &= Math.abs(pos.getY()) < dy;
|
||||
run &= Math.abs(pos.getZ()) < dz;
|
||||
|
||||
if (!blocks.contains(pos) && canReplace.apply(world.getBlockState(wpos))) {
|
||||
if (this.getDistance(pos.getX(), pos.getY(), pos.getZ()) <= 0) {
|
||||
BlocksHelper.setWithoutUpdate(world, wpos, Blocks.STONE);
|
||||
add.add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
blocks.addAll(ends);
|
||||
ends.clear();
|
||||
ends.addAll(add);
|
||||
add.clear();
|
||||
|
||||
run &= !ends.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
default void fillRecursive(ServerWorldAccess world, BlockPos start, Function<BlockState, Boolean> canReplace) {
|
||||
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;
|
||||
|
||||
while (run) {
|
||||
for (BlockPos center: ends) {
|
||||
for (Direction dir: Direction.values()) {
|
||||
BlockPos pos = center.offset(dir);
|
||||
BlockPos wpos = pos.add(start);
|
||||
|
||||
if (!blocks.contains(pos) && canReplace.apply(world.getBlockState(wpos))) {
|
||||
if (this.getDistance(pos.getX(), pos.getY(), pos.getZ()) <= 0) {
|
||||
BlocksHelper.setWithoutUpdate(world, wpos, Blocks.STONE);
|
||||
add.add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
blocks.addAll(ends);
|
||||
ends.clear();
|
||||
ends.addAll(add);
|
||||
add.clear();
|
||||
|
||||
run &= !ends.isEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
19
src/main/java/ru/betterend/util/sdf/operator/SDFScale3D.java
Normal file
19
src/main/java/ru/betterend/util/sdf/operator/SDFScale3D.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package ru.betterend.util.sdf.operator;
|
||||
|
||||
public class SDFScale3D extends SDFUnary {
|
||||
private float x;
|
||||
private float y;
|
||||
private float z;
|
||||
|
||||
public SDFScale3D setScale(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDistance(float x, float y, float z) {
|
||||
return source.getDistance(x / this.x, y / this.y, z / this.z);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,6 @@ public class SDFSubtraction extends SDFBinary {
|
|||
public float getDistance(float x, float y, float z) {
|
||||
float a = this.sourceA.getDistance(x, y, z);
|
||||
float b = this.sourceB.getDistance(x, y, z);
|
||||
return MHelper.max(-a, b);
|
||||
return MHelper.max(a, -b);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package ru.betterend.util.sdf.operator;
|
||||
|
||||
public class SDFTranslate extends SDFUnary {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
public SDFTranslate setTranslate(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDistance(float x, float y, float z) {
|
||||
return source.getDistance(x - this.x, y - this.y, z - this.z);
|
||||
}
|
||||
}
|
|
@ -20,6 +20,6 @@ public class SDFCapsule implements ISDF {
|
|||
|
||||
@Override
|
||||
public float getDistance(float x, float y, float z) {
|
||||
return MHelper.length(x, MathHelper.clamp(y, 0F, height), z) - radius;
|
||||
return MHelper.length(x, MathHelper.clamp(y, -height, 0), z) - radius;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue