Mushroom fixes
This commit is contained in:
parent
150b005257
commit
31e33ba2d3
4 changed files with 83 additions and 91 deletions
|
@ -7,7 +7,7 @@ import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
|
|
||||||
public class PosInfo {
|
public class PosInfo implements Comparable<PosInfo> {
|
||||||
private static final BlockState AIR = Blocks.AIR.getDefaultState();
|
private static final BlockState AIR = Blocks.AIR.getDefaultState();
|
||||||
private final Map<BlockPos, PosInfo> blocks;
|
private final Map<BlockPos, PosInfo> blocks;
|
||||||
private final BlockPos pos;
|
private final BlockPos pos;
|
||||||
|
@ -39,6 +39,14 @@ public class PosInfo {
|
||||||
return info.getState();
|
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() {
|
public BlockState getStateUp() {
|
||||||
return getState(Direction.UP);
|
return getState(Direction.UP);
|
||||||
}
|
}
|
||||||
|
@ -57,4 +65,13 @@ public class PosInfo {
|
||||||
}
|
}
|
||||||
return pos.equals(((PosInfo) obj).pos);
|
return pos.equals(((PosInfo) obj).pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(PosInfo info) {
|
||||||
|
return this.pos.getY() - info.pos.getY();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos getPos() {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package ru.betterend.util.sdf;
|
package ru.betterend.util.sdf;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -36,7 +39,7 @@ public abstract class SDF {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<BlockPos> 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<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
|
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
|
||||||
Set<BlockPos> blocks = Sets.newHashSet();
|
Set<BlockPos> blocks = Sets.newHashSet();
|
||||||
Set<BlockPos> ends = Sets.newHashSet();
|
Set<BlockPos> ends = Sets.newHashSet();
|
||||||
|
@ -74,15 +77,17 @@ public abstract class SDF {
|
||||||
run &= !ends.isEmpty();
|
run &= !ends.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
mapWorld.forEach((pos, info) -> {
|
List<PosInfo> infos = new ArrayList<PosInfo>(mapWorld.values());
|
||||||
BlockState state = postProcess.apply(info);
|
if (infos.size() > 0) {
|
||||||
BlocksHelper.setWithoutUpdate(world, pos, state);
|
Collections.sort(infos);
|
||||||
});
|
infos.forEach((info) -> {
|
||||||
|
BlockState state = postProcess.apply(info);
|
||||||
return mapWorld.keySet();
|
BlocksHelper.setWithoutUpdate(world, info.getPos(), state);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<BlockPos> fillRecursive(ServerWorldAccess world, BlockPos start) {
|
public void fillRecursive(ServerWorldAccess world, BlockPos start) {
|
||||||
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
|
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
|
||||||
Set<BlockPos> blocks = Sets.newHashSet();
|
Set<BlockPos> blocks = Sets.newHashSet();
|
||||||
Set<BlockPos> ends = Sets.newHashSet();
|
Set<BlockPos> ends = Sets.newHashSet();
|
||||||
|
@ -119,10 +124,17 @@ public abstract class SDF {
|
||||||
BlocksHelper.setWithoutUpdate(world, pos, state);
|
BlocksHelper.setWithoutUpdate(world, pos, state);
|
||||||
});
|
});
|
||||||
|
|
||||||
return mapWorld.keySet();
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<BlockPos> fillRecursive(StructureWorld world, BlockPos start) {
|
public void fillRecursive(StructureWorld world, BlockPos start) {
|
||||||
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
|
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
|
||||||
Set<BlockPos> blocks = Sets.newHashSet();
|
Set<BlockPos> blocks = Sets.newHashSet();
|
||||||
Set<BlockPos> ends = Sets.newHashSet();
|
Set<BlockPos> ends = Sets.newHashSet();
|
||||||
|
@ -154,11 +166,11 @@ public abstract class SDF {
|
||||||
run &= !ends.isEmpty();
|
run &= !ends.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
mapWorld.forEach((pos, info) -> {
|
List<PosInfo> infos = new ArrayList<PosInfo>(mapWorld.values());
|
||||||
|
Collections.sort(infos);
|
||||||
|
infos.forEach((info) -> {
|
||||||
BlockState state = postProcess.apply(info);
|
BlockState state = postProcess.apply(info);
|
||||||
world.setBlock(pos, state);
|
world.setBlock(info.getPos(), state);
|
||||||
});
|
});
|
||||||
|
|
||||||
return mapWorld.keySet();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package ru.betterend.world.features;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
@ -10,20 +9,17 @@ import net.minecraft.block.Material;
|
||||||
import net.minecraft.client.util.math.Vector3f;
|
import net.minecraft.client.util.math.Vector3f;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.BlockPos.Mutable;
|
import net.minecraft.util.math.BlockPos.Mutable;
|
||||||
import net.minecraft.util.math.Direction;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.world.StructureWorldAccess;
|
import net.minecraft.world.StructureWorldAccess;
|
||||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||||
import ru.betterend.blocks.BlockMossyGlowshroomCap;
|
import ru.betterend.blocks.BlockMossyGlowshroomCap;
|
||||||
import ru.betterend.blocks.basis.BlockGlowingFur;
|
|
||||||
import ru.betterend.noise.OpenSimplexNoise;
|
import ru.betterend.noise.OpenSimplexNoise;
|
||||||
import ru.betterend.registry.BlockRegistry;
|
import ru.betterend.registry.BlockRegistry;
|
||||||
import ru.betterend.registry.BlockTagRegistry;
|
import ru.betterend.registry.BlockTagRegistry;
|
||||||
import ru.betterend.util.BlocksHelper;
|
import ru.betterend.util.BlocksHelper;
|
||||||
import ru.betterend.util.MHelper;
|
import ru.betterend.util.MHelper;
|
||||||
import ru.betterend.util.SplineHelper;
|
import ru.betterend.util.SplineHelper;
|
||||||
import ru.betterend.util.sdf.PosInfo;
|
|
||||||
import ru.betterend.util.sdf.SDF;
|
import ru.betterend.util.sdf.SDF;
|
||||||
import ru.betterend.util.sdf.operator.SDFBinary;
|
import ru.betterend.util.sdf.operator.SDFBinary;
|
||||||
import ru.betterend.util.sdf.operator.SDFCoordModify;
|
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;
|
import ru.betterend.util.sdf.primitive.SDFSphere;
|
||||||
|
|
||||||
public class MossyGlowshroomFeature extends DefaultFeature {
|
public class MossyGlowshroomFeature extends DefaultFeature {
|
||||||
private static final Function<PosInfo, BlockState> POST_PROCESS;
|
|
||||||
private static final Function<BlockState, Boolean> REPLACE;
|
private static final Function<BlockState, Boolean> REPLACE;
|
||||||
private static final Vector3f CENTER = new Vector3f();
|
private static final Vector3f CENTER = new Vector3f();
|
||||||
private static final SDFBinary FUNCTION;
|
private static final SDFBinary FUNCTION;
|
||||||
|
@ -112,37 +107,32 @@ public class MossyGlowshroomFeature extends DefaultFeature {
|
||||||
ROOTS_ROT.setAngle(random.nextFloat() * MHelper.PI2);
|
ROOTS_ROT.setAngle(random.nextFloat() * MHelper.PI2);
|
||||||
FUNCTION.setSourceA(sdf);
|
FUNCTION.setSourceA(sdf);
|
||||||
|
|
||||||
Set<BlockPos> blocks = new SDFScale()
|
new SDFScale().setScale(scale)
|
||||||
.setScale(scale)
|
|
||||||
.setSource(FUNCTION)
|
.setSource(FUNCTION)
|
||||||
.setReplaceFunction(REPLACE)
|
.setReplaceFunction(REPLACE)
|
||||||
.setPostProcess(POST_PROCESS)
|
.setPostProcess((info) -> {
|
||||||
.fillRecursive(world, blockPos);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
for (BlockPos bpos: blocks) {
|
info.setState(BlockRegistry.MOSSY_GLOWSHROOM_CAP.getDefaultState());
|
||||||
BlockState state = world.getBlockState(bpos);
|
return info.getState();
|
||||||
if (state.getBlock() == BlockRegistry.MOSSY_GLOWSHROOM_HYMENOPHORE) {
|
}
|
||||||
if (world.isAir(bpos.north())) {
|
return info.getState();
|
||||||
BlocksHelper.setWithoutUpdate(world, bpos.north(), BlockRegistry.MOSSY_GLOWSHROOM_FUR.getDefaultState().with(BlockGlowingFur.FACING, Direction.NORTH));
|
})
|
||||||
}
|
.fillRecursive(world, blockPos);
|
||||||
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;
|
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 cone1 = new SDFCapedCone().setHeight(2.5F).setRadius1(1.5F).setRadius2(2.5F);
|
||||||
SDFCapedCone cone2 = new SDFCapedCone().setHeight(3F).setRadius1(2.5F).setRadius2(13F);
|
SDFCapedCone cone2 = new SDFCapedCone().setHeight(3F).setRadius1(2.5F).setRadius2(13F);
|
||||||
SDF posedCone2 = new SDFTranslate().setTranslate(0, 5, 0).setSource(cone2);
|
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 upCone = new SDFSubtraction().setSourceA(posedCone2).setSourceB(posedCone3);
|
||||||
SDF wave = new SDFFlatWave().setRaysCount(12).setIntensity(1.3F).setSource(upCone);
|
SDF wave = new SDFFlatWave().setRaysCount(12).setIntensity(1.3F).setSource(upCone);
|
||||||
SDF cones = new SDFSmoothUnion().setRadius(3).setSourceA(cone1).setSourceB(wave);
|
SDF cones = new SDFSmoothUnion().setRadius(3).setSourceA(cone1).setSourceB(wave);
|
||||||
|
@ -195,30 +185,5 @@ public class MossyGlowshroomFeature extends DefaultFeature {
|
||||||
}
|
}
|
||||||
return state.getMaterial().isReplaceable();
|
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();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@ package ru.betterend.world.structures.features;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.client.util.math.Vector3f;
|
import net.minecraft.client.util.math.Vector3f;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
|
||||||
import ru.betterend.blocks.BlockMossyGlowshroomCap;
|
import ru.betterend.blocks.BlockMossyGlowshroomCap;
|
||||||
import ru.betterend.noise.OpenSimplexNoise;
|
import ru.betterend.noise.OpenSimplexNoise;
|
||||||
import ru.betterend.registry.BlockRegistry;
|
import ru.betterend.registry.BlockRegistry;
|
||||||
|
@ -90,30 +90,28 @@ public class StructureGiantMossyGlowshroom extends SDFStructureFeature {
|
||||||
|
|
||||||
return new SDFRound().setRadius(1.5F).setSource(new SDFScale()
|
return new SDFRound().setRadius(1.5F).setSource(new SDFScale()
|
||||||
.setScale(scale)
|
.setScale(scale)
|
||||||
.setSource(function)
|
.setSource(function))
|
||||||
.setPostProcess((info) -> {
|
.setPostProcess((info) -> {
|
||||||
if (BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getState())) {
|
if (BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getState())) {
|
||||||
if (!BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp()) || !BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) {
|
if (random.nextBoolean() && info.getStateUp().getBlock() == BlockRegistry.MOSSY_GLOWSHROOM_CAP) {
|
||||||
return BlockRegistry.MOSSY_GLOWSHROOM.bark.getDefaultState();
|
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) {
|
else if (info.getState().getBlock() == BlockRegistry.MOSSY_GLOWSHROOM_CAP) {
|
||||||
if (BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) {
|
if (BlockRegistry.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown().getBlock())) {
|
||||||
return info.getState().with(BlockMossyGlowshroomCap.TRANSITION, true);
|
info.setState(BlockRegistry.MOSSY_GLOWSHROOM_CAP.getDefaultState().with(BlockMossyGlowshroomCap.TRANSITION, true));
|
||||||
|
return info.getState();
|
||||||
}
|
}
|
||||||
|
|
||||||
int air = 0;
|
info.setState(BlockRegistry.MOSSY_GLOWSHROOM_CAP.getDefaultState());
|
||||||
for (Direction dir: Direction.values()) {
|
return info.getState();
|
||||||
if (info.getState(dir).isAir()) {
|
|
||||||
air ++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (air > 4) {
|
|
||||||
info.setState(AIR);
|
|
||||||
return AIR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return info.getState();
|
return info.getState();
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue