diff --git a/src/main/java/ru/betterend/util/sdf/PosInfo.java b/src/main/java/ru/betterend/util/sdf/PosInfo.java index d072c6c9..7c71dc67 100644 --- a/src/main/java/ru/betterend/util/sdf/PosInfo.java +++ b/src/main/java/ru/betterend/util/sdf/PosInfo.java @@ -7,7 +7,7 @@ import net.minecraft.block.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -public class PosInfo { +public class PosInfo implements Comparable { private static final BlockState AIR = Blocks.AIR.getDefaultState(); private final Map blocks; private final BlockPos pos; @@ -39,6 +39,14 @@ public class PosInfo { return info.getState(); } + public BlockState getState(Direction dir, int distance) { + PosInfo info = blocks.get(pos.offset(dir, distance)); + if (info == null) { + return AIR; + } + return info.getState(); + } + public BlockState getStateUp() { return getState(Direction.UP); } @@ -57,4 +65,13 @@ public class PosInfo { } return pos.equals(((PosInfo) obj).pos); } + + @Override + public int compareTo(PosInfo info) { + return this.pos.getY() - info.pos.getY(); + } + + public BlockPos getPos() { + return pos; + } } diff --git a/src/main/java/ru/betterend/util/sdf/SDF.java b/src/main/java/ru/betterend/util/sdf/SDF.java index b9a532b4..f822198b 100644 --- a/src/main/java/ru/betterend/util/sdf/SDF.java +++ b/src/main/java/ru/betterend/util/sdf/SDF.java @@ -1,5 +1,8 @@ package ru.betterend.util.sdf; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Function; @@ -36,7 +39,7 @@ public abstract class SDF { return this; } - public Set fillRecursive(ServerWorldAccess world, BlockPos start, int dx, int dy, int dz) { + public void fillRecursive(ServerWorldAccess world, BlockPos start, int dx, int dy, int dz) { Map mapWorld = Maps.newHashMap(); Set blocks = Sets.newHashSet(); Set ends = Sets.newHashSet(); @@ -74,15 +77,17 @@ public abstract class SDF { run &= !ends.isEmpty(); } - mapWorld.forEach((pos, info) -> { - BlockState state = postProcess.apply(info); - BlocksHelper.setWithoutUpdate(world, pos, state); - }); - - return mapWorld.keySet(); + List infos = new ArrayList(mapWorld.values()); + if (infos.size() > 0) { + Collections.sort(infos); + infos.forEach((info) -> { + BlockState state = postProcess.apply(info); + BlocksHelper.setWithoutUpdate(world, info.getPos(), state); + }); + } } - public Set fillRecursive(ServerWorldAccess world, BlockPos start) { + public void fillRecursive(ServerWorldAccess world, BlockPos start) { Map mapWorld = Maps.newHashMap(); Set blocks = Sets.newHashSet(); Set ends = Sets.newHashSet(); @@ -119,10 +124,17 @@ public abstract class SDF { BlocksHelper.setWithoutUpdate(world, pos, state); }); - return mapWorld.keySet(); + List infos = new ArrayList(mapWorld.values()); + if (infos.size() > 0) { + Collections.sort(infos); + infos.forEach((info) -> { + BlockState state = postProcess.apply(info); + BlocksHelper.setWithoutUpdate(world, info.getPos(), state); + }); + } } - public Set fillRecursive(StructureWorld world, BlockPos start) { + public void fillRecursive(StructureWorld world, BlockPos start) { Map mapWorld = Maps.newHashMap(); Set blocks = Sets.newHashSet(); Set ends = Sets.newHashSet(); @@ -154,11 +166,11 @@ public abstract class SDF { run &= !ends.isEmpty(); } - mapWorld.forEach((pos, info) -> { + List infos = new ArrayList(mapWorld.values()); + Collections.sort(infos); + infos.forEach((info) -> { BlockState state = postProcess.apply(info); - world.setBlock(pos, state); + world.setBlock(info.getPos(), state); }); - - return mapWorld.keySet(); } } diff --git a/src/main/java/ru/betterend/world/features/MossyGlowshroomFeature.java b/src/main/java/ru/betterend/world/features/MossyGlowshroomFeature.java index 85364689..86535057 100644 --- a/src/main/java/ru/betterend/world/features/MossyGlowshroomFeature.java +++ b/src/main/java/ru/betterend/world/features/MossyGlowshroomFeature.java @@ -2,7 +2,6 @@ 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; @@ -10,20 +9,17 @@ import net.minecraft.block.Material; import net.minecraft.client.util.math.Vector3f; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos.Mutable; -import net.minecraft.util.math.Direction; import net.minecraft.util.math.MathHelper; import net.minecraft.world.StructureWorldAccess; import net.minecraft.world.gen.chunk.ChunkGenerator; import net.minecraft.world.gen.feature.DefaultFeatureConfig; import ru.betterend.blocks.BlockMossyGlowshroomCap; -import ru.betterend.blocks.basis.BlockGlowingFur; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.BlockRegistry; 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; @@ -39,7 +35,6 @@ import ru.betterend.util.sdf.primitive.SDFPrimitive; import ru.betterend.util.sdf.primitive.SDFSphere; public class MossyGlowshroomFeature extends DefaultFeature { - private static final Function POST_PROCESS; private static final Function REPLACE; private static final Vector3f CENTER = new Vector3f(); private static final SDFBinary FUNCTION; @@ -112,38 +107,33 @@ public class MossyGlowshroomFeature extends DefaultFeature { ROOTS_ROT.setAngle(random.nextFloat() * MHelper.PI2); FUNCTION.setSourceA(sdf); - Set blocks = new SDFScale() - .setScale(scale) + new SDFScale().setScale(scale) .setSource(FUNCTION) .setReplaceFunction(REPLACE) - .setPostProcess(POST_PROCESS) + .setPostProcess((info) -> { + if (BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getState())) { + if (random.nextBoolean() && info.getStateUp().getBlock() == BlockRegistry.MOSSY_GLOWSHROOM_CAP) { + info.setState(BlockRegistry.MOSSY_GLOWSHROOM_CAP.getDefaultState().with(BlockMossyGlowshroomCap.TRANSITION, true)); + return info.getState(); + } + else if (!BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp()) || !BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) { + info.setState(BlockRegistry.MOSSY_GLOWSHROOM.bark.getDefaultState()); + return info.getState(); + } + } + else if (info.getState().getBlock() == BlockRegistry.MOSSY_GLOWSHROOM_CAP) { + if (BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown().getBlock())) { + info.setState(BlockRegistry.MOSSY_GLOWSHROOM_CAP.getDefaultState().with(BlockMossyGlowshroomCap.TRANSITION, true)); + return info.getState(); + } + + info.setState(BlockRegistry.MOSSY_GLOWSHROOM_CAP.getDefaultState()); + return info.getState(); + } + return info.getState(); + }) .fillRecursive(world, blockPos); - for (BlockPos bpos: blocks) { - BlockState state = world.getBlockState(bpos); - if (state.getBlock() == BlockRegistry.MOSSY_GLOWSHROOM_HYMENOPHORE) { - if (world.isAir(bpos.north())) { - BlocksHelper.setWithoutUpdate(world, bpos.north(), BlockRegistry.MOSSY_GLOWSHROOM_FUR.getDefaultState().with(BlockGlowingFur.FACING, Direction.NORTH)); - } - if (world.isAir(bpos.east())) { - BlocksHelper.setWithoutUpdate(world, bpos.east(), BlockRegistry.MOSSY_GLOWSHROOM_FUR.getDefaultState().with(BlockGlowingFur.FACING, Direction.EAST)); - } - if (world.isAir(bpos.south())) { - BlocksHelper.setWithoutUpdate(world, bpos.south(), BlockRegistry.MOSSY_GLOWSHROOM_FUR.getDefaultState().with(BlockGlowingFur.FACING, Direction.SOUTH)); - } - if (world.isAir(bpos.west())) { - BlocksHelper.setWithoutUpdate(world, bpos.west(), BlockRegistry.MOSSY_GLOWSHROOM_FUR.getDefaultState().with(BlockGlowingFur.FACING, Direction.WEST)); - } - if (world.getBlockState(bpos.down()).getMaterial().isReplaceable()) { - BlocksHelper.setWithoutUpdate(world, bpos.down(), BlockRegistry.MOSSY_GLOWSHROOM_FUR.getDefaultState().with(BlockGlowingFur.FACING, Direction.DOWN)); - } - } - else if (BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(state) && random.nextBoolean() && world.getBlockState(bpos.up()).getBlock() == BlockRegistry.MOSSY_GLOWSHROOM_CAP) { - BlocksHelper.setWithoutUpdate(world, bpos, BlockRegistry.MOSSY_GLOWSHROOM_CAP.getDefaultState().with(BlockMossyGlowshroomCap.TRANSITION, true)); - BlocksHelper.setWithoutUpdate(world, bpos.up(), BlockRegistry.MOSSY_GLOWSHROOM_CAP); - } - } - return true; } @@ -151,7 +141,7 @@ public class MossyGlowshroomFeature extends DefaultFeature { SDFCapedCone cone1 = new SDFCapedCone().setHeight(2.5F).setRadius1(1.5F).setRadius2(2.5F); SDFCapedCone cone2 = new SDFCapedCone().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 posedCone3 = new SDFTranslate().setTranslate(0, 12F, 0).setSource(new SDFScale().setScale(2).setSource(cone2)); SDF upCone = new SDFSubtraction().setSourceA(posedCone2).setSourceB(posedCone3); SDF wave = new SDFFlatWave().setRaysCount(12).setIntensity(1.3F).setSource(upCone); SDF cones = new SDFSmoothUnion().setRadius(3).setSourceA(cone1).setSourceB(wave); @@ -195,30 +185,5 @@ public class MossyGlowshroomFeature extends DefaultFeature { } return state.getMaterial().isReplaceable(); }; - - POST_PROCESS = (info) -> { - if (BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getState())) { - if (!BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp()) || !BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) { - return BlockRegistry.MOSSY_GLOWSHROOM.bark.getDefaultState(); - } - } - else if (info.getState().getBlock() == BlockRegistry.MOSSY_GLOWSHROOM_CAP) { - 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(); - }; } } diff --git a/src/main/java/ru/betterend/world/structures/features/StructureGiantMossyGlowshroom.java b/src/main/java/ru/betterend/world/structures/features/StructureGiantMossyGlowshroom.java index 126fb8df..1a43c1ad 100644 --- a/src/main/java/ru/betterend/world/structures/features/StructureGiantMossyGlowshroom.java +++ b/src/main/java/ru/betterend/world/structures/features/StructureGiantMossyGlowshroom.java @@ -2,11 +2,11 @@ package ru.betterend.world.structures.features; import java.util.List; import java.util.Random; + import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.client.util.math.Vector3f; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; import ru.betterend.blocks.BlockMossyGlowshroomCap; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.BlockRegistry; @@ -90,30 +90,28 @@ public class StructureGiantMossyGlowshroom extends SDFStructureFeature { return new SDFRound().setRadius(1.5F).setSource(new SDFScale() .setScale(scale) - .setSource(function) + .setSource(function)) .setPostProcess((info) -> { if (BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getState())) { - if (!BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp()) || !BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) { - return BlockRegistry.MOSSY_GLOWSHROOM.bark.getDefaultState(); + if (random.nextBoolean() && info.getStateUp().getBlock() == BlockRegistry.MOSSY_GLOWSHROOM_CAP) { + info.setState(BlockRegistry.MOSSY_GLOWSHROOM_CAP.getDefaultState().with(BlockMossyGlowshroomCap.TRANSITION, true)); + return info.getState(); + } + else if (!BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp()) || !BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) { + info.setState(BlockRegistry.MOSSY_GLOWSHROOM.bark.getDefaultState()); + return info.getState(); } } else if (info.getState().getBlock() == BlockRegistry.MOSSY_GLOWSHROOM_CAP) { - if (BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) { - return info.getState().with(BlockMossyGlowshroomCap.TRANSITION, true); + if (BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown().getBlock())) { + info.setState(BlockRegistry.MOSSY_GLOWSHROOM_CAP.getDefaultState().with(BlockMossyGlowshroomCap.TRANSITION, true)); + return info.getState(); } - int air = 0; - for (Direction dir: Direction.values()) { - if (info.getState(dir).isAir()) { - air ++; - } - } - if (air > 4) { - info.setState(AIR); - return AIR; - } + info.setState(BlockRegistry.MOSSY_GLOWSHROOM_CAP.getDefaultState()); + return info.getState(); } return info.getState(); - })); + }); } }