Mushroom improvements

This commit is contained in:
paulevsGitch 2020-09-29 22:18:55 +03:00
parent 9a1dc34927
commit 6c4a1d2eb0
28 changed files with 501 additions and 44 deletions

View file

@ -17,6 +17,9 @@ public abstract class SDF {
private Function<PosInfo, BlockState> postProcess = (info) -> {
return info.getState();
};
private Function<BlockState, Boolean> canReplace = (state) -> {
return state.getMaterial().isReplaceable();
};
public abstract float getDistance(float x, float y, float z);
@ -27,13 +30,17 @@ public abstract class SDF {
return this;
}
public void fillRecursive(ServerWorldAccess world, BlockPos start, Function<BlockState, Boolean> canReplace, int dx, int dy, int dz) {
public SDF setReplaceFunction(Function<BlockState, Boolean> canReplace) {
this.canReplace = canReplace;
return this;
}
public Set<BlockPos> fillRecursive(ServerWorldAccess world, BlockPos start, int dx, int dy, int dz) {
Map<BlockPos, PosInfo> mapWorld = 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 process = postProcess != null;
boolean run = true;
while (run) {
@ -70,9 +77,11 @@ public abstract class SDF {
BlockState state = postProcess.apply(info);
BlocksHelper.setWithoutUpdate(world, pos, state);
});
return mapWorld.keySet();
}
public void fillRecursive(ServerWorldAccess world, BlockPos start, Function<BlockState, Boolean> canReplace) {
public Set<BlockPos> fillRecursive(ServerWorldAccess world, BlockPos start) {
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
Set<BlockPos> blocks = Sets.newHashSet();
Set<BlockPos> ends = Sets.newHashSet();
@ -87,7 +96,7 @@ public abstract class SDF {
BlockPos wpos = pos.add(start);
if (!blocks.contains(pos) && canReplace.apply(world.getBlockState(wpos))) {
if (this.getDistance(pos.getX(), pos.getY(), pos.getZ()) <= 0) {
if (this.getDistance(pos.getX(), pos.getY(), pos.getZ()) < 0) {
BlockState state = getBlockState(wpos);
PosInfo.create(mapWorld, wpos).setState(state);
add.add(pos);
@ -108,5 +117,7 @@ public abstract class SDF {
BlockState state = postProcess.apply(info);
BlocksHelper.setWithoutUpdate(world, pos, state);
});
return mapWorld.keySet();
}
}

View file

@ -0,0 +1,22 @@
package ru.betterend.util.sdf.operator;
import java.util.function.Consumer;
import net.minecraft.client.util.math.Vector3f;
public class SDFCoordModify extends SDFUnary {
private static final Vector3f POS = new Vector3f();
private Consumer<Vector3f> function;
public SDFCoordModify setFunction(Consumer<Vector3f> function) {
this.function = function;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
POS.set(x, y, z);
function.accept(POS);
return this.source.getDistance(POS.getX(), POS.getY(), POS.getZ());
}
}

View file

@ -0,0 +1,19 @@
package ru.betterend.util.sdf.operator;
import ru.betterend.util.MHelper;
public class SDFCopyRotate extends SDFUnary {
int count = 1;
public SDFCopyRotate setCount(int count) {
this.count = count;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
float px = (float) Math.atan2(x, z);
float pz = MHelper.length(x, z);
return this.source.getDistance(px, y, pz);
}
}

View file

@ -3,10 +3,11 @@ package ru.betterend.util.sdf.operator;
public class SDFFlatWave extends SDFDisplacement {
private int rayCount = 1;
private float intensity;
private float angle;
public SDFFlatWave() {
setFunction((pos) -> {
return (float) Math.cos(Math.atan2(pos.getX(), pos.getZ()) * rayCount) * intensity;
return (float) Math.cos(Math.atan2(pos.getX(), pos.getZ()) * rayCount + angle) * intensity;
});
}
@ -15,6 +16,11 @@ public class SDFFlatWave extends SDFDisplacement {
return this;
}
public SDFFlatWave setAngle(float angle) {
this.angle = angle;
return this;
}
public SDFFlatWave setIntensity(float intensity) {
this.intensity = intensity;
return this;