Start migration
This commit is contained in:
parent
6630ce0cab
commit
47ed597358
491 changed files with 12045 additions and 11953 deletions
|
@ -2,13 +2,13 @@ package ru.betterend.world.structures.piece;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
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.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.Mutable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
|
@ -23,7 +23,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,19 +36,20 @@ public class CavePiece extends BasePiece {
|
|||
super(EndStructures.CAVE_PIECE, tag);
|
||||
makeBoundingBox();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
public boolean generate(StructureWorldAccess 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;
|
||||
|
||||
|
||||
double hr = radius * 0.75;
|
||||
double nr = radius * 0.25;
|
||||
Mutable pos = new Mutable();
|
||||
MutableBlockPos pos = new MutableBlockPos();
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
int xsq = x - center.getX();
|
||||
xsq *= xsq;
|
||||
|
@ -69,8 +70,7 @@ public class CavePiece extends BasePiece {
|
|||
if (world.getBlockState(pos).isIn(EndTags.END_GROUND)) {
|
||||
BlocksHelper.setWithoutUpdate(world, pos, 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,7 +78,7 @@ public class CavePiece extends BasePiece {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -94,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);
|
||||
|
|
|
@ -2,15 +2,15 @@ package ru.betterend.world.structures.piece;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
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.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.Mutable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
|
@ -26,7 +26,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().getSurfaceConfig().getTopMaterial();
|
||||
|
@ -43,10 +43,11 @@ public class CrystalMountainPiece extends MountainPiece {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator,
|
||||
Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
int sx = chunkPos.getStartX();
|
||||
int sz = chunkPos.getStartZ();
|
||||
Mutable pos = new Mutable();
|
||||
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);
|
||||
|
@ -68,7 +69,8 @@ public class CrystalMountainPiece extends MountainPiece {
|
|||
continue;
|
||||
}
|
||||
pos.setY(minY);
|
||||
while (!chunk.getBlockState(pos).isIn(EndTags.GEN_TERRAIN) && pos.getY() > 56 && !chunk.getBlockState(pos.down()).isOf(Blocks.CAVE_AIR)) {
|
||||
while (!chunk.getBlockState(pos).isIn(EndTags.GEN_TERRAIN) && pos.getY() > 56
|
||||
&& !chunk.getBlockState(pos.below()).is(Blocks.CAVE_AIR)) {
|
||||
pos.setY(pos.getY() - 1);
|
||||
}
|
||||
minY = pos.getY();
|
||||
|
@ -81,22 +83,24 @@ 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.setBlockState(pos, needCover && y == cover ? top : Blocks.END_STONE.getDefaultState(), false);
|
||||
chunk.setBlockAndUpdate(pos,
|
||||
needCover && y == cover ? top : Blocks.END_STONE.defaultBlockState(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
map = chunk.getHeightmap(Type.WORLD_SURFACE);
|
||||
|
||||
|
||||
// Big crystals
|
||||
int count = (map.get(8, 8) - (center.getY() + 24)) / 7;
|
||||
count = MathHelper.clamp(count, 0, 8);
|
||||
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);
|
||||
|
@ -105,16 +109,16 @@ public class CrystalMountainPiece extends MountainPiece {
|
|||
int y = map.get(x, z);
|
||||
if (y > 80) {
|
||||
pos.set(x, y, z);
|
||||
if (chunk.getBlockState(pos.down()).isOf(Blocks.END_STONE)) {
|
||||
if (chunk.getBlockState(pos.below()).is(Blocks.END_STONE)) {
|
||||
int height = MHelper.floor(radius * MHelper.randRange(1.5F, 3F, random) + (y - 80) * 0.3F);
|
||||
crystal(chunk, pos, radius, height, fill, random);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Small crystals
|
||||
count = (map.get(8, 8) - (center.getY() + 24)) / 2;
|
||||
count = MathHelper.clamp(count, 4, 8);
|
||||
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;
|
||||
|
@ -123,18 +127,18 @@ public class CrystalMountainPiece extends MountainPiece {
|
|||
int y = map.get(x, z);
|
||||
if (y > 80) {
|
||||
pos.set(x, y, z);
|
||||
if (chunk.getBlockState(pos.down()).getBlock() == Blocks.END_STONE) {
|
||||
if (chunk.getBlockState(pos.below()).getBlock() == Blocks.END_STONE) {
|
||||
int height = MHelper.floor(radius * MHelper.randRange(1.5F, 3F, random) + (y - 80) * 0.3F);
|
||||
crystal(chunk, pos, radius, height, fill, random);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void crystal(Chunk chunk, BlockPos pos, int radius, int height, float fill, Random random) {
|
||||
Mutable mut = new Mutable();
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
int max = MHelper.floor(fill * radius + radius + 0.5F);
|
||||
height += pos.getY();
|
||||
Heightmap map = chunk.getHeightmap(Type.WORLD_SURFACE);
|
||||
|
@ -156,7 +160,7 @@ public class CrystalMountainPiece extends MountainPiece {
|
|||
int h = coefX * x + coefZ * z + height;
|
||||
for (int y = minY; y < h; y++) {
|
||||
mut.setY(y);
|
||||
chunk.setBlockState(mut, EndBlocks.AURORA_CRYSTAL.getDefaultState(), false);
|
||||
chunk.setBlockAndUpdate(mut, EndBlocks.AURORA_CRYSTAL.defaultBlockState(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,19 +5,19 @@ import java.util.Random;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
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.util.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.Mutable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
@ -33,8 +33,8 @@ import ru.betterend.util.BlocksHelper;
|
|||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class LakePiece extends BasePiece {
|
||||
private static final BlockState ENDSTONE = Blocks.END_STONE.getDefaultState();
|
||||
private static final BlockState WATER = Blocks.WATER.getDefaultState();
|
||||
private static final BlockState ENDSTONE = Blocks.END_STONE.defaultBlockState();
|
||||
private static final BlockState WATER = Blocks.WATER.defaultBlockState();
|
||||
private Map<Integer, Byte> heightmap = Maps.newHashMap();
|
||||
private OpenSimplexNoise noise;
|
||||
private BlockPos center;
|
||||
|
@ -42,9 +42,9 @@ public class LakePiece extends BasePiece {
|
|||
private float aspect;
|
||||
private float depth;
|
||||
private int seed;
|
||||
|
||||
private Identifier biomeID;
|
||||
|
||||
|
||||
private ResourceLocation biomeID;
|
||||
|
||||
public LakePiece(BlockPos center, float radius, float depth, Random random, Biome biome) {
|
||||
super(EndStructures.LAKE_PIECE, random.nextInt());
|
||||
this.center = center;
|
||||
|
@ -79,16 +79,17 @@ public class LakePiece extends BasePiece {
|
|||
seed = tag.getInt("seed");
|
||||
noise = new OpenSimplexNoise(seed);
|
||||
aspect = radius / depth;
|
||||
biomeID = new Identifier(tag.getString("biome"));
|
||||
biomeID = new ResourceLocation(tag.getString("biome"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator,
|
||||
Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
int minY = this.boundingBox.minY;
|
||||
int maxY = this.boundingBox.maxY;
|
||||
int sx = chunkPos.x << 4;
|
||||
int sz = chunkPos.z << 4;
|
||||
Mutable mut = new Mutable();
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
Chunk chunk = world.getChunk(chunkPos.x, chunkPos.z);
|
||||
for (int x = 0; x < 16; x++) {
|
||||
mut.setX(x);
|
||||
|
@ -101,12 +102,13 @@ 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,21 +121,22 @@ public class LakePiece extends BasePiece {
|
|||
BlockState state = chunk.getBlockState(mut);
|
||||
if (state.isIn(EndTags.GEN_TERRAIN) || state.isAir()) {
|
||||
state = mut.getY() < center.getY() ? WATER : AIR;
|
||||
chunk.setBlockState(mut, state, false);
|
||||
chunk.setBlockAndUpdate(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());
|
||||
if (state.isAir()) {
|
||||
state = random.nextBoolean() ? ENDSTONE : world.getBiome(worldPos).getGenerationSettings().getSurfaceConfig().getTopMaterial();
|
||||
state = random.nextBoolean() ? ENDSTONE
|
||||
: world.getBiome(worldPos).getGenerationSettings().getSurfaceConfig()
|
||||
.getTopMaterial();
|
||||
} else {
|
||||
state = state.getFluidState().isEmpty() ? ENDSTONE
|
||||
: EndBlocks.ENDSTONE_DUST.defaultBlockState();
|
||||
}
|
||||
else {
|
||||
state = state.getFluidState().isEmpty() ? ENDSTONE : EndBlocks.ENDSTONE_DUST.getDefaultState();
|
||||
}
|
||||
chunk.setBlockState(mut, state, false);
|
||||
chunk.setBlockAndUpdate(mut, state, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,8 +145,8 @@ public class LakePiece extends BasePiece {
|
|||
fixWater(world, chunk, mut, random, sx, sz);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void fixWater(StructureWorldAccess world, Chunk chunk, Mutable mut, Random random, int sx, int sz) {
|
||||
|
||||
private void fixWater(StructureWorldAccess world, Chunk chunk, MutableBlockPos mut, Random random, int sx, int sz) {
|
||||
int minY = this.boundingBox.minY;
|
||||
int maxY = this.boundingBox.maxY;
|
||||
for (int x = 0; x < 16; x++) {
|
||||
|
@ -157,39 +160,41 @@ 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().getSurfaceConfig().getTopMaterial();
|
||||
bState = random.nextBoolean() ? ENDSTONE
|
||||
: world.getBiome(mut.add(sx, 0, sz)).getGenerationSettings().getSurfaceConfig()
|
||||
.getTopMaterial();
|
||||
} else {
|
||||
bState = bState.getFluidState().isEmpty() ? ENDSTONE
|
||||
: EndBlocks.ENDSTONE_DUST.defaultBlockState();
|
||||
}
|
||||
else {
|
||||
bState = bState.getFluidState().isEmpty() ? ENDSTONE : EndBlocks.ENDSTONE_DUST.getDefaultState();
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
for (Direction dir : BlocksHelper.HORIZONTAL) {
|
||||
BlockPos wPos = mut.add(dir.getOffsetX(), 0, dir.getOffsetZ());
|
||||
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().getSurfaceConfig().getTopMaterial();
|
||||
}
|
||||
else {
|
||||
bState = bState.getFluidState().isEmpty() ? ENDSTONE : EndBlocks.ENDSTONE_DUST.getDefaultState();
|
||||
bState = random.nextBoolean() ? ENDSTONE
|
||||
: world.getBiome(mut.add(sx, 0, sz)).getGenerationSettings()
|
||||
.getSurfaceConfig().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()) {
|
||||
} else if (chunk.getBlockState(mut.move(Direction.UP)).isAir()) {
|
||||
chunk.getFluidTickScheduler().schedule(mut.move(Direction.DOWN), state.getFluid(), 0);
|
||||
}
|
||||
}
|
||||
|
@ -197,38 +202,38 @@ public class LakePiece extends BasePiece {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void makeEndstonePillar(Chunk chunk, Mutable mut, BlockState terrain) {
|
||||
chunk.setBlockState(mut, terrain, false);
|
||||
|
||||
private void makeEndstonePillar(Chunk chunk, MutableBlockPos mut, BlockState terrain) {
|
||||
chunk.setBlockAndUpdate(mut, terrain, false);
|
||||
mut.setY(mut.getY() - 1);
|
||||
while (!chunk.getFluidState(mut).isEmpty()) {
|
||||
chunk.setBlockState(mut, ENDSTONE, false);
|
||||
chunk.setBlockAndUpdate(mut, ENDSTONE, false);
|
||||
mut.setY(mut.getY() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int getHeight(StructureWorldAccess 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.getTopY(Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
|
||||
h = MathHelper.abs(h - center.getY());
|
||||
h = Mth.abs(h - center.getY());
|
||||
h = h < 8 ? 1 : 0;
|
||||
|
||||
|
||||
heightmap.put(p, (byte) h);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
private float getHeightClamp(StructureWorldAccess world, int radius, int posX, int posZ) {
|
||||
Mutable mut = new Mutable();
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
int r2 = radius * radius;
|
||||
float height = 0;
|
||||
float max = 0;
|
||||
|
@ -246,9 +251,9 @@ public class LakePiece extends BasePiece {
|
|||
}
|
||||
}
|
||||
height /= max;
|
||||
return MathHelper.clamp(height, 0, 1);
|
||||
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);
|
||||
|
|
|
@ -9,11 +9,11 @@ import net.minecraft.nbt.CompoundTag;
|
|||
import net.minecraft.nbt.NbtHelper;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.structure.StructurePieceType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.Mutable;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
@ -29,11 +29,12 @@ public abstract class MountainPiece extends BasePiece {
|
|||
protected float radius;
|
||||
protected float height;
|
||||
protected float r2;
|
||||
protected Identifier biomeID;
|
||||
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;
|
||||
|
@ -67,47 +68,48 @@ public abstract class MountainPiece extends BasePiece {
|
|||
center = NbtHelper.toBlockPos(tag.getCompound("center"));
|
||||
radius = tag.getFloat("radius");
|
||||
height = tag.getFloat("height");
|
||||
biomeID = new Identifier(tag.getString("biome"));
|
||||
biomeID = new ResourceLocation(tag.getString("biome"));
|
||||
r2 = radius * radius;
|
||||
seed1 = tag.getInt("seed1");
|
||||
seed2 = tag.getInt("seed2");
|
||||
noise1 = new OpenSimplexNoise(seed1);
|
||||
noise2 = new OpenSimplexNoise(seed2);
|
||||
}
|
||||
|
||||
|
||||
private int getHeight(StructureWorldAccess 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;
|
||||
}
|
||||
h = world.getTopY(Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
|
||||
h = MathHelper.abs(h - center.getY());
|
||||
h = Mth.abs(h - center.getY());
|
||||
if (h > 4) {
|
||||
h = 4 - h;
|
||||
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(StructureWorldAccess world, int radius, int posX, int posZ) {
|
||||
Mutable mut = new Mutable();
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
float height = 0;
|
||||
float max = 0;
|
||||
for (int x = -radius; x <= radius; x++) {
|
||||
|
@ -124,9 +126,9 @@ public abstract class MountainPiece extends BasePiece {
|
|||
}
|
||||
}
|
||||
height /= max;
|
||||
return MathHelper.clamp(height / radius, 0, 1);
|
||||
return Mth.clamp(height / radius, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
private void makeBoundingBox() {
|
||||
int minX = MHelper.floor(center.getX() - radius);
|
||||
int minZ = MHelper.floor(center.getZ() - radius);
|
||||
|
|
|
@ -8,10 +8,10 @@ import net.minecraft.structure.Structure;
|
|||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.structure.StructurePlacementData;
|
||||
import net.minecraft.util.BlockMirror;
|
||||
import net.minecraft.util.BlockRotation;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
|
@ -21,19 +21,20 @@ import ru.betterend.util.MHelper;
|
|||
import ru.betterend.util.StructureHelper;
|
||||
|
||||
public class NBTPiece extends BasePiece {
|
||||
private Identifier structureID;
|
||||
private BlockRotation rotation;
|
||||
private ResourceLocation structureID;
|
||||
private Rotation rotation;
|
||||
private BlockMirror mirror;
|
||||
private Structure structure;
|
||||
private BlockPos pos;
|
||||
private int erosion;
|
||||
private boolean cover;
|
||||
|
||||
public NBTPiece(Identifier structureID, Structure structure, BlockPos pos, int erosion, boolean cover, Random random) {
|
||||
|
||||
public NBTPiece(ResourceLocation structureID, Structure structure, BlockPos pos, int erosion, boolean cover,
|
||||
Random random) {
|
||||
super(EndStructures.NBT_PIECE, random.nextInt());
|
||||
this.structureID = structureID;
|
||||
this.structure = structure;
|
||||
this.rotation = BlockRotation.random(random);
|
||||
this.rotation = Rotation.random(random);
|
||||
this.mirror = BlockMirror.values()[random.nextInt(3)];
|
||||
this.pos = StructureHelper.offsetPos(pos, structure, rotation, mirror);
|
||||
this.erosion = erosion;
|
||||
|
@ -58,8 +59,8 @@ public class NBTPiece extends BasePiece {
|
|||
|
||||
@Override
|
||||
protected void fromNbt(CompoundTag tag) {
|
||||
structureID = new Identifier(tag.getString("id"));
|
||||
rotation = BlockRotation.values()[tag.getInt("rotation")];
|
||||
structureID = new ResourceLocation(tag.getString("id"));
|
||||
rotation = Rotation.values()[tag.getInt("rotation")];
|
||||
mirror = BlockMirror.values()[tag.getInt("mirror")];
|
||||
erosion = tag.getInt("erosion");
|
||||
pos = NbtHelper.toBlockPos(tag.getCompound("pos"));
|
||||
|
@ -68,11 +69,13 @@ public class NBTPiece extends BasePiece {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
public boolean generate(StructureWorldAccess 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);
|
||||
StructurePlacementData placementData = new StructurePlacementData().setRotation(rotation).setMirror(mirror)
|
||||
.setBoundingBox(bounds);
|
||||
structure.place(world, pos, placementData, random);
|
||||
if (erosion > 0) {
|
||||
bounds.maxX = MHelper.min(bounds.maxX, boundingBox.maxX);
|
||||
|
@ -86,7 +89,7 @@ public class NBTPiece extends BasePiece {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void makeBoundingBox() {
|
||||
this.boundingBox = StructureHelper.getStructureBounds(pos, structure, rotation, mirror);
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@ package ru.betterend.world.structures.piece;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
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.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.Mutable;
|
||||
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;
|
||||
|
@ -23,7 +23,9 @@ 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;
|
||||
}
|
||||
|
@ -36,7 +38,7 @@ public class PaintedMountainPiece extends MountainPiece {
|
|||
protected void toNbt(CompoundTag tag) {
|
||||
super.toNbt(tag);
|
||||
ListTag slise = new ListTag();
|
||||
for (BlockState state: slises) {
|
||||
for (BlockState state : slises) {
|
||||
slise.add(NbtHelper.fromBlockState(state));
|
||||
}
|
||||
tag.put("slises", slise);
|
||||
|
@ -53,10 +55,11 @@ public class PaintedMountainPiece extends MountainPiece {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator,
|
||||
Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
int sx = chunkPos.getStartX();
|
||||
int sz = chunkPos.getStartZ();
|
||||
Mutable pos = new Mutable();
|
||||
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);
|
||||
|
@ -76,7 +79,7 @@ public class PaintedMountainPiece extends MountainPiece {
|
|||
int minY = map.get(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));
|
||||
|
@ -86,18 +89,19 @@ public class PaintedMountainPiece extends MountainPiece {
|
|||
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.setBlockState(pos, slises[index], false);
|
||||
chunk.setBlockAndUpdate(pos, slises[index], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.function.Consumer;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
|
@ -16,7 +16,7 @@ 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();
|
||||
|
@ -40,7 +40,8 @@ public class VoxelPiece extends BasePiece {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator,
|
||||
Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
this.world.placeChunk(world, chunkPos);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue