This commit is contained in:
paulevsGitch 2020-10-06 17:24:46 +03:00
parent b47607cb6a
commit d2148baf66
5 changed files with 52 additions and 26 deletions

View file

@ -1,7 +1,6 @@
package ru.betterend.util.sdf;
import java.util.Map;
import java.util.Set;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@ -11,15 +10,15 @@ import net.minecraft.util.math.Direction;
public class PosInfo implements Comparable<PosInfo> {
private static final BlockState AIR = Blocks.AIR.getDefaultState();
private final Map<BlockPos, PosInfo> blocks;
private final Set<PosInfo> add;
private final Map<BlockPos, PosInfo> add;
private final BlockPos pos;
private BlockState state;
public static PosInfo create(Map<BlockPos, PosInfo> blocks, Set<PosInfo> add, BlockPos pos) {
public static PosInfo create(Map<BlockPos, PosInfo> blocks, Map<BlockPos, PosInfo> add, BlockPos pos) {
return new PosInfo(blocks, add, pos);
}
private PosInfo(Map<BlockPos, PosInfo> blocks, Set<PosInfo> add, BlockPos pos) {
private PosInfo(Map<BlockPos, PosInfo> blocks, Map<BlockPos, PosInfo> add, BlockPos pos) {
this.blocks = blocks;
this.add = add;
this.pos = pos;
@ -37,7 +36,8 @@ public class PosInfo implements Comparable<PosInfo> {
public BlockState getState(Direction dir) {
PosInfo info = blocks.get(pos.offset(dir));
if (info == null) {
return AIR;
info = add.get(pos.offset(dir));
return info == null ? AIR : info.getState();
}
return info.getState();
}
@ -83,6 +83,6 @@ public class PosInfo implements Comparable<PosInfo> {
public void setBlockPos(BlockPos pos, BlockState state) {
PosInfo info = new PosInfo(blocks, add, pos);
info.state = state;
add.add(info);
add.put(pos, info);
}
}

View file

@ -41,7 +41,7 @@ public abstract class SDF {
public void fillRecursive(ServerWorldAccess world, BlockPos start, int dx, int dy, int dz) {
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
Set<PosInfo> addInfo = Sets.newHashSet();
Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();
Set<BlockPos> blocks = Sets.newHashSet();
Set<BlockPos> ends = Sets.newHashSet();
Set<BlockPos> add = Sets.newHashSet();
@ -85,19 +85,22 @@ public abstract class SDF {
BlockState state = postProcess.apply(info);
BlocksHelper.setWithoutUpdate(world, info.getPos(), state);
});
}
addInfo.forEach((info) -> {
infos.clear();
infos.addAll(addInfo.values());
Collections.sort(infos);
infos.forEach((info) -> {
if (canReplace.apply(world.getBlockState(info.getPos()))) {
BlockState state = postProcess.apply(info);
BlocksHelper.setWithoutUpdate(world, info.getPos(), state);
}
});
}
}
public void fillRecursive(ServerWorldAccess world, BlockPos start) {
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
Set<PosInfo> addInfo = Sets.newHashSet();
Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();
Set<BlockPos> blocks = Sets.newHashSet();
Set<BlockPos> ends = Sets.newHashSet();
Set<BlockPos> add = Sets.newHashSet();
@ -135,19 +138,22 @@ public abstract class SDF {
BlockState state = postProcess.apply(info);
BlocksHelper.setWithoutUpdate(world, info.getPos(), state);
});
}
addInfo.forEach((info) -> {
infos.clear();
infos.addAll(addInfo.values());
Collections.sort(infos);
infos.forEach((info) -> {
if (canReplace.apply(world.getBlockState(info.getPos()))) {
BlockState state = postProcess.apply(info);
BlocksHelper.setWithoutUpdate(world, info.getPos(), state);
}
});
}
}
public void fillRecursive(StructureWorld world, BlockPos start) {
Map<BlockPos, PosInfo> mapWorld = Maps.newHashMap();
Set<PosInfo> addInfo = Sets.newHashSet();
Map<BlockPos, PosInfo> addInfo = Maps.newHashMap();
Set<BlockPos> blocks = Sets.newHashSet();
Set<BlockPos> ends = Sets.newHashSet();
Set<BlockPos> add = Sets.newHashSet();
@ -179,14 +185,16 @@ public abstract class SDF {
}
List<PosInfo> infos = new ArrayList<PosInfo>(mapWorld.values());
infos.addAll(addInfo);
Collections.sort(infos);
infos.forEach((info) -> {
BlockState state = postProcess.apply(info);
world.setBlock(info.getPos(), state);
});
addInfo.forEach((info) -> {
infos.clear();
infos.addAll(addInfo.values());
Collections.sort(infos);
infos.forEach((info) -> {
BlockState state = postProcess.apply(info);
world.setBlock(info.getPos(), state);
});

View file

@ -139,7 +139,7 @@ public class MossyGlowshroomFeature extends DefaultFeature {
}
}
if (info.getStateDown() == AIR) {
if (info.getStateDown().getBlock() != BlockRegistry.MOSSY_GLOWSHROOM_HYMENOPHORE) {
info.setBlockPos(info.getPos().down(), BlockRegistry.MOSSY_GLOWSHROOM_FUR.getDefaultState().with(BlockGlowingFur.FACING, Direction.DOWN));
}
}

View file

@ -2,6 +2,8 @@ package ru.betterend.world.structures.features;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.Heightmap;
@ -13,6 +15,8 @@ import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.StructureFeature;
public abstract class StructureFeatureBase extends StructureFeature<DefaultFeatureConfig> {
protected static final BlockState AIR = Blocks.AIR.getDefaultState();
public StructureFeatureBase() {
super(DefaultFeatureConfig.CODEC);
}

View file

@ -5,9 +5,12 @@ import java.util.Random;
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.blocks.basis.BlockGlowingFur;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.BlockRegistry;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper;
import ru.betterend.util.SplineHelper;
import ru.betterend.util.sdf.SDF;
@ -107,6 +110,17 @@ public class StructureGiantMossyGlowshroom extends SDFStructureFeature {
info.setState(BlockRegistry.MOSSY_GLOWSHROOM_CAP.getDefaultState());
return info.getState();
}
else if (info.getState().getBlock() == BlockRegistry.MOSSY_GLOWSHROOM_HYMENOPHORE) {
for (Direction dir: BlocksHelper.HORIZONTAL) {
if (info.getState(dir) == AIR) {
info.setBlockPos(info.getPos().offset(dir), BlockRegistry.MOSSY_GLOWSHROOM_FUR.getDefaultState().with(BlockGlowingFur.FACING, dir));
}
}
if (info.getStateDown().getBlock() != BlockRegistry.MOSSY_GLOWSHROOM_HYMENOPHORE) {
info.setBlockPos(info.getPos().down(), BlockRegistry.MOSSY_GLOWSHROOM_FUR.getDefaultState().with(BlockGlowingFur.FACING, Direction.DOWN));
}
}
return info.getState();
});
}