Continue mapping migration

This commit is contained in:
Aleksey 2021-04-12 21:38:22 +03:00
parent 99ade39404
commit f03fd03bd0
499 changed files with 12567 additions and 12723 deletions

View file

@ -3,31 +3,32 @@ package ru.betterend.world.structures;
import java.util.Random;
import net.fabricmc.fabric.api.structure.v1.FabricStructureBuilder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import ru.betterend.BetterEnd;
public class EndStructureFeature {
private static final Random RANDOM = new Random(354);
private final StructureFeature<NoneFeatureConfiguration> structure;
private final ConfiguredStructureFeature<?, ?> featureConfigured;
private final GenerationStep.Feature featureStep;
public EndStructureFeature(String name, StructureFeature<NoneFeatureConfiguration> structure,
GenerationStep.Feature step, int spacing, int separation) {
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();
this.structure = FabricStructureBuilder.create(id, structure)
.step(step)
.defaultConfig(spacing, separation, RANDOM.nextInt(8192))
.register();
this.featureConfigured = this.structure.configure(NoneFeatureConfiguration.DEFAULT);
BuiltinRegistries.add(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured);
this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE);
BuiltinRegistries.register(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured);
}
public StructureFeature<NoneFeatureConfiguration> getStructure() {
@ -38,7 +39,7 @@ public class EndStructureFeature {
return featureConfigured;
}
public GenerationStep.Feature getFeatureStep() {
public GenerationStep.Decoration getFeatureStep() {
return featureStep;
}
}

View file

@ -3,17 +3,16 @@ package ru.betterend.world.structures;
import java.util.Map;
import com.google.common.collect.Maps;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
public class StructureWorld {
private Map<ChunkPos, Part> parts = Maps.newHashMap();
@ -25,10 +24,9 @@ public class StructureWorld {
private int maxX = Integer.MIN_VALUE;
private int maxY = Integer.MIN_VALUE;
private int maxZ = Integer.MIN_VALUE;
public StructureWorld() {
}
public StructureWorld() {}
public StructureWorld(CompoundTag tag) {
minX = tag.getInt("minX");
maxX = tag.getInt("maxX");
@ -36,7 +34,7 @@ public class StructureWorld {
maxY = tag.getInt("maxY");
minZ = tag.getInt("minZ");
maxZ = tag.getInt("maxZ");
ListTag map = tag.getList("parts", 10);
map.forEach((element) -> {
CompoundTag compound = (CompoundTag) element;
@ -46,49 +44,43 @@ public class StructureWorld {
parts.put(new ChunkPos(x, z), part);
});
}
public void setBlock(BlockPos pos, BlockState state) {
ChunkPos cPos = new ChunkPos(pos);
if (cPos.equals(lastPos)) {
lastPart.addBlock(pos, state);
return;
}
Part part = parts.get(cPos);
if (part == null) {
part = new Part();
parts.put(cPos, part);
if (cPos.x < minX)
minX = cPos.x;
if (cPos.x > maxX)
maxX = cPos.x;
if (cPos.z < minZ)
minZ = cPos.z;
if (cPos.z > maxZ)
maxZ = cPos.z;
if (cPos.x < minX) minX = cPos.x;
if (cPos.x > maxX) maxX = cPos.x;
if (cPos.z < minZ) minZ = cPos.z;
if (cPos.z > maxZ) maxZ = cPos.z;
}
if (pos.getY() < minY)
minY = pos.getY();
if (pos.getY() > maxY)
maxY = pos.getY();
if (pos.getY() < minY) minY = pos.getY();
if (pos.getY() > maxY) maxY = pos.getY();
part.addBlock(pos, state);
lastPos = cPos;
lastPart = part;
}
public boolean placeChunk(WorldGenLevel world, ChunkPos chunkPos) {
Part part = parts.get(chunkPos);
if (part != null) {
Chunk chunk = world.getChunk(chunkPos.x, chunkPos.z);
ChunkAccess chunk = world.getChunk(chunkPos.x, chunkPos.z);
part.placeChunk(chunk);
return true;
}
return false;
}
public CompoundTag toBNT() {
CompoundTag tag = new CompoundTag();
tag.putInt("minX", minX);
@ -104,49 +96,47 @@ public class StructureWorld {
});
return tag;
}
public BlockBox getBounds() {
if (minX == Integer.MAX_VALUE || maxX == Integer.MIN_VALUE || minZ == Integer.MAX_VALUE
|| maxZ == Integer.MIN_VALUE) {
return BlockBox.empty();
public BoundingBox getBounds() {
if (minX == Integer.MAX_VALUE || maxX == Integer.MIN_VALUE || minZ == Integer.MAX_VALUE || maxZ == Integer.MIN_VALUE) {
return BoundingBox.getUnknownBox();
}
return new BlockBox(minX << 4, minY, minZ << 4, (maxX << 4) | 15, maxY, (maxZ << 4) | 15);
return new BoundingBox(minX << 4, minY, minZ << 4, (maxX << 4) | 15, maxY, (maxZ << 4) | 15);
}
private static final class Part {
Map<BlockPos, BlockState> blocks = Maps.newHashMap();
public Part() {
}
public Part() {}
public Part(CompoundTag tag) {
ListTag map = tag.getList("blocks", 10);
ListTag map2 = tag.getList("states", 10);
BlockState[] states = new BlockState[map2.size()];
for (int i = 0; i < states.length; i++) {
states[i] = NbtHelper.toBlockState((CompoundTag) map2.get(i));
states[i] = NbtUtils.readBlockState((CompoundTag) map2.get(i));
}
map.forEach((element) -> {
CompoundTag block = (CompoundTag) element;
BlockPos pos = NbtHelper.toBlockPos(block.getCompound("pos"));
BlockPos pos = NbtUtils.readBlockPos(block.getCompound("pos"));
int stateID = block.getInt("state");
BlockState state = stateID < states.length ? states[stateID] : Block.getStateFromRawId(stateID);
BlockState state = stateID < states.length ? states[stateID] : Block.stateById(stateID);
blocks.put(pos, state);
});
}
void addBlock(BlockPos pos, BlockState state) {
BlockPos inner = new BlockPos(pos.getX() & 15, pos.getY(), pos.getZ() & 15);
blocks.put(inner, state);
}
void placeChunk(Chunk chunk) {
void placeChunk(ChunkAccess chunk) {
blocks.forEach((pos, state) -> {
chunk.setBlockAndUpdate(pos, state, false);
chunk.setBlockState(pos, state, false);
});
}
CompoundTag toNBT(int x, int z) {
CompoundTag tag = new CompoundTag();
tag.putInt("x", x);
@ -155,24 +145,24 @@ public class StructureWorld {
tag.put("blocks", map);
ListTag stateMap = new ListTag();
tag.put("states", stateMap);
int[] id = new int[1];
Map<BlockState, Integer> states = Maps.newHashMap();
blocks.forEach((pos, state) -> {
int stateID = states.getOrDefault(states, -1);
if (stateID < 0) {
stateID = id[0]++;
stateID = id[0] ++;
states.put(state, stateID);
stateMap.add(NbtHelper.fromBlockState(state));
stateMap.add(NbtUtils.writeBlockState(state));
}
CompoundTag block = new CompoundTag();
block.put("pos", NbtHelper.fromBlockPos(pos));
block.put("pos", NbtUtils.writeBlockPos(pos));
block.putInt("state", stateID);
map.add(block);
});
return tag;
}
}

View file

@ -1,21 +1,21 @@
package ru.betterend.world.structures.features;
import net.minecraft.structure.Structure;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructureStart;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.world.Heightmap;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.gen.ChunkRandom;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.Heightmap;
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;
import ru.betterend.BetterEnd;
import ru.betterend.util.MHelper;
import ru.betterend.util.StructureHelper;
@ -23,46 +23,40 @@ 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 Structure STRUCTURE = StructureHelper.readStructure(STRUCTURE_ID);
private static final StructureTemplate STRUCTURE = StructureHelper.readStructure(STRUCTURE_ID);
@Override
protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed,
ChunkRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos,
NoneFeatureConfiguration featureConfig) {
protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed, WorldgenRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos, NoneFeatureConfiguration featureConfig) {
long x = chunkPos.x;
long z = chunkPos.z;
if (x * x + z * z < 10000) {
return false;
}
if (chunkGenerator.getHeight((chunkX << 4) | 8, (chunkZ << 4) | 8, Heightmap.Type.WORLD_SURFACE_WG) < 10) {
if (chunkGenerator.getBaseHeight((chunkX << 4) | 8, (chunkZ << 4) | 8, Heightmap.Types.WORLD_SURFACE_WG) < 10) {
return false;
}
return super.shouldStartAt(chunkGenerator, biomeSource, worldSeed, chunkRandom, chunkX, chunkZ, biome, chunkPos,
featureConfig);
return super.shouldStartAt(chunkGenerator, biomeSource, worldSeed, chunkRandom, chunkX, chunkZ, biome, chunkPos, featureConfig);
}
@Override
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStructureStartFactory() {
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return SDFStructureStart::new;
}
public static class SDFStructureStart extends StructureStart<NoneFeatureConfiguration> {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ,
BlockBox box, int references, long seed) {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) {
super(feature, chunkX, chunkZ, box, references, seed);
}
@Override
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG);
if (y > 4) {
this.children.add(new NBTPiece(STRUCTURE_ID, STRUCTURE, new BlockPos(x, y - 4, z), random.nextInt(5),
true, random));
this.pieces.add(new NBTPiece(STRUCTURE_ID, STRUCTURE, new BlockPos(x, y - 4, z), random.nextInt(5), true, random));
}
this.setBoundingBoxFromChildren();
this.calculateBoundingBox();
}
}
}

View file

@ -1,35 +1,32 @@
package ru.betterend.world.structures.features;
import java.util.Random;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.Heightmap;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.gen.ChunkRandom;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
public abstract class FeatureBaseStructure extends StructureFeature<NoneFeatureConfiguration> {
protected static final BlockState AIR = Blocks.AIR.defaultBlockState();
public FeatureBaseStructure() {
super(NoneFeatureConfiguration.CODEC);
}
protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed,
ChunkRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos,
NoneFeatureConfiguration featureConfig) {
protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed, WorldgenRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos, NoneFeatureConfiguration featureConfig) {
return getGenerationHeight(chunkX, chunkZ, chunkGenerator) >= 20;
}
private static int getGenerationHeight(int chunkX, int chunkZ, ChunkGenerator chunkGenerator) {
Random random = new Random((long) (chunkX + chunkZ * 10387313));
Rotation blockRotation = Rotation.random(random);
Rotation blockRotation = Rotation.getRandom(random);
int i = 5;
int j = 5;
if (blockRotation == Rotation.CLOCKWISE_90) {
@ -43,10 +40,10 @@ public abstract class FeatureBaseStructure extends StructureFeature<NoneFeatureC
int k = (chunkX << 4) + 7;
int l = (chunkZ << 4) + 7;
int m = chunkGenerator.getHeightInGround(k, l, Heightmap.Type.WORLD_SURFACE_WG);
int n = chunkGenerator.getHeightInGround(k, l + j, Heightmap.Type.WORLD_SURFACE_WG);
int o = chunkGenerator.getHeightInGround(k + i, l, Heightmap.Type.WORLD_SURFACE_WG);
int p = chunkGenerator.getHeightInGround(k + i, l + j, Heightmap.Type.WORLD_SURFACE_WG);
int m = chunkGenerator.getFirstOccupiedHeight(k, l, Heightmap.Types.WORLD_SURFACE_WG);
int n = chunkGenerator.getFirstOccupiedHeight(k, l + j, Heightmap.Types.WORLD_SURFACE_WG);
int o = chunkGenerator.getFirstOccupiedHeight(k + i, l, Heightmap.Types.WORLD_SURFACE_WG);
int p = chunkGenerator.getFirstOccupiedHeight(k + i, l + j, Heightmap.Types.WORLD_SURFACE_WG);
return Math.min(Math.min(m, n), Math.min(o, p));
}
}

View file

@ -1,20 +1,19 @@
package ru.betterend.world.structures.features;
import com.mojang.math.Vector3f;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.world.level.block.state.BlockState;
import com.mojang.math.Vector3f;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructureStart;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
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.betterend.registry.EndBlocks;
import ru.betterend.util.MHelper;
import ru.betterend.util.sdf.SDF;
@ -29,58 +28,59 @@ public class GiantIceStarStructure extends SDFStructureFeature {
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);
int count = MHelper.randRange(minCount, maxCount, random);
List<Vector3f> points = getFibonacciPoints(count);
SDF sdf = null;
SDF spike = new SDFCappedCone().setRadius1(3 + (size - 5) * 0.2F).setRadius2(0).setHeight(size)
.setBlock(EndBlocks.DENSE_SNOW);
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.POSITIVE_Y, point);
float angle = MHelper.angle(Vector3f.YP, point);
if (angle > 0.01F && angle < 3.14F) {
Vector3f axis = MHelper.normalize(MHelper.cross(Vector3f.POSITIVE_Y, point));
Vector3f axis = MHelper.normalize(MHelper.cross(Vector3f.YP, point));
rotated = new SDFRotation().setRotation(axis, angle).setSource(spike);
} else if (angle > 1) {
rotated = new SDFRotation().setRotation(Vector3f.POSITIVE_Y, (float) Math.PI).setSource(spike);
}
else if (angle > 1) {
rotated = new SDFRotation().setRotation(Vector3f.YP, (float) Math.PI).setSource(spike);
}
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();
float py = bpos.getY() - center.getY();
float pz = bpos.getZ() - center.getZ();
float distance = MHelper.length(px, py, pz) + sdfCopy.getDistance(px, py, pz) * 0.4F
+ random.nextFloat() * randScale;
float distance = MHelper.length(px, py, pz) + sdfCopy.getDistance(px, py, pz) * 0.4F + random.nextFloat() * randScale;
if (distance < ancientRadius) {
return ancient;
} else if (distance < denseRadius) {
}
else if (distance < denseRadius) {
return dense;
} else if (distance < iceRadius) {
}
else if (distance < iceRadius) {
return ice;
}
return info.getState();
});
}
private List<Vector3f> getFibonacciPoints(int count) {
float max = count - 1;
List<Vector3f> result = new ArrayList<Vector3f>(count);
@ -94,29 +94,25 @@ public class GiantIceStarStructure extends SDFStructureFeature {
}
return result;
}
@Override
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStructureStartFactory() {
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return StarStructureStart::new;
}
public static class StarStructureStart extends StructureStart<NoneFeatureConfiguration> {
public StarStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ,
BlockBox box, int references, long seed) {
public StarStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) {
super(feature, chunkX, chunkZ, box, references, seed);
}
@Override
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
int z = (chunkZ << 4) | 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());
this.children.add(piece);
this.setBoundingBoxFromChildren();
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,9 +1,8 @@
package ru.betterend.world.structures.features;
import com.mojang.math.Vector3f;
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.betterend.blocks.MossyGlowshroomCapBlock;
@ -34,49 +33,43 @@ public class GiantMossyGlowshroomStructure extends SDFStructureFeature {
SDFCappedCone cone1 = new SDFCappedCone().setHeight(2.5F).setRadius1(1.5F).setRadius2(2.5F);
SDFCappedCone cone2 = new SDFCappedCone().setHeight(3F).setRadius1(2.5F).setRadius2(13F);
SDF posedCone2 = new SDFTranslate().setTranslate(0, 5, 0).setSource(cone2);
SDF posedCone3 = new SDFTranslate().setTranslate(0, 12F, 0)
.setSource(new SDFScale().setScale(2).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);
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.getX(), pos.getZ());
float y = pos.getY()
+ (float) noise.eval(pos.getX() * 0.1 + center.getX(), pos.getZ() * 0.1 + center.getZ()) * dist
* 0.3F
- dist * 0.15F;
pos.set(pos.getX(), y, pos.getZ());
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));
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));
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);
@ -86,43 +79,43 @@ public class GiantMossyGlowshroomStructure extends SDFStructureFeature {
});
Vector3f pos = spline.get(spline.size() - 1);
float scale = MHelper.randRange(2F, 3.5F, random);
HEAD_POS.setTranslate(pos.getX(), pos.getY(), pos.getZ());
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))
return new SDFRound().setRadius(1.5F).setSource(new SDFScale()
.setScale(scale)
.setSource(function))
.addPostProcess((info) -> {
if (EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getState())) {
if (random.nextBoolean() && info.getStateUp().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_CAP) {
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState()
.with(MossyGlowshroomCapBlock.TRANSITION, true));
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState().setValue(MossyGlowshroomCapBlock.TRANSITION, true));
return info.getState();
} else if (!EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp())
|| !EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) {
}
else if (!EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp()) || !EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) {
info.setState(EndBlocks.MOSSY_GLOWSHROOM.bark.defaultBlockState());
return info.getState();
}
} else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_CAP) {
}
else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_CAP) {
if (EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown().getBlock())) {
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState()
.with(MossyGlowshroomCapBlock.TRANSITION, true));
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) {
}
else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE) {
for (Direction dir: BlocksHelper.HORIZONTAL) {
if (info.getState(dir) == AIR) {
info.setBlockPos(info.getPos().offset(dir),
EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState().with(FurBlock.FACING, dir));
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()
.with(FurBlock.FACING, Direction.DOWN));
info.setBlockPos(info.getPos().below(), EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState().setValue(FurBlock.FACING, Direction.DOWN));
}
}
return info.getState();

