Code style changes, entities fixes

This commit is contained in:
paulevsGitch 2021-07-08 00:21:47 +03:00
parent 9d604b2d25
commit 44962e18b6
377 changed files with 5038 additions and 4914 deletions

View file

@ -1,7 +1,5 @@
package ru.betterend.world.structures;
import java.util.Random;
import net.fabricmc.fabric.api.structure.v1.FabricStructureBuilder;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceLocation;
@ -11,23 +9,25 @@ import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import ru.betterend.BetterEnd;
import java.util.Random;
public class EndStructureFeature {
private static final Random RANDOM = new Random(354);
private final StructureFeature<NoneFeatureConfiguration> structure;
private final ConfiguredStructureFeature<?, ?> featureConfigured;
private final GenerationStep.Decoration featureStep;
public EndStructureFeature(String name, StructureFeature<NoneFeatureConfiguration> structure, GenerationStep.Decoration step, int spacing, int separation) {
ResourceLocation id = BetterEnd.makeID(name);
this.featureStep = step;
this.structure = FabricStructureBuilder.create(id, structure)
.step(step)
.defaultConfig(spacing, separation, RANDOM.nextInt(8192))
.register();
.step(step)
.defaultConfig(spacing, separation, RANDOM.nextInt(8192))
.register();
this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE);
BuiltinRegistries.register(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured);
}

View file

