This commit is contained in:
paulevsGitch 2020-09-30 00:14:10 +03:00
parent 518e7b3fcf
commit 46ceaee8be
21 changed files with 207 additions and 55 deletions

View file

@ -3,6 +3,7 @@ package ru.betterend.world.features;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.function.Function;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@ -20,6 +21,7 @@ import ru.betterend.registry.BlockTagRegistry;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper;
import ru.betterend.util.SplineHelper;
import ru.betterend.util.sdf.PosInfo;
import ru.betterend.util.sdf.SDF;
import ru.betterend.util.sdf.operator.SDFBinary;
import ru.betterend.util.sdf.operator.SDFCoordModify;
@ -34,6 +36,8 @@ import ru.betterend.util.sdf.primitive.SDFCapedCone;
import ru.betterend.util.sdf.primitive.SDFSphere;
public class MossyGlowshroomFeature extends DefaultFeature {
private static final Function<PosInfo, BlockState> POST_PROCESS;
private static final Function<BlockState, Boolean> REPLACE;
private static final Vector3f CENTER = new Vector3f();
private static final SDFBinary FUNCTION;
private static final SDFTranslate HEAD_POS;
@ -61,7 +65,12 @@ public class MossyGlowshroomFeature extends DefaultFeature {
HEAD_POS.setTranslate(pos.getX(), pos.getY(), pos.getZ());
ROOTS.setAngle(random.nextFloat() * MHelper.PI2);
FUNCTION.setSourceA(sdf);
Set<BlockPos> blocks = new SDFScale().setScale(MHelper.randRange(0.5F, 1F, random)).setSource(FUNCTION).fillRecursive(world, blockPos);
Set<BlockPos> blocks = new SDFScale()
.setScale(MHelper.randRange(0.5F, 1F, random))
.setSource(FUNCTION)
.setReplaceFunction(REPLACE)
.setPostProcess(POST_PROCESS)
.fillRecursive(world, blockPos);
for (BlockPos bpos: blocks) {
BlockState state = world.getBlockState(bpos);
@ -92,8 +101,8 @@ public class MossyGlowshroomFeature extends DefaultFeature {
}
static {
SDFCapedCone cone1 = new SDFCapedCone(BlockRegistry.MOSSY_GLOWSHROOM_CAP.getDefaultState()).setHeight(2.5F).setRadius1(1.5F).setRadius2(2.5F);
SDFCapedCone cone2 = new SDFCapedCone(BlockRegistry.MOSSY_GLOWSHROOM_CAP.getDefaultState()).setHeight(3F).setRadius1(2.5F).setRadius2(13F);
SDFCapedCone cone1 = new SDFCapedCone(BlockRegistry.MOSSY_GLOWSHROOM_CAP).setHeight(2.5F).setRadius1(1.5F).setRadius2(2.5F);
SDFCapedCone cone2 = new SDFCapedCone(BlockRegistry.MOSSY_GLOWSHROOM_CAP).setHeight(3F).setRadius1(2.5F).setRadius2(13F);
SDF posedCone2 = new SDFTranslate().setTranslate(0, 5, 0).setSource(cone2);
SDF posedCone3 = new SDFTranslate().setTranslate(0, 7F, 0).setSource(cone2);
SDF upCone = new SDFSubtraction().setSourceA(posedCone2).setSourceB(posedCone3);
@ -104,7 +113,7 @@ public class MossyGlowshroomFeature extends DefaultFeature {
innerCone = new SDFScale3D().setScale(1.2F, 1F, 1.2F).setSource(innerCone);
cones = new SDFUnion().setSourceA(cones).setSourceB(innerCone);
SDF glowCone = new SDFCapedCone(BlockRegistry.MOSSY_GLOWSHROOM_HYMENOPHORE.getDefaultState()).setHeight(3F).setRadius1(2F).setRadius2(12.5F);
SDF glowCone = new SDFCapedCone(BlockRegistry.MOSSY_GLOWSHROOM_HYMENOPHORE).setHeight(3F).setRadius1(2F).setRadius2(12.5F);
glowCone = new SDFTranslate().setTranslate(0, 4.25F, 0).setSource(glowCone);
glowCone = new SDFSubtraction().setSourceA(glowCone).setSourceB(posedCone3);
@ -119,15 +128,22 @@ public class MossyGlowshroomFeature extends DefaultFeature {
HEAD_POS = (SDFTranslate) new SDFTranslate().setSource(new SDFTranslate().setTranslate(0, 2.5F, 0).setSource(cones));
SDF roots = new SDFSphere(BlockRegistry.MOSSY_GLOWSHROOM.bark.getDefaultState()).setRadius(4F);
SDF roots = new SDFSphere(BlockRegistry.MOSSY_GLOWSHROOM.bark).setRadius(4F);
roots = new SDFScale3D().setScale(1, 0.7F, 1).setSource(roots);
ROOTS = (SDFFlatWave) new SDFFlatWave().setRaysCount(5).setIntensity(1.5F).setSource(roots);
FUNCTION = new SDFSmoothUnion().setRadius(4).setSourceB(new SDFUnion().setSourceA(HEAD_POS).setSourceB(ROOTS));
FUNCTION.setPostProcess((info) -> {
REPLACE = (state) -> {
if (state.getBlock() != Blocks.END_STONE && state.isIn(BlockTagRegistry.END_GROUND)) {
return true;
}
return state.getMaterial().isReplaceable();
};
POST_PROCESS = (info) -> {
if (BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getState())) {
BlockState up = info.getStateUp();
if (!BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(up) || !BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) {
if (!BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp()) || !BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) {
return BlockRegistry.MOSSY_GLOWSHROOM.bark.getDefaultState();
}
}
@ -135,15 +151,19 @@ public class MossyGlowshroomFeature extends DefaultFeature {
if (BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) {
return info.getState().with(BlockMossyGlowshroomCap.TRANSITION, true);
}
int air = 0;
for (Direction dir: Direction.values()) {
if (info.getState(dir).isAir()) {
air ++;
}
}
if (air > 4) {
info.setState(AIR);
return AIR;
}
}
return info.getState();
});
FUNCTION.setReplaceFunction((state) -> {
if (state.getBlock() != Blocks.END_STONE && state.isIn(BlockTagRegistry.END_GROUND)) {
return true;
}
return state.getMaterial().isReplaceable();
});
};
}
}