View file

@ -1,43 +1,41 @@
package ru.betterend.world.structures.features;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructureStart;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
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.betterend.util.MHelper;
import ru.betterend.world.structures.piece.LakePiece;
public class MegaLakeSmallStructure extends FeatureBaseStructure {
@Override
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStructureStartFactory() {
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return SDFStructureStart::new;
}
public static class SDFStructureStart extends StructureStart<NoneFeatureConfiguration> {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ,
BlockBox box, int references, long seed) {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) {
super(feature, chunkX, chunkZ, box, references, seed);
}
@Override
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG);
if (y > 5) {
float radius = MHelper.randRange(20, 40, random);
float depth = MHelper.randRange(5, 10, random);
LakePiece piece = new LakePiece(new BlockPos(x, y, z), radius, depth, random, biome);
this.children.add(piece);
this.pieces.add(piece);
}
this.setBoundingBoxFromChildren();
this.calculateBoundingBox();
}
}
}

View file

@ -1,43 +1,41 @@
package ru.betterend.world.structures.features;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructureStart;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
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.betterend.util.MHelper;
import ru.betterend.world.structures.piece.LakePiece;
public class MegaLakeStructure extends FeatureBaseStructure {
@Override
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStructureStartFactory() {
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return SDFStructureStart::new;
}
public static class SDFStructureStart extends StructureStart<NoneFeatureConfiguration> {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ,
BlockBox box, int references, long seed) {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) {
super(feature, chunkX, chunkZ, box, references, seed);
}
@Override
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG);
if (y > 5) {
float radius = MHelper.randRange(32, 64, random);
float depth = MHelper.randRange(7, 15, random);
LakePiece piece = new LakePiece(new BlockPos(x, y, z), radius, depth, random, biome);
this.children.add(piece);
this.pieces.add(piece);
}
this.setBoundingBoxFromChildren();
this.calculateBoundingBox();
}
}
}