@ -13,7 +13,6 @@ import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
@ -25,7 +24,7 @@ import ru.betterend.world.structures.piece.NBTPiece;
public class EternalPortalStructure extends FeatureBaseStructure {
private static final ResourceLocation STRUCTURE_ID = BetterEnd.makeID("portal/eternal_portal");
private static final StructureTemplate STRUCTURE = StructureHelper.readStructure(STRUCTURE_ID);
@Override
protected boolean isFeatureChunk(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed, WorldgenRandom chunkRandom, ChunkPos pos, Biome biome, ChunkPos chunkPos, NoneFeatureConfiguration featureConfig, LevelHeightAccessor levelHeightAccessor) {
long x = (long) chunkPos.x * (long) chunkPos.x;
@ -38,12 +37,12 @@ public class EternalPortalStructure extends FeatureBaseStructure {
}
return super.isFeatureChunk(chunkGenerator, biomeSource, worldSeed, chunkRandom, pos, biome, chunkPos, featureConfig, levelHeightAccessor);
}
@Override
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return PortalStructureStart::new;
}
public static class PortalStructureStart extends StructureStart<NoneFeatureConfiguration> {
public PortalStructureStart(StructureFeature<NoneFeatureConfiguration> feature, ChunkPos pos, int references, long seed) {
super(feature, pos, references, seed);
@ -52,8 +51,8 @@ public class EternalPortalStructure extends FeatureBaseStructure {
@Override
public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager structureManager, ChunkPos chunkPos, Biome biome, NoneFeatureConfiguration featureConfiguration, LevelHeightAccessor levelHeightAccessor) {
int x = chunkPos.getBlockX( MHelper.randRange(4, 12, random));
int z =chunkPos.getBlockZ( MHelper.randRange(4, 12, random));
int x = chunkPos.getBlockX(MHelper.randRange(4, 12, random));
int z = chunkPos.getBlockZ(MHelper.randRange(4, 12, random));
int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG, levelHeightAccessor);
if (y > 4) {
this.pieces.add(new NBTPiece(STRUCTURE_ID, STRUCTURE, new BlockPos(x, y - 4, z), random.nextInt(5), true, random));

View file

@ -1,7 +1,5 @@
package ru.betterend.world.structures.features;
import java.util.Random;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.LevelHeightAccessor;
import net.minecraft.world.level.biome.Biome;
@ -15,13 +13,15 @@ import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import java.util.Random;
public abstract class FeatureBaseStructure extends StructureFeature<NoneFeatureConfiguration> {
protected static final BlockState AIR = Blocks.AIR.defaultBlockState();
public FeatureBaseStructure() {
super(NoneFeatureConfiguration.CODEC);
}
@Override
protected boolean isFeatureChunk(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed, WorldgenRandom chunkRandom, ChunkPos pos, Biome biome, ChunkPos chunkPos, NoneFeatureConfiguration featureConfig, LevelHeightAccessor levelHeightAccessor) {
return getGenerationHeight(pos, chunkGenerator, levelHeightAccessor) >= 20;
@ -34,10 +34,12 @@ public abstract class FeatureBaseStructure extends StructureFeature<NoneFeatureC
int j = 5;
if (blockRotation == Rotation.CLOCKWISE_90) {
i = -5;
} else if (blockRotation == Rotation.CLOCKWISE_180) {
}
else if (blockRotation == Rotation.CLOCKWISE_180) {
i = -5;
j = -5;
} else if (blockRotation == Rotation.COUNTERCLOCKWISE_90) {
}
else if (blockRotation == Rotation.COUNTERCLOCKWISE_90) {
j = -5;
}

View file

@ -1,11 +1,6 @@
package ru.betterend.world.structures.features;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import com.mojang.math.Vector3f;
import net.minecraft.core.BlockPos;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.level.ChunkPos;
@ -15,7 +10,6 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import ru.bclib.sdf.SDF;
@ -27,12 +21,16 @@ import ru.bclib.util.MHelper;
import ru.betterend.registry.EndBlocks;
import ru.betterend.world.structures.piece.VoxelPiece;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class GiantIceStarStructure extends SDFStructureFeature {
private final float minSize = 20;
private final float maxSize = 35;
private final int minCount = 25;
private final int maxCount = 40;
@Override
protected SDF getSDF(BlockPos pos, Random random) {
float size = MHelper.randRange(minSize, maxSize, random);
@ -41,7 +39,7 @@ public class GiantIceStarStructure extends SDFStructureFeature {
SDF sdf = null;
SDF spike = new SDFCappedCone().setRadius1(3 + (size - 5) * 0.2F).setRadius2(0).setHeight(size).setBlock(EndBlocks.DENSE_SNOW);
spike = new SDFTranslate().setTranslate(0, size - 0.5F, 0).setSource(spike);
for (Vector3f point: points) {
for (Vector3f point : points) {
SDF rotated = spike;
point = MHelper.normalize(point);
float angle = MHelper.angle(Vector3f.YP, point);
@ -54,18 +52,18 @@ public class GiantIceStarStructure extends SDFStructureFeature {
}
sdf = (sdf == null) ? rotated : new SDFUnion().setSourceA(sdf).setSourceB(rotated);
}
final float ancientRadius = size * 0.7F;
final float denseRadius = size * 0.9F;
final float iceRadius = size < 7 ? size * 5 : size * 1.3F;
final float randScale = size * 0.3F;
final BlockPos center = pos;
final BlockState ice = EndBlocks.EMERALD_ICE.defaultBlockState();
final BlockState dense = EndBlocks.DENSE_EMERALD_ICE.defaultBlockState();
final BlockState ancient = EndBlocks.ANCIENT_EMERALD_ICE.defaultBlockState();
final SDF sdfCopy = sdf;
return sdf.addPostProcess((info) -> {
BlockPos bpos = info.getPos();
float px = bpos.getX() - center.getX();
@ -84,7 +82,7 @@ public class GiantIceStarStructure extends SDFStructureFeature {
return info.getState();
});
}
private List<Vector3f> getFibonacciPoints(int count) {
float max = count - 1;
List<Vector3f> result = new ArrayList<Vector3f>(count);
@ -98,12 +96,12 @@ public class GiantIceStarStructure extends SDFStructureFeature {
}
return result;
}
@Override
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return StarStructureStart::new;
}
public static class StarStructureStart extends StructureStart<NoneFeatureConfiguration> {
public StarStructureStart(StructureFeature<NoneFeatureConfiguration> feature, ChunkPos pos, int references, long seed) {
super(feature, pos, references, seed);
@ -112,9 +110,11 @@ public class GiantIceStarStructure extends SDFStructureFeature {
@Override
public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager structureManager, ChunkPos chunkPos, Biome biome, NoneFeatureConfiguration featureConfiguration, LevelHeightAccessor levelHeightAccessor) {
int x = chunkPos.getBlockX(MHelper.randRange(4, 12, random));
int z = chunkPos.getBlockZ( MHelper.randRange(4, 12, random));
int z = chunkPos.getBlockZ(MHelper.randRange(4, 12, random));
BlockPos start = new BlockPos(x, MHelper.randRange(32, 128, random), z);
VoxelPiece piece = new VoxelPiece((world) -> { ((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start); }, random.nextInt());
VoxelPiece piece = new VoxelPiece((world) -> {
((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start);
}, random.nextInt());
this.pieces.add(piece);
//this.calculateBoundingBox();

View file

@ -1,10 +1,6 @@
package ru.betterend.world.structures.features;
import java.util.List;
import java.util.Random;
import com.mojang.math.Vector3f;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import ru.bclib.sdf.SDF;
@ -29,6 +25,9 @@ import ru.betterend.blocks.basis.FurBlock;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.EndBlocks;
import java.util.List;
import java.util.Random;
public class GiantMossyGlowshroomStructure extends SDFStructureFeature {
@Override
protected SDF getSDF(BlockPos center, Random random) {
@ -39,39 +38,39 @@ public class GiantMossyGlowshroomStructure extends SDFStructureFeature {
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);
SDF innerCone = new SDFTranslate().setTranslate(0, 1.25F, 0).setSource(upCone);
innerCone = new SDFScale3D().setScale(1.2F, 1F, 1.2F).setSource(innerCone);
cones = new SDFUnion().setSourceA(cones).setSourceB(innerCone);
SDF glowCone = new SDFCappedCone().setHeight(3F).setRadius1(2F).setRadius2(12.5F);
SDFPrimitive priGlowCone = (SDFPrimitive) glowCone;
glowCone = new SDFTranslate().setTranslate(0, 4.25F, 0).setSource(glowCone);
glowCone = new SDFSubtraction().setSourceA(glowCone).setSourceB(posedCone3);
cones = new SDFUnion().setSourceA(cones).setSourceB(glowCone);
OpenSimplexNoise noise = new OpenSimplexNoise(1234);
cones = new SDFCoordModify().setFunction((pos) -> {
float dist = MHelper.length(pos.x(), pos.z());
float y = pos.y() + (float) noise.eval(pos.x() * 0.1 + center.getX(), pos.z() * 0.1 + center.getZ()) * dist * 0.3F - dist * 0.15F;
pos.set(pos.x(), y, pos.z());
}).setSource(cones);
SDFTranslate HEAD_POS = (SDFTranslate) new SDFTranslate().setSource(new SDFTranslate().setTranslate(0, 2.5F, 0).setSource(cones));
SDF roots = new SDFSphere().setRadius(4F);
SDFPrimitive primRoots = (SDFPrimitive) roots;
roots = new SDFScale3D().setScale(1, 0.7F, 1).setSource(roots);
SDFFlatWave rotRoots = (SDFFlatWave) new SDFFlatWave().setRaysCount(5).setIntensity(1.5F).setSource(roots);
SDFBinary function = new SDFSmoothUnion().setRadius(4).setSourceB(new SDFUnion().setSourceA(HEAD_POS).setSourceB(rotRoots));
cone1.setBlock(EndBlocks.MOSSY_GLOWSHROOM_CAP);
cone2.setBlock(EndBlocks.MOSSY_GLOWSHROOM_CAP);
priGlowCone.setBlock(EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE);
primRoots.setBlock(EndBlocks.MOSSY_GLOWSHROOM.bark);
float height = MHelper.randRange(10F, 25F, random);
int count = MHelper.floor(height / 4);
List<Vector3f> spline = SplineHelper.makeSpline(0, 0, 0, 0, height, 0, count);
@ -81,11 +80,11 @@ public class GiantMossyGlowshroomStructure extends SDFStructureFeature {
});
Vector3f pos = spline.get(spline.size() - 1);
float scale = MHelper.randRange(2F, 3.5F, random);
HEAD_POS.setTranslate(pos.x(), pos.y(), pos.z());
rotRoots.setAngle(random.nextFloat() * MHelper.PI2);
function.setSourceA(sdf);
return new SDFRound().setRadius(1.5F).setSource(new SDFScale()
.setScale(scale)
.setSource(function))
@ -105,17 +104,17 @@ public class GiantMossyGlowshroomStructure extends SDFStructureFeature {
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState().setValue(MossyGlowshroomCapBlock.TRANSITION, true));
return info.getState();
}
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState());
return info.getState();
}
else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE) {
for (Direction dir: BlocksHelper.HORIZONTAL) {
for (Direction dir : BlocksHelper.HORIZONTAL) {
if (info.getState(dir) == AIR) {
info.setBlockPos(info.getPos().relative(dir), EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState().setValue(FurBlock.FACING, dir));
}
}
if (info.getStateDown().getBlock() != EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE) {
info.setBlockPos(info.getPos().below(), EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState().setValue(FurBlock.FACING, Direction.DOWN));
}

View file

@ -9,7 +9,6 @@ import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import ru.bclib.util.MHelper;
@ -20,7 +19,7 @@ public class MegaLakeSmallStructure extends FeatureBaseStructure {
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return SDFStructureStart::new;
}
public static class SDFStructureStart extends StructureStart<NoneFeatureConfiguration> {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, ChunkPos chunkPos, int references, long seed) {
super(feature, chunkPos, references, seed);
@ -28,7 +27,7 @@ public class MegaLakeSmallStructure extends FeatureBaseStructure {
@Override
public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager structureManager, ChunkPos chunkPos, Biome biome, NoneFeatureConfiguration featureConfiguration, LevelHeightAccessor levelHeightAccessor) {
int x = chunkPos.getBlockX( MHelper.randRange(4, 12, random));
int x = chunkPos.getBlockX(MHelper.randRange(4, 12, random));
int z = chunkPos.getBlockZ(MHelper.randRange(4, 12, random));
int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG, levelHeightAccessor);
if (y > 5) {

View file

@ -9,7 +9,6 @@ import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import ru.bclib.util.MHelper;
@ -20,7 +19,7 @@ public class MegaLakeStructure extends FeatureBaseStructure {
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return SDFStructureStart::new;
}
public static class SDFStructureStart extends StructureStart<NoneFeatureConfiguration> {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, ChunkPos chunkPos, int references, long seed) {
super(feature, chunkPos, references, seed);

View file

@ -9,7 +9,6 @@ import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import ru.bclib.util.MHelper;
@ -20,7 +19,7 @@ public class MountainStructure extends FeatureBaseStructure {
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return SDFStructureStart::new;
}
public static class SDFStructureStart extends StructureStart<NoneFeatureConfiguration> {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, ChunkPos chunkPos, int references, long seed) {
super(feature, chunkPos, references, seed);
@ -29,7 +28,7 @@ public class MountainStructure extends FeatureBaseStructure {
@Override
public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager structureManager, ChunkPos chunkPos, Biome biome, NoneFeatureConfiguration featureConfiguration, LevelHeightAccessor levelHeightAccessor) {
int x = chunkPos.getBlockX(MHelper.randRange(4, 12, random));
int z =chunkPos.getBlockZ(MHelper.randRange(4, 12, random));
int z = chunkPos.getBlockZ(MHelper.randRange(4, 12, random));
int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG, levelHeightAccessor);
if (y > 5) {
float radius = MHelper.randRange(50, 100, random);

View file

@ -11,7 +11,6 @@ import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import ru.bclib.util.MHelper;
@ -20,12 +19,12 @@ import ru.betterend.world.structures.piece.PaintedMountainPiece;
public class PaintedMountainStructure extends FeatureBaseStructure {
private static final BlockState[] VARIANTS;
@Override
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return SDFStructureStart::new;
}
public static class SDFStructureStart extends StructureStart<NoneFeatureConfiguration> {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, ChunkPos chunkPos, int references, long seed) {
super(feature, chunkPos, references, seed);
@ -44,15 +43,15 @@ public class PaintedMountainStructure extends FeatureBaseStructure {
for (int i = 0; i < count; i++) {
slises[i] = VARIANTS[random.nextInt(VARIANTS.length)];
}
this.pieces.add(new PaintedMountainPiece(new BlockPos(x, y, z), radius, height, random, biome, slises ));
this.pieces.add(new PaintedMountainPiece(new BlockPos(x, y, z), radius, height, random, biome, slises));
}
//this.calculateBoundingBox();
}
}
static {
VARIANTS = new BlockState[] {
VARIANTS = new BlockState[]{
Blocks.END_STONE.defaultBlockState(),
EndBlocks.FLAVOLITE.stone.defaultBlockState(),
EndBlocks.VIOLECITE.stone.defaultBlockState(),

View file

@ -1,7 +1,5 @@
package ru.betterend.world.structures.features;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.level.ChunkPos;
@ -11,22 +9,23 @@ import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import ru.bclib.sdf.SDF;
import ru.bclib.util.MHelper;
import ru.betterend.world.structures.piece.VoxelPiece;
import java.util.Random;
public abstract class SDFStructureFeature extends FeatureBaseStructure {
protected abstract SDF getSDF(BlockPos pos, Random random);
@Override
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return SDFStructureStart::new;
}
public static class SDFStructureStart extends StructureStart<NoneFeatureConfiguration> {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, ChunkPos chunkPos, int references, long seed) {
super(feature, chunkPos, references, seed);
@ -39,7 +38,9 @@ public abstract class SDFStructureFeature extends FeatureBaseStructure {
int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG, levelHeightAccessor);
if (y > 5) {
BlockPos start = new BlockPos(x, y, z);
VoxelPiece piece = new VoxelPiece((world) -> { ((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start); }, random.nextInt());
VoxelPiece piece = new VoxelPiece((world) -> {
((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start);
}, random.nextInt());
this.pieces.add(piece);
}

View file

@ -14,6 +14,6 @@ public abstract class BasePiece extends StructurePiece {
super(type, tag);
fromNbt(tag);
}
protected abstract void fromNbt(CompoundTag tag);
}

View file

@ -1,7 +1,5 @@
package ru.betterend.world.structures.piece;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.nbt.CompoundTag;
@ -13,18 +11,19 @@ import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import ru.bclib.api.TagAPI;
import ru.bclib.util.BlocksHelper;
import ru.bclib.util.MHelper;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.EndStructures;
import java.util.Random;
public class CavePiece extends BasePiece {
private OpenSimplexNoise noise;
private BlockPos center;
private float radius;
public CavePiece(BlockPos center, float radius, int id) {
super(EndStructures.CAVE_PIECE, id, null);
this.center = center;
@ -37,7 +36,7 @@ public class CavePiece extends BasePiece {
super(EndStructures.CAVE_PIECE, tag);
makeBoundingBox();
}
@Override
public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
int x1 = MHelper.max(this.boundingBox.minX(), blockBox.minX());
@ -46,7 +45,7 @@ public class CavePiece extends BasePiece {
int z2 = MHelper.min(this.boundingBox.maxZ(), blockBox.maxZ());
int y1 = this.boundingBox.minY();
int y2 = this.boundingBox.maxY();
double hr = radius * 0.75;
double nr = radius * 0.25;
MutableBlockPos pos = new MutableBlockPos();
@ -79,7 +78,7 @@ public class CavePiece extends BasePiece {
}
}
}
return true;
}
@ -95,7 +94,7 @@ public class CavePiece extends BasePiece {
radius = tag.getFloat("radius");
noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ()));
}
private void makeBoundingBox() {
int minX = MHelper.floor(center.getX() - radius);
int minY = MHelper.floor(center.getY() - radius);

View file

@ -1,7 +1,5 @@
package ru.betterend.world.structures.piece;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.nbt.CompoundTag;
@ -18,16 +16,17 @@ import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import ru.bclib.api.BiomeAPI;
import ru.bclib.api.TagAPI;
import ru.bclib.util.MHelper;
import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndStructures;
import java.util.Random;
public class CrystalMountainPiece extends MountainPiece {
private BlockState top;
public CrystalMountainPiece(BlockPos center, float radius, float height, Random random, Biome biome) {
super(EndStructures.MOUNTAIN_PIECE, center, radius, height, random, biome);
top = biome.getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
@ -92,9 +91,9 @@ public class CrystalMountainPiece extends MountainPiece {
}
}
}
map = chunk.getOrCreateHeightmapUnprimed(Types.WORLD_SURFACE);
// Big crystals
int count = (map.getFirstAvailable(8, 8) - (center.getY() + 24)) / 7;
count = Mth.clamp(count, 0, 8);
@ -112,7 +111,7 @@ public class CrystalMountainPiece extends MountainPiece {
}
}
}
// Small crystals
count = (map.getFirstAvailable(8, 8) - (center.getY() + 24)) / 2;
count = Mth.clamp(count, 4, 8);
@ -130,10 +129,10 @@ public class CrystalMountainPiece extends MountainPiece {
}
}
}
return true;
}
private void crystal(ChunkAccess chunk, BlockPos pos, int radius, int height, float fill, Random random) {
MutableBlockPos mut = new MutableBlockPos();
int max = MHelper.floor(fill * radius + radius + 0.5F);

View file

@ -1,10 +1,6 @@
package ru.betterend.world.structures.piece;
import java.util.Map;
import java.util.Random;
import com.google.common.collect.Maps;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
@ -24,7 +20,6 @@ import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import net.minecraft.world.level.material.FluidState;
import ru.bclib.api.BiomeAPI;
import ru.bclib.api.TagAPI;
@ -34,6 +29,9 @@ import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndStructures;
import java.util.Map;
import java.util.Random;
public class LakePiece extends BasePiece {
private static final BlockState ENDSTONE = Blocks.END_STONE.defaultBlockState();
private static final BlockState WATER = Blocks.WATER.defaultBlockState();
@ -44,9 +42,9 @@ public class LakePiece extends BasePiece {
private float aspect;
private float depth;
private int seed;
private ResourceLocation biomeID;
public LakePiece(BlockPos center, float radius, float depth, Random random, Biome biome) {
super(EndStructures.LAKE_PIECE, random.nextInt(), null);
this.center = center;
@ -104,11 +102,11 @@ public class LakePiece extends BasePiece {
int z2 = wz - center.getZ();
float clamp = getHeightClamp(world, 8, wx, wz);
if (clamp < 0.01) continue;
double n = noise.eval(nx, nz) * 1.5 + 1.5;
double x3 = MHelper.sqr(x2 + noise.eval(nx, nz, 100) * 10);
double z3 = MHelper.sqr(z2 + noise.eval(nx, nz, -100) * 10);
for (int y = minY; y <= maxY; y++) {
mut.setY((int) (y + n));
double y2 = MHelper.sqr((y - center.getY()) * aspect);
@ -144,7 +142,7 @@ public class LakePiece extends BasePiece {
fixWater(world, chunk, mut, random, sx, sz);
return true;
}
private void fixWater(WorldGenLevel world, ChunkAccess chunk, MutableBlockPos mut, Random random, int sx, int sz) {
int minY = this.boundingBox.minY();
int maxY = this.boundingBox.maxY();
@ -159,7 +157,7 @@ public class LakePiece extends BasePiece {
mut.setY(y - 1);
if (chunk.getBlockState(mut).isAir()) {
mut.setY(y + 1);
BlockState bState = chunk.getBlockState(mut);
if (bState.isAir()) {
bState = random.nextBoolean() ? ENDSTONE : world.getBiome(mut.offset(sx, 0, sz)).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
@ -167,14 +165,14 @@ public class LakePiece extends BasePiece {
else {
bState = bState.getFluidState().isEmpty() ? ENDSTONE : EndBlocks.ENDSTONE_DUST.defaultBlockState();
}
mut.setY(y);
makeEndstonePillar(chunk, mut, bState);
}
else if (x > 1 && x < 15 && z > 1 && z < 15) {
mut.setY(y);
for (Direction dir: BlocksHelper.HORIZONTAL) {
for (Direction dir : BlocksHelper.HORIZONTAL) {
BlockPos wPos = mut.offset(dir.getStepX(), 0, dir.getStepZ());
if (chunk.getBlockState(wPos).isAir()) {
mut.setY(y + 1);
@ -199,7 +197,7 @@ public class LakePiece extends BasePiece {
}
}
}
private void makeEndstonePillar(ChunkAccess chunk, MutableBlockPos mut, BlockState terrain) {
chunk.setBlockState(mut, terrain, false);
mut.setY(mut.getY() - 1);
@ -208,27 +206,27 @@ public class LakePiece extends BasePiece {
mut.setY(mut.getY() - 1);
}
}
private int getHeight(WorldGenLevel world, BlockPos pos) {
int p = ((pos.getX() & 2047) << 11) | (pos.getZ() & 2047);
int h = heightmap.getOrDefault(p, Byte.MIN_VALUE);
if (h > Byte.MIN_VALUE) {
return h;
}
if (!BiomeAPI.getBiomeID(world.getBiome(pos)).equals(biomeID)) {
heightmap.put(p, (byte) 0);
return 0;
}
h = world.getHeight(Types.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
h = Mth.abs(h - center.getY());
h = h < 8 ? 1 : 0;
heightmap.put(p, (byte) h);
return h;
}
private float getHeightClamp(WorldGenLevel world, int radius, int posX, int posZ) {
MutableBlockPos mut = new MutableBlockPos();
int r2 = radius * radius;
@ -250,7 +248,7 @@ public class LakePiece extends BasePiece {
height /= max;
return Mth.clamp(height, 0, 1);
}
private void makeBoundingBox() {
int minX = MHelper.floor(center.getX() - radius - 8);
int minY = MHelper.floor(center.getY() - depth - 8);

View file

@ -1,10 +1,6 @@
package ru.betterend.world.structures.piece;
import java.util.Map;
import java.util.Random;
import com.google.common.collect.Maps;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.nbt.CompoundTag;
@ -17,11 +13,13 @@ import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.feature.StructurePieceType;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import ru.bclib.api.BiomeAPI;
import ru.bclib.util.MHelper;
import ru.betterend.noise.OpenSimplexNoise;
import java.util.Map;
import java.util.Random;
public abstract class MountainPiece extends BasePiece {
protected Map<Integer, Integer> heightmap = Maps.newHashMap();
protected OpenSimplexNoise noise1;
@ -33,7 +31,7 @@ public abstract class MountainPiece extends BasePiece {
protected ResourceLocation biomeID;
protected int seed1;
protected int seed2;
public MountainPiece(StructurePieceType type, BlockPos center, float radius, float height, Random random, Biome biome) {
super(type, random.nextInt(), null);
this.center = center;
@ -75,14 +73,14 @@ public abstract class MountainPiece extends BasePiece {
noise1 = new OpenSimplexNoise(seed1);
noise2 = new OpenSimplexNoise(seed2);
}
private int getHeight(WorldGenLevel world, BlockPos pos) {
int p = ((pos.getX() & 2047) << 11) | (pos.getZ() & 2047);
int h = heightmap.getOrDefault(p, Integer.MIN_VALUE);
if (h > Integer.MIN_VALUE) {
return h;
}
if (!BiomeAPI.getBiomeID(world.getBiome(pos)).equals(biomeID)) {
heightmap.put(p, -10);
return -10;
@ -94,19 +92,19 @@ public abstract class MountainPiece extends BasePiece {
heightmap.put(p, h);
return h;
}
h = MHelper.floor(noise2.eval(pos.getX() * 0.01, pos.getZ() * 0.01) * noise2.eval(pos.getX() * 0.002, pos.getZ() * 0.002) * 8 + 8);
if (h < 0) {
heightmap.put(p, 0);
return 0;
}
heightmap.put(p, h);
return h;
}
protected float getHeightClamp(WorldGenLevel world, int radius, int posX, int posZ) {
MutableBlockPos mut = new MutableBlockPos();
float height = 0;
@ -127,7 +125,7 @@ public abstract class MountainPiece extends BasePiece {
height /= max;
return Mth.clamp(height / radius, 0, 1);
}
private void makeBoundingBox() {
int minX = MHelper.floor(center.getX() - radius);
int minY = MHelper.floor(center.getY() - radius);

View file

@ -1,7 +1,5 @@
package ru.betterend.world.structures.piece;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i;
import net.minecraft.nbt.CompoundTag;
@ -15,13 +13,14 @@ import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import ru.bclib.util.MHelper;
import ru.bclib.util.StructureHelper;
import ru.betterend.registry.EndStructures;
import java.util.Random;
public class NBTPiece extends BasePiece {
private ResourceLocation structureID;
private Rotation rotation;
@ -30,7 +29,7 @@ public class NBTPiece extends BasePiece {
private BlockPos pos;
private int erosion;
private boolean cover;
public NBTPiece(ResourceLocation structureID, StructureTemplate structure, BlockPos pos, int erosion, boolean cover, Random random) {
super(EndStructures.NBT_PIECE, random.nextInt(), null);
this.structureID = structureID;
@ -72,8 +71,8 @@ public class NBTPiece extends BasePiece {
@Override
public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
BoundingBox bounds = BoundingBox.fromCorners(
new Vec3i(blockBox.minX(), this.boundingBox.minY(), blockBox.minZ()),
new Vec3i(blockBox.maxX(), this.boundingBox.maxX(), blockBox.maxZ())
new Vec3i(blockBox.minX(), this.boundingBox.minY(), blockBox.minZ()),
new Vec3i(blockBox.maxX(), this.boundingBox.maxX(), blockBox.maxZ())
);
StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror).setBoundingBox(bounds);
structure.placeInWorld(world, pos, pos, placementData, random, 2);
@ -90,7 +89,7 @@ public class NBTPiece extends BasePiece {
}
return true;
}
private void makeBoundingBox() {
this.boundingBox = StructureHelper.getStructureBounds(pos, structure, rotation, mirror);
}

View file

@ -1,7 +1,5 @@
package ru.betterend.world.structures.piece;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.nbt.CompoundTag;
@ -18,12 +16,14 @@ import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import ru.bclib.util.MHelper;
import ru.betterend.registry.EndStructures;
import java.util.Random;
public class PaintedMountainPiece extends MountainPiece {
private BlockState[] slises;
public PaintedMountainPiece(BlockPos center, float radius, float height, Random random, Biome biome, BlockState[] slises) {
super(EndStructures.PAINTED_MOUNTAIN_PIECE, center, radius, height, random, biome);
this.slises = slises;
@ -37,7 +37,7 @@ public class PaintedMountainPiece extends MountainPiece {
protected void addAdditionalSaveData(ServerLevel serverLevel, CompoundTag tag) {
super.addAdditionalSaveData(serverLevel, tag);
ListTag slise = new ListTag();
for (BlockState state: slises) {
for (BlockState state : slises) {
slise.add(NbtUtils.writeBlockState(state));
}
tag.put("slises", slise);
@ -77,7 +77,7 @@ public class PaintedMountainPiece extends MountainPiece {
int minY = map.getFirstAvailable(x, z);
pos.setY(minY - 1);
while (chunk.getBlockState(pos).isAir() && pos.getY() > 50) {
pos.setY(minY --);
pos.setY(minY--);
}
minY = pos.getY();
minY = Math.max(minY, map2.getFirstAvailable(x, z));
@ -98,7 +98,7 @@ public class PaintedMountainPiece extends MountainPiece {
}
}
}
return true;
}
}

View file

@ -1,8 +1,5 @@
package ru.betterend.world.structures.piece;
import java.util.Random;
import java.util.function.Consumer;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
@ -11,13 +8,15 @@ import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import ru.bclib.world.structures.StructureWorld;
import ru.betterend.registry.EndStructures;
import java.util.Random;
import java.util.function.Consumer;
public class VoxelPiece extends BasePiece {
private StructureWorld world;
public VoxelPiece(Consumer<StructureWorld> function, int id) {
super(EndStructures.VOXEL_PIECE, id, null);
world = new StructureWorld();