View file

@ -1,44 +1,41 @@
package ru.betterend.world.structures.features;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructureStart;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
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.betterend.util.MHelper;
import ru.betterend.world.structures.piece.CrystalMountainPiece;
public class MountainStructure extends FeatureBaseStructure {
@Override
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStructureStartFactory() {
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return SDFStructureStart::new;
}
public static class SDFStructureStart extends StructureStart<NoneFeatureConfiguration> {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ,
BlockBox box, int references, long seed) {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) {
super(feature, chunkX, chunkZ, box, references, seed);
}
@Override
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG);
if (y > 5) {
float radius = MHelper.randRange(50, 100, random);
float height = radius * MHelper.randRange(0.8F, 1.2F, random);
CrystalMountainPiece piece = new CrystalMountainPiece(new BlockPos(x, y, z), radius, height, random,
biome);
this.children.add(piece);
CrystalMountainPiece piece = new CrystalMountainPiece(new BlockPos(x, y, z), radius, height, random, biome);
this.pieces.add(piece);
}
this.setBoundingBoxFromChildren();
this.calculateBoundingBox();
}
}
}

View file

@ -1,41 +1,39 @@
package ru.betterend.world.structures.features;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructureStart;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
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.betterend.registry.EndBlocks;
import ru.betterend.util.MHelper;
import ru.betterend.world.structures.piece.PaintedMountainPiece;
public class PaintedMountainStructure extends FeatureBaseStructure {
private static final BlockState[] VARIANTS;
@Override
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStructureStartFactory() {
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return SDFStructureStart::new;
}
public static class SDFStructureStart extends StructureStart<NoneFeatureConfiguration> {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ,
BlockBox box, int references, long seed) {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) {
super(feature, chunkX, chunkZ, box, references, seed);
}
@Override
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG);
if (y > 50) {
float radius = MHelper.randRange(50, 100, random);
float height = radius * MHelper.randRange(0.4F, 0.6F, random);
@ -44,15 +42,17 @@ public class PaintedMountainStructure extends FeatureBaseStructure {
for (int i = 0; i < count; i++) {
slises[i] = VARIANTS[random.nextInt(VARIANTS.length)];
}
this.children
.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.setBoundingBoxFromChildren();
this.calculateBoundingBox();
}
}
static {
VARIANTS = new BlockState[] { Blocks.END_STONE.defaultBlockState(),
EndBlocks.FLAVOLITE.stone.defaultBlockState(), EndBlocks.VIOLECITE.stone.defaultBlockState(), };
VARIANTS = new BlockState[] {
Blocks.END_STONE.defaultBlockState(),
EndBlocks.FLAVOLITE.stone.defaultBlockState(),
EndBlocks.VIOLECITE.stone.defaultBlockState(),
};
}
}

View file

@ -1,50 +1,45 @@
package ru.betterend.world.structures.features;
import java.util.Random;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructureStart;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
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.betterend.util.MHelper;
import ru.betterend.util.sdf.SDF;
import ru.betterend.world.structures.piece.VoxelPiece;
public abstract class SDFStructureFeature extends FeatureBaseStructure {
protected abstract SDF getSDF(BlockPos pos, Random random);
@Override
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStructureStartFactory() {
public StructureFeature.StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
return SDFStructureStart::new;
}
public static class SDFStructureStart extends StructureStart<NoneFeatureConfiguration> {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ,
BlockBox box, int references, long seed) {
public SDFStructureStart(StructureFeature<NoneFeatureConfiguration> feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) {
super(feature, chunkX, chunkZ, box, references, seed);
}
@Override
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) {
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG);
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());
this.children.add(piece);
VoxelPiece piece = new VoxelPiece((world) -> { ((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start); }, random.nextInt());
this.pieces.add(piece);
}
this.setBoundingBoxFromChildren();
this.calculateBoundingBox();
}
}
}

View file

@ -1,8 +1,8 @@
package ru.betterend.world.structures.piece;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.structure.StructurePiece;
import net.minecraft.structure.StructurePieceType;
import net.minecraft.world.level.levelgen.feature.StructurePieceType;
import net.minecraft.world.level.levelgen.structure.StructurePiece;
public abstract class BasePiece extends StructurePiece {
protected BasePiece(StructurePieceType type, int i) {

View file

@ -1,18 +1,17 @@
package ru.betterend.world.structures.piece;
import java.util.Random;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.structure.StructureManager;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.gen.StructureAccessor;
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.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.EndStructures;
import ru.betterend.registry.EndTags;
@ -23,7 +22,7 @@ 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);
this.center = center;
@ -36,17 +35,16 @@ public class CavePiece extends BasePiece {
super(EndStructures.CAVE_PIECE, tag);
makeBoundingBox();
}
@Override
public boolean place(WorldGenLevel world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random,
BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
int x1 = MHelper.max(this.boundingBox.minX, blockBox.minX);
int z1 = MHelper.max(this.boundingBox.minZ, blockBox.minZ);
int x2 = MHelper.min(this.boundingBox.maxX, blockBox.maxX);
int z2 = MHelper.min(this.boundingBox.maxZ, blockBox.maxZ);
int y1 = this.boundingBox.minY;
int y2 = this.boundingBox.maxY;
public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
int x1 = MHelper.max(this.boundingBox.x0, blockBox.x0);
int z1 = MHelper.max(this.boundingBox.z0, blockBox.z0);
int x2 = MHelper.min(this.boundingBox.x1, blockBox.x1);
int z2 = MHelper.min(this.boundingBox.z1, blockBox.z1);
int y1 = this.boundingBox.y0;
int y2 = this.boundingBox.y1;
double hr = radius * 0.75;
double nr = radius * 0.25;
MutableBlockPos pos = new MutableBlockPos();
@ -67,10 +65,11 @@ public class CavePiece extends BasePiece {
double r2 = r - 4.5;
double dist = xsq + ysq + zsq;
if (dist < r2 * r2) {
if (world.getBlockState(pos).isIn(EndTags.END_GROUND)) {
BlocksHelper.setWithoutUpdate(world, pos, AIR);
if (world.getBlockState(pos).is(EndTags.END_GROUND)) {
BlocksHelper.setWithoutUpdate(world, pos, CAVE_AIR);
}
} else if (dist < r * r) {
}
else if (dist < r * r) {
if (world.getBlockState(pos).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, pos, Blocks.END_STONE);
}
@ -78,23 +77,23 @@ public class CavePiece extends BasePiece {
}
}
}
return true;
}
@Override
protected void toNbt(CompoundTag tag) {
tag.put("center", NbtHelper.fromBlockPos(center));
protected void addAdditionalSaveData(CompoundTag tag) {
tag.put("center", NbtUtils.writeBlockPos(center));
tag.putFloat("radius", radius);
}
@Override
protected void fromNbt(CompoundTag tag) {
center = NbtHelper.toBlockPos(tag.getCompound("center"));
center = NbtUtils.readBlockPos(tag.getCompound("center"));
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);
@ -102,6 +101,6 @@ public class CavePiece extends BasePiece {
int maxX = MHelper.floor(center.getX() + radius + 1);
int maxY = MHelper.floor(center.getY() + radius + 1);
int maxZ = MHelper.floor(center.getZ() + radius + 1);
this.boundingBox = new BlockBox(minX, minY, minZ, maxX, maxY, maxZ);
this.boundingBox = new BoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
}
}

View file

@ -1,23 +1,22 @@
package ru.betterend.world.structures.piece;
import java.util.Random;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.structure.StructureManager;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Mth;
import net.minecraft.world.Heightmap;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
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.betterend.registry.EndBiomes;
import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndStructures;
@ -26,7 +25,7 @@ import ru.betterend.util.MHelper;
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();
@ -43,14 +42,13 @@ public class CrystalMountainPiece extends MountainPiece {
}
@Override
public boolean place(WorldGenLevel world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random,
BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
int sx = chunkPos.getStartX();
int sz = chunkPos.getStartZ();
public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
int sx = chunkPos.getMinBlockX();
int sz = chunkPos.getMinBlockZ();
MutableBlockPos pos = new MutableBlockPos();
Chunk chunk = world.getChunk(chunkPos.x, chunkPos.z);
Heightmap map = chunk.getHeightmap(Type.WORLD_SURFACE);
Heightmap map2 = chunk.getHeightmap(Type.WORLD_SURFACE_WG);
ChunkAccess chunk = world.getChunk(chunkPos.x, chunkPos.z);
Heightmap map = chunk.getOrCreateHeightmapUnprimed(Types.WORLD_SURFACE);
Heightmap map2 = chunk.getOrCreateHeightmapUnprimed(Types.WORLD_SURFACE_WG);
for (int x = 0; x < 16; x++) {
int px = x + sx;
int px2 = px - center.getX();
@ -64,17 +62,16 @@ public class CrystalMountainPiece extends MountainPiece {
if (dist < r2) {
pos.setZ(z);
dist = 1 - (float) Math.pow(dist / r2, 0.3);
int minY = map.get(x, z);
int minY = map.getFirstAvailable(x, z);
if (minY < 10) {
continue;
}
pos.setY(minY);
while (!chunk.getBlockState(pos).isIn(EndTags.GEN_TERRAIN) && pos.getY() > 56
&& !chunk.getBlockState(pos.below()).is(Blocks.CAVE_AIR)) {
while (!chunk.getBlockState(pos).is(EndTags.GEN_TERRAIN) && pos.getY() > 56 && !chunk.getBlockState(pos.below()).is(Blocks.CAVE_AIR)) {
pos.setY(pos.getY() - 1);
}
minY = pos.getY();
minY = Math.max(minY, map2.get(x, z));
minY = Math.max(minY, map2.getFirstAvailable(x, z));
if (minY > center.getY() - 8) {
float maxY = dist * height * getHeightClamp(world, 12, px, pz);
if (maxY > 0) {
@ -83,30 +80,28 @@ public class CrystalMountainPiece extends MountainPiece {
maxY += center.getY();
int maxYI = (int) (maxY);
int cover = maxYI - 1;
boolean needCover = (noise1.eval(px * 0.1, pz * 0.1) + MHelper.randRange(-0.4, 0.4, random)
- (center.getY() + 14) * 0.1) > 0;
boolean needCover = (noise1.eval(px * 0.1, pz * 0.1) + MHelper.randRange(-0.4, 0.4, random) - (center.getY() + 14) * 0.1) > 0;
for (int y = minY - 1; y < maxYI; y++) {
pos.setY(y);
chunk.setBlockAndUpdate(pos,
needCover && y == cover ? top : Blocks.END_STONE.defaultBlockState(), false);
chunk.setBlockState(pos, needCover && y == cover ? top : Blocks.END_STONE.defaultBlockState(), false);
}
}
}
}
}
}
map = chunk.getHeightmap(Type.WORLD_SURFACE);
map = chunk.getOrCreateHeightmapUnprimed(Types.WORLD_SURFACE);
// Big crystals
int count = (map.get(8, 8) - (center.getY() + 24)) / 7;
int count = (map.getFirstAvailable(8, 8) - (center.getY() + 24)) / 7;
count = Mth.clamp(count, 0, 8);
for (int i = 0; i < count; i++) {
int radius = MHelper.randRange(2, 3, random);
float fill = MHelper.randRange(0F, 1F, random);
int x = MHelper.randRange(radius, 15 - radius, random);
int z = MHelper.randRange(radius, 15 - radius, random);
int y = map.get(x, z);
int y = map.getFirstAvailable(x, z);
if (y > 80) {
pos.set(x, y, z);
if (chunk.getBlockState(pos.below()).is(Blocks.END_STONE)) {
@ -115,16 +110,16 @@ public class CrystalMountainPiece extends MountainPiece {
}
}
}
// Small crystals
count = (map.get(8, 8) - (center.getY() + 24)) / 2;
count = (map.getFirstAvailable(8, 8) - (center.getY() + 24)) / 2;
count = Mth.clamp(count, 4, 8);
for (int i = 0; i < count; i++) {
int radius = MHelper.randRange(1, 2, random);
float fill = random.nextBoolean() ? 0 : 1;
int x = MHelper.randRange(radius, 15 - radius, random);
int z = MHelper.randRange(radius, 15 - radius, random);
int y = map.get(x, z);
int y = map.getFirstAvailable(x, z);
if (y > 80) {
pos.set(x, y, z);
if (chunk.getBlockState(pos.below()).getBlock() == Blocks.END_STONE) {
@ -133,15 +128,15 @@ public class CrystalMountainPiece extends MountainPiece {
}
}
}
return true;
}
private void crystal(Chunk chunk, BlockPos pos, int radius, int height, float fill, Random random) {
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);
height += pos.getY();
Heightmap map = chunk.getHeightmap(Type.WORLD_SURFACE);
Heightmap map = chunk.getOrCreateHeightmapUnprimed(Types.WORLD_SURFACE);
int coefX = MHelper.randRange(-1, 1, random);
int coefZ = MHelper.randRange(-1, 1, random);
for (int x = -radius; x <= radius; x++) {
@ -153,14 +148,14 @@ public class CrystalMountainPiece extends MountainPiece {
if (mut.getZ() >= 0 && mut.getZ() < 16) {
int az = Math.abs(z);
if (ax + az < max) {
int minY = map.get(mut.getX(), mut.getZ()) - MHelper.randRange(3, 7, random);
int minY = map.getFirstAvailable(mut.getX(), mut.getZ()) - MHelper.randRange(3, 7, random);
if (pos.getY() - minY > 8) {
minY = pos.getY() - 8;
}
int h = coefX * x + coefZ * z + height;
for (int y = minY; y < h; y++) {
mut.setY(y);
chunk.setBlockAndUpdate(mut, EndBlocks.AURORA_CRYSTAL.defaultBlockState(), false);
chunk.setBlockState(mut, EndBlocks.AURORA_CRYSTAL.defaultBlockState(), false);
}
}
}

View file

@ -4,26 +4,25 @@ import java.util.Map;
import java.util.Random;
import com.google.common.collect.Maps;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.fluid.FluidState;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.structure.StructureManager;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
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.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.EndBiomes;
import ru.betterend.registry.EndBlocks;
@ -42,9 +41,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());
this.center = center;
@ -63,8 +62,8 @@ public class LakePiece extends BasePiece {
}
@Override
protected void toNbt(CompoundTag tag) {
tag.put("center", NbtHelper.fromBlockPos(center));
protected void addAdditionalSaveData(CompoundTag tag) {
tag.put("center", NbtUtils.writeBlockPos(center));
tag.putFloat("radius", radius);
tag.putFloat("depth", depth);
tag.putInt("seed", seed);
@ -73,7 +72,7 @@ public class LakePiece extends BasePiece {
@Override
protected void fromNbt(CompoundTag tag) {
center = NbtHelper.toBlockPos(tag.getCompound("center"));
center = NbtUtils.readBlockPos(tag.getCompound("center"));
radius = tag.getFloat("radius");
depth = tag.getFloat("depth");
seed = tag.getInt("seed");
@ -83,14 +82,13 @@ public class LakePiece extends BasePiece {
}
@Override
public boolean place(WorldGenLevel world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random,
BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
int minY = this.boundingBox.minY;
int maxY = this.boundingBox.maxY;
public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
int minY = this.boundingBox.y0;
int maxY = this.boundingBox.y1;
int sx = chunkPos.x << 4;
int sz = chunkPos.z << 4;
MutableBlockPos mut = new MutableBlockPos();
Chunk chunk = world.getChunk(chunkPos.x, chunkPos.z);
ChunkAccess chunk = world.getChunk(chunkPos.x, chunkPos.z);
for (int x = 0; x < 16; x++) {
mut.setX(x);
int wx = x | sx;
@ -102,13 +100,12 @@ public class LakePiece extends BasePiece {
double nz = wz * 0.1;
int z2 = wz - center.getZ();
float clamp = getHeightClamp(world, 8, wx, wz);
if (clamp < 0.01)
continue;
if (clamp < 0.01) continue;
double n = noise.eval(nx, nz) * 1.5 + 1.5;
double x3 = MHelper.pow2(x2 + noise.eval(nx, nz, 100) * 10);
double z3 = MHelper.pow2(z2 + noise.eval(nx, nz, -100) * 10);
for (int y = minY; y <= maxY; y++) {
mut.setY((int) (y + n));
double y2 = MHelper.pow2((y - center.getY()) * aspect);
@ -119,24 +116,23 @@ public class LakePiece extends BasePiece {
double dist = x3 + y2 + z3;
if (dist < r2) {
BlockState state = chunk.getBlockState(mut);
if (state.isIn(EndTags.GEN_TERRAIN) || state.isAir()) {
state = mut.getY() < center.getY() ? WATER : AIR;
chunk.setBlockAndUpdate(mut, state, false);
if (state.is(EndTags.GEN_TERRAIN) || state.isAir()) {
state = mut.getY() < center.getY() ? WATER : CAVE_AIR;
chunk.setBlockState(mut, state, false);
}
} else if (dist <= r3 && mut.getY() < center.getY()) {
}
else if (dist <= r3 && mut.getY() < center.getY()) {
BlockState state = chunk.getBlockState(mut);
BlockPos worldPos = mut.add(sx, 0, sz);
if (!state.isFullCube(world, worldPos) && !state.isSolidBlock(world, worldPos)) {
state = chunk.getBlockState(mut.up());
BlockPos worldPos = mut.offset(sx, 0, sz);
if (!state.isCollisionShapeFullBlock(world, worldPos) && !state.isRedstoneConductor(world, worldPos)) {
state = chunk.getBlockState(mut.above());
if (state.isAir()) {
state = random.nextBoolean() ? ENDSTONE
: world.getBiome(worldPos).getGenerationSettings().getSurfaceBuilderConfig()
.getTopMaterial();
} else {
state = state.getFluidState().isEmpty() ? ENDSTONE
: EndBlocks.ENDSTONE_DUST.defaultBlockState();
state = random.nextBoolean() ? ENDSTONE : world.getBiome(worldPos).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
}
chunk.setBlockAndUpdate(mut, state, false);
else {
state = state.getFluidState().isEmpty() ? ENDSTONE : EndBlocks.ENDSTONE_DUST.defaultBlockState();
}
chunk.setBlockState(mut, state, false);
}
}
}
@ -145,10 +141,10 @@ public class LakePiece extends BasePiece {
fixWater(world, chunk, mut, random, sx, sz);
return true;
}
private void fixWater(WorldGenLevel world, Chunk chunk, MutableBlockPos mut, Random random, int sx, int sz) {
int minY = this.boundingBox.minY;
int maxY = this.boundingBox.maxY;
private void fixWater(WorldGenLevel world, ChunkAccess chunk, MutableBlockPos mut, Random random, int sx, int sz) {
int minY = this.boundingBox.y0;
int maxY = this.boundingBox.y1;
for (int x = 0; x < 16; x++) {
mut.setX(x);
for (int z = 0; z < 16; z++) {
@ -160,78 +156,76 @@ 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.add(sx, 0, sz)).getGenerationSettings()
.getSurfaceBuilderConfig().getTopMaterial();
} else {
bState = bState.getFluidState().isEmpty() ? ENDSTONE
: EndBlocks.ENDSTONE_DUST.defaultBlockState();
bState = random.nextBoolean() ? ENDSTONE : world.getBiome(mut.offset(sx, 0, sz)).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
}
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) {
}
else if (x > 1 && x < 15 && z > 1 && z < 15) {
mut.setY(y);
for (Direction dir : BlocksHelper.HORIZONTAL) {
BlockPos wPos = mut.add(dir.getOffsetX(), 0, dir.getOffsetZ());
for (Direction dir: BlocksHelper.HORIZONTAL) {
BlockPos wPos = mut.offset(dir.getStepX(), 0, dir.getStepZ());
if (chunk.getBlockState(wPos).isAir()) {
mut.setY(y + 1);
BlockState bState = chunk.getBlockState(mut);
if (bState.isAir()) {
bState = random.nextBoolean() ? ENDSTONE
: world.getBiome(mut.add(sx, 0, sz)).getGenerationSettings()
.getSurfaceBuilderConfig().getTopMaterial();
} else {
bState = bState.getFluidState().isEmpty() ? ENDSTONE
: EndBlocks.ENDSTONE_DUST.defaultBlockState();
bState = random.nextBoolean() ? ENDSTONE : world.getBiome(mut.offset(sx, 0, sz)).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
}
else {
bState = bState.getFluidState().isEmpty() ? ENDSTONE : EndBlocks.ENDSTONE_DUST.defaultBlockState();
}
mut.setY(y);
makeEndstonePillar(chunk, mut, bState);
break;
}
}
} else if (chunk.getBlockState(mut.move(Direction.UP)).isAir()) {
chunk.getFluidTickScheduler().schedule(mut.move(Direction.DOWN), state.getFluid(), 0);
}
else if (chunk.getBlockState(mut.move(Direction.UP)).isAir()) {
chunk.getLiquidTicks().scheduleTick(mut.move(Direction.DOWN), state.getType(), 0);
}
}
}
}
}
}
private void makeEndstonePillar(Chunk chunk, MutableBlockPos mut, BlockState terrain) {
chunk.setBlockAndUpdate(mut, terrain, false);
private void makeEndstonePillar(ChunkAccess chunk, MutableBlockPos mut, BlockState terrain) {
chunk.setBlockState(mut, terrain, false);
mut.setY(mut.getY() - 1);
while (!chunk.getFluidState(mut).isEmpty()) {
chunk.setBlockAndUpdate(mut, ENDSTONE, false);
chunk.setBlockState(mut, ENDSTONE, false);
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 (!EndBiomes.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;
@ -253,7 +247,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);
@ -261,6 +255,6 @@ public class LakePiece extends BasePiece {
int maxX = MHelper.floor(center.getX() + radius + 8);
int maxY = MHelper.floor(center.getY() + depth);
int maxZ = MHelper.floor(center.getZ() + radius + 8);
this.boundingBox = new BlockBox(minX, minY, minZ, maxX, maxY, maxZ);
this.boundingBox = new BoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
}
}

View file

@ -4,19 +4,18 @@ import java.util.Map;
import java.util.Random;
import com.google.common.collect.Maps;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructurePieceType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.world.level.WorldGenLevel;
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.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.EndBiomes;
import ru.betterend.util.MHelper;
@ -32,9 +31,8 @@ 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) {
public MountainPiece(StructurePieceType type, BlockPos center, float radius, float height, Random random, Biome biome) {
super(type, random.nextInt());
this.center = center;
this.radius = radius;
@ -54,8 +52,8 @@ public abstract class MountainPiece extends BasePiece {
}
@Override
protected void toNbt(CompoundTag tag) {
tag.put("center", NbtHelper.fromBlockPos(center));
protected void addAdditionalSaveData(CompoundTag tag) {
tag.put("center", NbtUtils.writeBlockPos(center));
tag.putFloat("radius", radius);
tag.putFloat("height", height);
tag.putString("biome", biomeID.toString());
@ -65,7 +63,7 @@ public abstract class MountainPiece extends BasePiece {
@Override
protected void fromNbt(CompoundTag tag) {
center = NbtHelper.toBlockPos(tag.getCompound("center"));
center = NbtUtils.readBlockPos(tag.getCompound("center"));
radius = tag.getFloat("radius");
height = tag.getFloat("height");
biomeID = new ResourceLocation(tag.getString("biome"));
@ -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 (!EndBiomes.getBiomeID(world.getBiome(pos)).equals(biomeID)) {
heightmap.put(p, -10);
return -10;
@ -94,20 +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);
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;
@ -128,12 +125,12 @@ 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 minZ = MHelper.floor(center.getZ() - radius);
int maxX = MHelper.floor(center.getX() + radius + 1);
int maxZ = MHelper.floor(center.getZ() + radius + 1);
this.boundingBox = new BlockBox(minX, minZ, maxX, maxZ);
this.boundingBox = new BoundingBox(minX, minZ, maxX, maxZ);
}
}

View file

@ -1,21 +1,20 @@
package ru.betterend.world.structures.piece;
import java.util.Random;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.structure.Structure;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructurePlacementData;
import net.minecraft.util.BlockMirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.gen.StructureAccessor;
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.betterend.registry.EndStructures;
import ru.betterend.util.MHelper;
import ru.betterend.util.StructureHelper;
@ -23,19 +22,18 @@ import ru.betterend.util.StructureHelper;
public class NBTPiece extends BasePiece {
private ResourceLocation structureID;
private Rotation rotation;
private BlockMirror mirror;
private Structure structure;
private Mirror mirror;
private StructureTemplate structure;
private BlockPos pos;
private int erosion;
private boolean cover;
public NBTPiece(ResourceLocation structureID, Structure structure, BlockPos pos, int erosion, boolean cover,
Random random) {
public NBTPiece(ResourceLocation structureID, StructureTemplate structure, BlockPos pos, int erosion, boolean cover, Random random) {
super(EndStructures.NBT_PIECE, random.nextInt());
this.structureID = structureID;
this.structure = structure;
this.rotation = Rotation.random(random);
this.mirror = BlockMirror.values()[random.nextInt(3)];
this.rotation = Rotation.getRandom(random);
this.mirror = Mirror.values()[random.nextInt(3)];
this.pos = StructureHelper.offsetPos(pos, structure, rotation, mirror);
this.erosion = erosion;
this.cover = cover;
@ -48,12 +46,12 @@ public class NBTPiece extends BasePiece {
}
@Override
protected void toNbt(CompoundTag tag) {
protected void addAdditionalSaveData(CompoundTag tag) {
tag.putString("id", structureID.toString());
tag.putInt("rotation", rotation.ordinal());
tag.putInt("mirror", mirror.ordinal());
tag.putInt("erosion", erosion);
tag.put("pos", NbtHelper.fromBlockPos(pos));
tag.put("pos", NbtUtils.writeBlockPos(pos));
tag.putBoolean("cover", cover);
}
@ -61,27 +59,25 @@ public class NBTPiece extends BasePiece {
protected void fromNbt(CompoundTag tag) {
structureID = new ResourceLocation(tag.getString("id"));
rotation = Rotation.values()[tag.getInt("rotation")];
mirror = BlockMirror.values()[tag.getInt("mirror")];
mirror = Mirror.values()[tag.getInt("mirror")];
erosion = tag.getInt("erosion");
pos = NbtHelper.toBlockPos(tag.getCompound("pos"));
pos = NbtUtils.readBlockPos(tag.getCompound("pos"));
cover = tag.getBoolean("cover");
structure = StructureHelper.readStructure(structureID);
}
@Override
public boolean place(WorldGenLevel world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random,
BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
BlockBox bounds = new BlockBox(blockBox);
bounds.maxY = this.boundingBox.maxY;
bounds.minY = this.boundingBox.minY;
StructurePlacementData placementData = new StructurePlacementData().setRotation(rotation).setMirror(mirror)
.setBoundingBox(bounds);
structure.place(world, pos, placementData, random);
public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
BoundingBox bounds = new BoundingBox(blockBox);
bounds.y1 = this.boundingBox.y1;
bounds.y0 = this.boundingBox.y0;
StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror).setBoundingBox(bounds);
structure.placeInWorldChunk(world, pos, placementData, random);
if (erosion > 0) {
bounds.maxX = MHelper.min(bounds.maxX, boundingBox.maxX);
bounds.minX = MHelper.max(bounds.minX, boundingBox.minX);
bounds.maxZ = MHelper.min(bounds.maxZ, boundingBox.maxZ);
bounds.minZ = MHelper.max(bounds.minZ, boundingBox.minZ);
bounds.x1 = MHelper.min(bounds.x1, boundingBox.x1);
bounds.x0 = MHelper.max(bounds.x0, boundingBox.x0);
bounds.z1 = MHelper.min(bounds.z1, boundingBox.z1);
bounds.z0 = MHelper.max(bounds.z0, boundingBox.z0);
StructureHelper.erode(world, bounds, erosion, random);
}
if (cover) {
@ -89,7 +85,7 @@ public class NBTPiece extends BasePiece {
}
return true;
}
private void makeBoundingBox() {
this.boundingBox = StructureHelper.getStructureBounds(pos, structure, rotation, mirror);
}

View file

@ -1,31 +1,28 @@
package ru.betterend.world.structures.piece;
import java.util.Random;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.structure.StructureManager;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.Heightmap;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
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.betterend.registry.EndStructures;
import ru.betterend.util.MHelper;
public class PaintedMountainPiece extends MountainPiece {
private BlockState[] slises;
public PaintedMountainPiece(BlockPos center, float radius, float height, Random random, Biome biome,
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;
}
@ -35,11 +32,11 @@ public class PaintedMountainPiece extends MountainPiece {
}
@Override
protected void toNbt(CompoundTag tag) {
super.toNbt(tag);
protected void addAdditionalSaveData(CompoundTag tag) {
super.addAdditionalSaveData(tag);
ListTag slise = new ListTag();
for (BlockState state : slises) {
slise.add(NbtHelper.fromBlockState(state));
for (BlockState state: slises) {
slise.add(NbtUtils.writeBlockState(state));
}
tag.put("slises", slise);
}
@ -50,19 +47,18 @@ public class PaintedMountainPiece extends MountainPiece {
ListTag slise = tag.getList("slises", 10);
slises = new BlockState[slise.size()];
for (int i = 0; i < slises.length; i++) {
slises[i] = NbtHelper.toBlockState(slise.getCompound(i));
slises[i] = NbtUtils.readBlockState(slise.getCompound(i));
}
}
@Override
public boolean place(WorldGenLevel world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random,
BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
int sx = chunkPos.getStartX();
int sz = chunkPos.getStartZ();
public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
int sx = chunkPos.getMinBlockX();
int sz = chunkPos.getMinBlockZ();
MutableBlockPos pos = new MutableBlockPos();
Chunk chunk = world.getChunk(chunkPos.x, chunkPos.z);
Heightmap map = chunk.getHeightmap(Type.WORLD_SURFACE);
Heightmap map2 = chunk.getHeightmap(Type.WORLD_SURFACE_WG);
ChunkAccess chunk = world.getChunk(chunkPos.x, chunkPos.z);
Heightmap map = chunk.getOrCreateHeightmapUnprimed(Types.WORLD_SURFACE);
Heightmap map2 = chunk.getOrCreateHeightmapUnprimed(Types.WORLD_SURFACE_WG);
for (int x = 0; x < 16; x++) {
int px = x + sx;
int px2 = px - center.getX();
@ -76,32 +72,31 @@ public class PaintedMountainPiece extends MountainPiece {
if (dist < r2) {
pos.setZ(z);
dist = 1 - dist / r2;
int minY = map.get(x, z);
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.get(x, z));
minY = Math.max(minY, map2.getFirstAvailable(x, z));
if (minY > center.getY() - 8) {
float maxY = dist * height * getHeightClamp(world, 10, px, pz);
if (maxY > 0) {
maxY *= (float) noise1.eval(px * 0.05, pz * 0.05) * 0.3F + 0.7F;
maxY *= (float) noise1.eval(px * 0.1, pz * 0.1) * 0.1F + 0.9F;
maxY += center.getY();
float offset = (float) (noise1.eval(px * 0.07, pz * 0.07) * 5
+ noise1.eval(px * 0.2, pz * 0.2) * 2 + 7);
float offset = (float) (noise1.eval(px * 0.07, pz * 0.07) * 5 + noise1.eval(px * 0.2, pz * 0.2) * 2 + 7);
for (int y = minY - 1; y < maxY; y++) {
pos.setY(y);
int index = MHelper.floor((y + offset) * 0.65F) % slises.length;
chunk.setBlockAndUpdate(pos, slises[index], false);
chunk.setBlockState(pos, slises[index], false);
}
}
}
}
}
}
return true;
}
}

View file

@ -2,21 +2,20 @@ package ru.betterend.world.structures.piece;
import java.util.Random;
import java.util.function.Consumer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.structure.StructureManager;
import net.minecraft.util.math.BlockBox;
import net.minecraft.core.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.gen.StructureAccessor;
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.betterend.registry.EndStructures;
import ru.betterend.world.structures.StructureWorld;
public class VoxelPiece extends BasePiece {
private StructureWorld world;
public VoxelPiece(Consumer<StructureWorld> function, int id) {
super(EndStructures.VOXEL_PIECE, id);
world = new StructureWorld();
@ -30,7 +29,7 @@ public class VoxelPiece extends BasePiece {
}
@Override
protected void toNbt(CompoundTag tag) {
protected void addAdditionalSaveData(CompoundTag tag) {
tag.put("world", world.toBNT());
}
@ -40,8 +39,7 @@ public class VoxelPiece extends BasePiece {
}
@Override
public boolean place(WorldGenLevel world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random,
BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
this.world.placeChunk(world, chunkPos);
return true;
}