Start migration

This commit is contained in:
Aleksey 2021-04-08 21:55:07 +03:00
parent 6630ce0cab
commit 47ed597358
491 changed files with 12045 additions and 11953 deletions

View file

@ -2,9 +2,9 @@ package ru.betterend.world.features.terrain;
import java.util.Random;
import net.minecraft.block.Material;
import net.minecraft.world.level.material.Material;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -19,30 +19,30 @@ import ru.betterend.world.features.DefaultFeature;
public class BigAuroraCrystalFeature extends DefaultFeature {
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
int maxY = pos.getY() + BlocksHelper.upRay(world, pos, 16);
int minY = pos.getY() - BlocksHelper.downRay(world, pos, 16);
if (maxY - minY < 10) {
return false;
}
int y = MHelper.randRange(minY, maxY, random);
pos = new BlockPos(pos.getX(), y, pos.getZ());
int height = MHelper.randRange(5, 25, random);
SDF prism = new SDFHexPrism().setHeight(height).setRadius(MHelper.randRange(1.7F, 3F, random)).setBlock(EndBlocks.AURORA_CRYSTAL);
SDF prism = new SDFHexPrism().setHeight(height).setRadius(MHelper.randRange(1.7F, 3F, random))
.setBlock(EndBlocks.AURORA_CRYSTAL);
Vector3f vec = MHelper.randomHorizontal(random);
prism = new SDFRotation().setRotation(vec, random.nextFloat()).setSource(prism);
prism.setReplaceFunction((bState) -> {
return bState.getMaterial().isReplaceable()
|| bState.isIn(EndTags.GEN_TERRAIN)
|| bState.getMaterial().equals(Material.PLANT)
|| bState.getMaterial().equals(Material.LEAVES);
return bState.getMaterial().isReplaceable() || bState.isIn(EndTags.GEN_TERRAIN)
|| bState.getMaterial().equals(Material.PLANT) || bState.getMaterial().equals(Material.LEAVES);
});
prism.fillRecursive(world, pos);
BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.AURORA_CRYSTAL);
return true;
}
}

View file

@ -2,12 +2,12 @@ package ru.betterend.world.features.terrain;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Material;
import net.minecraft.fluid.FluidState;
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.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -19,46 +19,52 @@ import ru.betterend.util.MHelper;
import ru.betterend.world.features.DefaultFeature;
public class EndLakeFeature extends DefaultFeature {
private static final BlockState END_STONE = Blocks.END_STONE.getDefaultState();
private static final BlockState END_STONE = Blocks.END_STONE.defaultBlockState();
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(15152);
private static final Mutable POS = new Mutable();
private static final MutableBlockPos POS = new MutableBlockPos();
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig featureConfig) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos,
DefaultFeatureConfig featureConfig) {
double radius = MHelper.randRange(10.0, 20.0, random);
double depth = radius * 0.5 * MHelper.randRange(0.8, 1.2, random);
int dist = MHelper.floor(radius);
int dist2 = MHelper.floor(radius * 1.5);
int bott = MHelper.floor(depth);
blockPos = getPosOnSurfaceWG(world, blockPos);
if (blockPos.getY() < 10) return false;
if (blockPos.getY() < 10)
return false;
int waterLevel = blockPos.getY();
BlockPos pos = getPosOnSurfaceRaycast(world, blockPos.north(dist).up(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
if (Math.abs(blockPos.getY() - pos.getY()) > 5)
return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurfaceRaycast(world, blockPos.south(dist).up(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
if (Math.abs(blockPos.getY() - pos.getY()) > 5)
return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurfaceRaycast(world, blockPos.east(dist).up(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
if (Math.abs(blockPos.getY() - pos.getY()) > 5)
return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurfaceRaycast(world, blockPos.west(dist).up(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
if (Math.abs(blockPos.getY() - pos.getY()) > 5)
return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
BlockState state;
int minX = blockPos.getX() - dist2;
int maxX = blockPos.getX() + dist2;
int minZ = blockPos.getZ() - dist2;
int maxZ = blockPos.getZ() + dist2;
int maskMinX = minX - 1;
int maskMinZ = minZ - 1;
boolean[][] mask = new boolean[maxX - minX + 3][maxZ - minZ + 3];
for (int x = minX; x <= maxX; x++) {
POS.setX(x);
@ -84,7 +90,7 @@ public class EndLakeFeature extends DefaultFeature {
}
}
}
for (int x = minX; x <= maxX; x++) {
POS.setX(x);
int x2 = x - blockPos.getX();
@ -104,7 +110,8 @@ public class EndLakeFeature extends DefaultFeature {
size *= 0.8;
add = 5;
}
double r = (add * 1.8 + radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75)) - 1.0 / size;
double r = (add * 1.8 + radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75))
- 1.0 / size;
if (r > 0) {
r *= r;
if (x2 + z2 <= r) {
@ -112,26 +119,28 @@ public class EndLakeFeature extends DefaultFeature {
if (state.isIn(EndTags.GEN_TERRAIN)) {
BlocksHelper.setWithoutUpdate(world, POS, AIR);
}
pos = POS.down();
pos = POS.below();
if (world.getBlockState(pos).isIn(EndTags.GEN_TERRAIN)) {
state = world.getBiome(pos).getGenerationSettings().getSurfaceConfig().getTopMaterial();
state = world.getBiome(pos).getGenerationSettings().getSurfaceConfig()
.getTopMaterial();
if (y > waterLevel + 1)
BlocksHelper.setWithoutUpdate(world, pos, state);
else if (y > waterLevel)
BlocksHelper.setWithoutUpdate(world, pos, random.nextBoolean() ? state : EndBlocks.ENDSTONE_DUST.getDefaultState());
BlocksHelper.setWithoutUpdate(world, pos, random.nextBoolean() ? state
: EndBlocks.ENDSTONE_DUST.defaultBlockState());
else
BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.ENDSTONE_DUST.getDefaultState());
BlocksHelper.setWithoutUpdate(world, pos,
EndBlocks.ENDSTONE_DUST.defaultBlockState());
}
}
}
else {
} else {
break;
}
}
}
}
}
double aspect = ((double) radius / (double) depth);
for (int x = blockPos.getX() - dist; x <= blockPos.getX() + dist; x++) {
@ -160,12 +169,13 @@ public class EndLakeFeature extends DefaultFeature {
state = canReplace(state) ? (y < waterLevel ? WATER : AIR) : state;
BlocksHelper.setWithoutUpdate(world, POS, state);
}
pos = POS.down();
pos = POS.below();
if (world.getBlockState(pos).getBlock().isIn(EndTags.GEN_TERRAIN)) {
BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.ENDSTONE_DUST.getDefaultState());
BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.ENDSTONE_DUST.defaultBlockState());
}
pos = POS.up();
while (canReplace(state = world.getBlockState(pos)) && !state.isAir() && state.getFluidState().isEmpty()) {
while (canReplace(state = world.getBlockState(pos)) && !state.isAir()
&& state.getFluidState().isEmpty()) {
BlocksHelper.setWithoutUpdate(world, pos, pos.getY() < waterLevel ? WATER : AIR);
pos = pos.up();
}
@ -174,30 +184,29 @@ public class EndLakeFeature extends DefaultFeature {
else if (y < waterLevel && y2 + x2 + z2 <= rb) {
if (world.isAir(POS.up())) {
state = world.getBiome(POS).getGenerationSettings().getSurfaceConfig().getTopMaterial();
BlocksHelper.setWithoutUpdate(world, POS, random.nextBoolean() ? state : EndBlocks.ENDSTONE_DUST.getDefaultState());
BlocksHelper.setWithoutUpdate(world, POS.down(), END_STONE);
BlocksHelper.setWithoutUpdate(world, POS,
random.nextBoolean() ? state : EndBlocks.ENDSTONE_DUST.defaultBlockState());
BlocksHelper.setWithoutUpdate(world, POS.below(), END_STONE);
} else {
BlocksHelper.setWithoutUpdate(world, POS, EndBlocks.ENDSTONE_DUST.defaultBlockState());
BlocksHelper.setWithoutUpdate(world, POS.below(), END_STONE);
}
else {
BlocksHelper.setWithoutUpdate(world, POS, EndBlocks.ENDSTONE_DUST.getDefaultState());
BlocksHelper.setWithoutUpdate(world, POS.down(), END_STONE);
}
//}
// }
}
}
}
}
}
BlocksHelper.fixBlocks(world, new BlockPos(minX - 2, waterLevel - 2, minZ - 2), new BlockPos(maxX + 2, blockPos.getY() + 20, maxZ + 2));
BlocksHelper.fixBlocks(world, new BlockPos(minX - 2, waterLevel - 2, minZ - 2),
new BlockPos(maxX + 2, blockPos.getY() + 20, maxZ + 2));
return true;
}
private boolean canReplace(BlockState state) {
return state.getMaterial().isReplaceable()
|| state.isIn(EndTags.GEN_TERRAIN)
|| state.isOf(EndBlocks.ENDSTONE_DUST)
|| state.getMaterial().equals(Material.PLANT)
return state.getMaterial().isReplaceable() || state.isIn(EndTags.GEN_TERRAIN)
|| state.is(EndBlocks.ENDSTONE_DUST) || state.getMaterial().equals(Material.PLANT)
|| state.getMaterial().equals(Material.UNDERWATER_PLANT)
|| state.getMaterial().equals(Material.UNUSED_PLANT);
}

View file

@ -2,11 +2,11 @@ package ru.betterend.world.features.terrain;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Material;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -23,15 +23,18 @@ import ru.betterend.world.features.DefaultFeature;
public class FallenPillarFeature extends DefaultFeature {
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
pos = getPosOnSurface(world, new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16)));
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
pos = getPosOnSurface(world,
new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16)));
if (!world.getBlockState(pos.down(5)).isIn(EndTags.GEN_TERRAIN)) {
return false;
}
float height = MHelper.randRange(20F, 40F, random);
float radius = MHelper.randRange(2F, 4F, random);
SDF pillar = new SDFCappedCone().setRadius1(radius).setRadius2(radius).setHeight(height * 0.5F).setBlock(Blocks.OBSIDIAN);
SDF pillar = new SDFCappedCone().setRadius1(radius).setRadius2(radius).setHeight(height * 0.5F)
.setBlock(Blocks.OBSIDIAN);
pillar = new SDFTranslate().setTranslate(0, radius * 0.5F - 2, 0).setSource(pillar);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
pillar = new SDFDisplacement().setFunction((vec) -> {
@ -40,17 +43,18 @@ public class FallenPillarFeature extends DefaultFeature {
Vector3f vec = MHelper.randomHorizontal(random);
float angle = (float) random.nextGaussian() * 0.05F + (float) Math.PI;
pillar = new SDFRotation().setRotation(vec, angle).setSource(pillar);
BlockState mossy = EndBlocks.MOSSY_OBSIDIAN.getDefaultState();
BlockState mossy = EndBlocks.MOSSY_OBSIDIAN.defaultBlockState();
pillar.addPostProcess((info) -> {
if (info.getStateUp().isAir() && random.nextFloat() > 0.1F) {
return mossy;
}
return info.getState();
}).setReplaceFunction((state) -> {
return state.getMaterial().isReplaceable() || state.isIn(EndTags.GEN_TERRAIN) || state.getMaterial().equals(Material.PLANT);
return state.getMaterial().isReplaceable() || state.isIn(EndTags.GEN_TERRAIN)
|| state.getMaterial().equals(Material.PLANT);
}).fillRecursive(world, pos);
return true;
}
}

View file

@ -5,9 +5,9 @@ import java.util.Random;
import com.google.common.collect.Lists;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -21,14 +21,16 @@ import ru.betterend.util.sdf.primitive.SDFSphere;
public class FloatingSpireFeature extends SpireFeature {
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
int minY = getYOnSurface(world, pos.getX(), pos.getZ());
int y = minY > 57 ? MHelper.floor(MHelper.randRange(minY, minY * 2, random) * 0.5F + 32) : MHelper.randRange(64, 192, random);
int y = minY > 57 ? MHelper.floor(MHelper.randRange(minY, minY * 2, random) * 0.5F + 32)
: MHelper.randRange(64, 192, random);
pos = new BlockPos(pos.getX(), y, pos.getZ());
SDF sdf = new SDFSphere().setRadius(MHelper.randRange(2, 3, random)).setBlock(Blocks.END_STONE);
int count = MHelper.randRange(3, 5, random);
for (int i = 0; i < count; i++) {
float rMin = (i * 1.3F) + 2.5F;
sdf = addSegment(sdf, MHelper.randRange(rMin, rMin + 1.5F, random), random);
@ -37,10 +39,11 @@ public class FloatingSpireFeature extends SpireFeature {
float rMin = (i * 1.3F) + 2.5F;
sdf = addSegment(sdf, MHelper.randRange(rMin, rMin + 1.5F, random), random);
}
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
sdf = new SDFDisplacement().setFunction((vec) -> {
return (float) (Math.abs(noise.eval(vec.getX() * 0.1, vec.getY() * 0.1, vec.getZ() * 0.1)) * 3F + Math.abs(noise.eval(vec.getX() * 0.3, vec.getY() * 0.3 + 100, vec.getZ() * 0.3)) * 1.3F);
return (float) (Math.abs(noise.eval(vec.getX() * 0.1, vec.getY() * 0.1, vec.getZ() * 0.1)) * 3F
+ Math.abs(noise.eval(vec.getX() * 0.3, vec.getY() * 0.3 + 100, vec.getZ() * 0.3)) * 1.3F);
}).setSource(sdf);
final BlockPos center = pos;
List<BlockPos> support = Lists.newArrayList();
@ -50,20 +53,19 @@ public class FloatingSpireFeature extends SpireFeature {
support.add(info.getPos().up());
}
return world.getBiome(info.getPos()).getGenerationSettings().getSurfaceConfig().getTopMaterial();
}
else if (info.getState(Direction.UP, 3).isAir()) {
} else if (info.getState(Direction.UP, 3).isAir()) {
return world.getBiome(info.getPos()).getGenerationSettings().getSurfaceConfig().getUnderMaterial();
}
return info.getState();
});
sdf.fillRecursive(world, center);
support.forEach((bpos) -> {
if (EndBiomes.getFromBiome(world.getBiome(bpos)) == EndBiomes.BLOSSOMING_SPIRES) {
EndFeatures.TENANEA_BUSH.getFeature().generate(world, chunkGenerator, random, bpos, null);
}
});
return true;
}
}

View file

@ -3,15 +3,15 @@ package ru.betterend.world.features.terrain;
import java.util.Random;
import java.util.function.Function;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.block.Material;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.HorizontalFacingBlock;
import net.minecraft.world.level.material.Material;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -43,23 +43,24 @@ public class GeyserFeature extends DefaultFeature {
protected static final Function<BlockState, Boolean> REPLACE2;
private static final Function<BlockState, Boolean> IGNORE;
private static final Direction[] HORIZONTAL = BlocksHelper.makeHorizontal();
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
pos = getPosOnSurfaceWG(world, pos);
if (pos.getY() < 10) {
return false;
}
Mutable bpos = new Mutable().set(pos);
MutableBlockPos bpos = new MutableBlockPos().set(pos);
bpos.setY(bpos.getY() - 1);
BlockState state = world.getBlockState(bpos);
while (state.isIn(EndTags.GEN_TERRAIN) || !state.getFluidState().isEmpty() && bpos.getY() > 5) {
bpos.setY(bpos.getY() - 1);
state = world.getBlockState(bpos);
}
if (pos.getY() - bpos.getY() < 25) {
return false;
}
@ -67,18 +68,21 @@ public class GeyserFeature extends DefaultFeature {
int halfHeight = MHelper.randRange(10, 20, random);
float radius1 = halfHeight * 0.5F;
float radius2 = halfHeight * 0.1F + 0.5F;
SDF sdf = new SDFCappedCone().setHeight(halfHeight).setRadius1(radius1).setRadius2(radius2).setBlock(EndBlocks.SULPHURIC_ROCK.stone);
SDF sdf = new SDFCappedCone().setHeight(halfHeight).setRadius1(radius1).setRadius2(radius2)
.setBlock(EndBlocks.SULPHURIC_ROCK.stone);
sdf = new SDFTranslate().setTranslate(0, halfHeight - 3, 0).setSource(sdf);
int count = halfHeight;
for (int i = 0; i < count; i++) {
int py = i << 1;
float delta = (float) i / (float) (count - 1);
float radius = MathHelper.lerp(delta, radius1, radius2) * 1.3F;
float radius = Mth.lerp(delta, radius1, radius2) * 1.3F;
SDF bowl = new SDFCappedCone().setHeight(radius).setRadius1(0).setRadius2(radius).setBlock(EndBlocks.SULPHURIC_ROCK.stone);
SDF bowl = new SDFCappedCone().setHeight(radius).setRadius1(0).setRadius2(radius)
.setBlock(EndBlocks.SULPHURIC_ROCK.stone);
SDF brimstone = new SDFCappedCone().setHeight(radius).setRadius1(0).setRadius2(radius).setBlock(EndBlocks.BRIMSTONE);
SDF brimstone = new SDFCappedCone().setHeight(radius).setRadius1(0).setRadius2(radius)
.setBlock(EndBlocks.BRIMSTONE);
brimstone = new SDFTranslate().setTranslate(0, 2F, 0).setSource(brimstone);
bowl = new SDFSubtraction().setSourceA(bowl).setSourceB(brimstone);
bowl = new SDFUnion().setSourceA(brimstone).setSourceB(bowl);
@ -156,7 +160,7 @@ public class GeyserFeature extends DefaultFeature {
}).setSource(cave).setReplaceFunction(REPLACE1).fillRecursiveIgnore(world, pos, IGNORE);
BlocksHelper.setWithoutUpdate(world, pos, WATER);
Mutable mut = new Mutable().set(pos);
MutableBlockPos mut = new MutableBlockPos().set(pos);
count = getYOnSurface(world, pos.getX(), pos.getZ()) - pos.getY();
for (int i = 0; i < count; i++) {
BlocksHelper.setWithoutUpdate(world, mut, WATER);
@ -167,7 +171,8 @@ public class GeyserFeature extends DefaultFeature {
}
for (int i = 0; i < 150; i++) {
mut.set(pos).move(MHelper.floor(random.nextGaussian() * 4 + 0.5), -halfHeight - 10, MHelper.floor(random.nextGaussian() * 4 + 0.5));
mut.set(pos).move(MHelper.floor(random.nextGaussian() * 4 + 0.5), -halfHeight - 10,
MHelper.floor(random.nextGaussian() * 4 + 0.5));
float distRaw = MHelper.length(mut.getX() - pos.getX(), mut.getZ() - pos.getZ());
int dist = MHelper.floor(6 - distRaw) + random.nextInt(2);
if (dist >= 0) {
@ -176,24 +181,26 @@ public class GeyserFeature extends DefaultFeature {
mut.setY(mut.getY() - 1);
state = world.getBlockState(mut);
}
if (state.isIn(EndTags.GEN_TERRAIN) && !world.getBlockState(mut.up()).isOf(EndBlocks.HYDROTHERMAL_VENT)) {
if (state.isIn(EndTags.GEN_TERRAIN) && !world.getBlockState(mut.up()).is(EndBlocks.HYDROTHERMAL_VENT)) {
for (int j = 0; j <= dist; j++) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.SULPHURIC_ROCK.stone);
MHelper.shuffle(HORIZONTAL, random);
for (Direction dir : HORIZONTAL) {
BlockPos p = mut.offset(dir);
if (random.nextBoolean() && world.getBlockState(p).isOf(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, p, EndBlocks.TUBE_WORM.getDefaultState().with(HorizontalFacingBlock.FACING, dir));
if (random.nextBoolean() && world.getBlockState(p).is(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, p, EndBlocks.TUBE_WORM.defaultBlockState()
.with(HorizontalFacingBlock.FACING, dir));
}
}
mut.setY(mut.getY() + 1);
}
state = EndBlocks.HYDROTHERMAL_VENT.getDefaultState().with(HydrothermalVentBlock.ACTIVATED, distRaw < 2);
state = EndBlocks.HYDROTHERMAL_VENT.defaultBlockState().with(HydrothermalVentBlock.ACTIVATED,
distRaw < 2);
BlocksHelper.setWithoutUpdate(world, mut, state);
mut.setY(mut.getY() + 1);
state = world.getBlockState(mut);
while (state.isOf(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.VENT_BUBBLE_COLUMN.getDefaultState());
while (state.is(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.VENT_BUBBLE_COLUMN.defaultBlockState());
mut.setY(mut.getY() + 1);
state = world.getBlockState(mut);
}
@ -202,12 +209,13 @@ public class GeyserFeature extends DefaultFeature {
}
for (int i = 0; i < 10; i++) {
mut.set(pos).move(MHelper.floor(random.nextGaussian() * 0.7 + 0.5), -halfHeight - 10, MHelper.floor(random.nextGaussian() * 0.7 + 0.5));
mut.set(pos).move(MHelper.floor(random.nextGaussian() * 0.7 + 0.5), -halfHeight - 10,
MHelper.floor(random.nextGaussian() * 0.7 + 0.5));
float distRaw = MHelper.length(mut.getX() - pos.getX(), mut.getZ() - pos.getZ());
int dist = MHelper.floor(6 - distRaw) + random.nextInt(2);
if (dist >= 0) {
state = world.getBlockState(mut);
while (state.isOf(Blocks.WATER)) {
while (state.is(Blocks.WATER)) {
mut.setY(mut.getY() - 1);
state = world.getBlockState(mut);
}
@ -216,12 +224,13 @@ public class GeyserFeature extends DefaultFeature {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.SULPHURIC_ROCK.stone);
mut.setY(mut.getY() + 1);
}
state = EndBlocks.HYDROTHERMAL_VENT.getDefaultState().with(HydrothermalVentBlock.ACTIVATED, distRaw < 2);
state = EndBlocks.HYDROTHERMAL_VENT.defaultBlockState().with(HydrothermalVentBlock.ACTIVATED,
distRaw < 2);
BlocksHelper.setWithoutUpdate(world, mut, state);
mut.setY(mut.getY() + 1);
state = world.getBlockState(mut);
while (state.isOf(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.VENT_BUBBLE_COLUMN.getDefaultState());
while (state.is(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.VENT_BUBBLE_COLUMN.defaultBlockState());
mut.setY(mut.getY() + 1);
state = world.getBlockState(mut);
}
@ -232,20 +241,21 @@ public class GeyserFeature extends DefaultFeature {
EndFeatures.SULPHURIC_LAKE.getFeature().generate(world, chunkGenerator, random, pos, null);
double distance = radius1 * 1.7;
BlockPos start = pos.add(-distance, -halfHeight - 15 - distance, -distance);
BlockPos end = pos.add(distance, -halfHeight - 5 + distance, distance);
BlockPos start = pos.offset(-distance, -halfHeight - 15 - distance, -distance);
BlockPos end = pos.offset(distance, -halfHeight - 5 + distance, distance);
BlocksHelper.fixBlocks(world, start, end);
return true;
}
static {
REPLACE1 = (state) -> {
return state.isAir() || (state.isIn(EndTags.GEN_TERRAIN));
};
REPLACE2 = (state) -> {
if (state.isIn(EndTags.GEN_TERRAIN) || state.isOf(EndBlocks.HYDROTHERMAL_VENT) || state.isOf(EndBlocks.SULPHUR_CRYSTAL)) {
if (state.isIn(EndTags.GEN_TERRAIN) || state.is(EndBlocks.HYDROTHERMAL_VENT)
|| state.is(EndBlocks.SULPHUR_CRYSTAL)) {
return true;
}
if (state.getMaterial().equals(Material.PLANT)) {
@ -253,9 +263,10 @@ public class GeyserFeature extends DefaultFeature {
}
return state.getMaterial().isReplaceable();
};
IGNORE = (state) -> {
return state.isOf(Blocks.WATER) || state.isOf(Blocks.CAVE_AIR) || state.isOf(EndBlocks.SULPHURIC_ROCK.stone) || state.isOf(EndBlocks.BRIMSTONE);
return state.is(Blocks.WATER) || state.is(Blocks.CAVE_AIR) || state.is(EndBlocks.SULPHURIC_ROCK.stone)
|| state.is(EndBlocks.BRIMSTONE);
};
}
}

View file

@ -4,9 +4,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -24,64 +24,64 @@ public class IceStarFeature extends DefaultFeature {
private final float maxSize;
private final int minCount;
private final int maxCount;
public IceStarFeature(float minSize, float maxSize, int minCount, int maxCount) {
this.minSize = minSize;
this.maxSize = maxSize;
this.minCount = minCount;
this.maxCount = maxCount;
}
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
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);
if (angle > 0.01F && angle < 3.14F) {
Vector3f axis = MHelper.normalize(MHelper.cross(Vector3f.POSITIVE_Y, point));
rotated = new SDFRotation().setRotation(axis, angle).setSource(spike);
}
else if (angle > 1) {
} else if (angle > 1) {
rotated = new SDFRotation().setRotation(Vector3f.POSITIVE_Y, (float) Math.PI).setSource(spike);
}
sdf = (sdf == null) ? rotated : new SDFUnion().setSourceA(sdf).setSourceB(rotated);
}
int x1 = (pos.getX() >> 4) << 4;
int z1 = (pos.getZ() >> 4) << 4;
pos = new BlockPos(x1 + random.nextInt(16), MHelper.randRange(32, 128, random), z1 + random.nextInt(16));
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.getDefaultState();
final BlockState dense = EndBlocks.DENSE_EMERALD_ICE.getDefaultState();
final BlockState ancient = EndBlocks.ANCIENT_EMERALD_ICE.getDefaultState();
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;
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();

View file

@ -2,10 +2,10 @@ package ru.betterend.world.features.terrain;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Material;
import net.minecraft.core.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -21,26 +21,29 @@ import ru.betterend.world.features.DefaultFeature;
public class ObsidianBoulderFeature extends DefaultFeature {
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
pos = getPosOnSurface(world, new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16)));
if (!world.getBlockState(pos.down()).isIn(EndTags.END_GROUND)) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
pos = getPosOnSurface(world,
new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16)));
if (!world.getBlockState(pos.below()).isIn(EndTags.END_GROUND)) {
return false;
}
int count = MHelper.randRange(1, 5, random);
for (int i = 0; i < count; i++) {
BlockPos p = getPosOnSurface(world, new BlockPos(pos.getX() + random.nextInt(16) - 8, pos.getY(), pos.getZ() + random.nextInt(16) - 8));
BlockPos p = getPosOnSurface(world,
new BlockPos(pos.getX() + random.nextInt(16) - 8, pos.getY(), pos.getZ() + random.nextInt(16) - 8));
makeBoulder(world, p, random);
}
return true;
}
private void makeBoulder(StructureWorldAccess world, BlockPos pos, Random random) {
if (!world.getBlockState(pos.down()).isIn(EndTags.END_GROUND)) {
if (!world.getBlockState(pos.below()).isIn(EndTags.END_GROUND)) {
return;
}
float radius = MHelper.randRange(1F, 5F, random);
SDF sphere = new SDFSphere().setRadius(radius).setBlock(Blocks.OBSIDIAN);
float sx = MHelper.randRange(0.7F, 1.3F, random);
@ -51,15 +54,16 @@ public class ObsidianBoulderFeature extends DefaultFeature {
sphere = new SDFDisplacement().setFunction((vec) -> {
return (float) (noise.eval(vec.getX() * 0.2, vec.getY() * 0.2, vec.getZ() * 0.2) * 1.5F);
}).setSource(sphere);
BlockState mossy = EndBlocks.MOSSY_OBSIDIAN.getDefaultState();
BlockState mossy = EndBlocks.MOSSY_OBSIDIAN.defaultBlockState();
sphere.addPostProcess((info) -> {
if (info.getStateUp().isAir() && random.nextFloat() > 0.1F) {
return mossy;
}
return info.getState();
}).setReplaceFunction((state) -> {
return state.getMaterial().isReplaceable() || state.isIn(EndTags.GEN_TERRAIN) || state.getMaterial().equals(Material.PLANT);
return state.getMaterial().isReplaceable() || state.isIn(EndTags.GEN_TERRAIN)
|| state.getMaterial().equals(Material.PLANT);
}).fillRecursive(world, pos);
}
}

View file

@ -2,11 +2,11 @@ package ru.betterend.world.features.terrain;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Material;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -25,15 +25,18 @@ import ru.betterend.world.features.DefaultFeature;
public class ObsidianPillarBasementFeature extends DefaultFeature {
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
pos = getPosOnSurface(world, new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16)));
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
pos = getPosOnSurface(world,
new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16)));
if (!world.getBlockState(pos.down(5)).isIn(EndTags.GEN_TERRAIN)) {
return false;
}
float height = MHelper.randRange(10F, 35F, random);
float radius = MHelper.randRange(2F, 5F, random);
SDF pillar = new SDFCappedCone().setRadius1(radius).setRadius2(radius).setHeight(height * 0.5F).setBlock(Blocks.OBSIDIAN);
SDF pillar = new SDFCappedCone().setRadius1(radius).setRadius2(radius).setHeight(height * 0.5F)
.setBlock(Blocks.OBSIDIAN);
pillar = new SDFTranslate().setTranslate(0, height * 0.5F - 3, 0).setSource(pillar);
SDF cut = new SDFFlatland().setBlock(Blocks.OBSIDIAN);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
@ -48,17 +51,18 @@ public class ObsidianPillarBasementFeature extends DefaultFeature {
vec = MHelper.randomHorizontal(random);
angle = random.nextFloat() * 0.2F;
pillar = new SDFRotation().setRotation(vec, angle).setSource(pillar);
BlockState mossy = EndBlocks.MOSSY_OBSIDIAN.getDefaultState();
BlockState mossy = EndBlocks.MOSSY_OBSIDIAN.defaultBlockState();
pillar.addPostProcess((info) -> {
if (info.getStateUp().isAir() && random.nextFloat() > 0.1F) {
return mossy;
}
return info.getState();
}).setReplaceFunction((state) -> {
return state.getMaterial().isReplaceable() || state.isIn(EndTags.GEN_TERRAIN) || state.getMaterial().equals(Material.PLANT);
return state.getMaterial().isReplaceable() || state.isIn(EndTags.GEN_TERRAIN)
|| state.getMaterial().equals(Material.PLANT);
}).fillRecursive(world, pos);
return true;
}
}

View file

@ -2,9 +2,9 @@ package ru.betterend.world.features.terrain;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -20,32 +20,33 @@ public class OreLayerFeature extends DefaultFeature {
private static final SDFSphere SPHERE;
private static final SDFCoordModify NOISE;
private static final SDF FUNCTION;
private final BlockState state;
private final float radius;
private final int minY;
private final int maxY;
private OpenSimplexNoise noise;
public OreLayerFeature(BlockState state, float radius, int minY, int maxY) {
this.state = state;
this.radius = radius;
this.minY = minY;
this.maxY = maxY;
}
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
float radius = this.radius * 0.5F;
int r = MHelper.floor(radius + 1);
int posX = MHelper.randRange(Math.max(r - 16, 0), Math.min(31 - r, 15), random) + pos.getX();
int posZ = MHelper.randRange(Math.max(r - 16, 0), Math.min(31 - r, 15), random) + pos.getZ();
int posY = MHelper.randRange(minY, maxY, random);
if (noise == null) {
noise = new OpenSimplexNoise(world.getSeed());
}
SPHERE.setRadius(radius).setBlock(state);
NOISE.setFunction((vec) -> {
double x = (vec.getX() + pos.getX()) * 0.1;
@ -56,18 +57,18 @@ public class OreLayerFeature extends DefaultFeature {
FUNCTION.fillRecursive(world, new BlockPos(posX, posY, posZ));
return true;
}
static {
SPHERE = new SDFSphere();
NOISE = new SDFCoordModify();
SDF body = SPHERE;
body = new SDFScale3D().setScale(1, 0.2F, 1).setSource(body);
body = NOISE.setSource(body);
body.setReplaceFunction((state) -> {
return state.isOf(Blocks.END_STONE);
return state.is(Blocks.END_STONE);
});
FUNCTION = body;
}
}

View file

@ -2,10 +2,10 @@ package ru.betterend.world.features.terrain;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -15,24 +15,25 @@ import ru.betterend.world.features.DefaultFeature;
public class SingleBlockFeature extends DefaultFeature {
private final Block block;
public SingleBlockFeature(Block block) {
this.block = block;
}
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
if (!world.getBlockState(pos.down()).isIn(EndTags.GEN_TERRAIN)) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
if (!world.getBlockState(pos.below()).isIn(EndTags.GEN_TERRAIN)) {
return false;
}
BlockState state = block.getDefaultState();
BlockState state = block.defaultBlockState();
if (block.getStateManager().getProperty("waterlogged") != null) {
boolean waterlogged = !world.getFluidState(pos).isEmpty();
state = state.with(Properties.WATERLOGGED, waterlogged);
}
BlocksHelper.setWithoutUpdate(world, pos, state);
return true;
}
}

View file

@ -2,10 +2,10 @@ package ru.betterend.world.features.terrain;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.state.property.Properties;
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.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -17,25 +17,28 @@ import ru.betterend.world.features.DefaultFeature;
public class SmaragdantCrystalFeature extends DefaultFeature {
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
if (!world.getBlockState(pos.down()).isIn(EndTags.GEN_TERRAIN)) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
if (!world.getBlockState(pos.below()).isIn(EndTags.GEN_TERRAIN)) {
return false;
}
Mutable mut = new Mutable();
MutableBlockPos mut = new MutableBlockPos();
int count = MHelper.randRange(15, 30, random);
BlockState crystal = EndBlocks.SMARAGDANT_CRYSTAL.getDefaultState();
BlockState shard = EndBlocks.SMARAGDANT_CRYSTAL_SHARD.getDefaultState();
BlockState crystal = EndBlocks.SMARAGDANT_CRYSTAL.defaultBlockState();
BlockState shard = EndBlocks.SMARAGDANT_CRYSTAL_SHARD.defaultBlockState();
for (int i = 0; i < count; i++) {
mut.set(pos).move(MHelper.floor(random.nextGaussian() * 2 + 0.5), 5, MHelper.floor(random.nextGaussian() * 2 + 0.5));
int dist = MHelper.floor(1.5F - MHelper.length(mut.getX() - pos.getX(), mut.getZ() - pos.getZ())) + random.nextInt(3);
mut.set(pos).move(MHelper.floor(random.nextGaussian() * 2 + 0.5), 5,
MHelper.floor(random.nextGaussian() * 2 + 0.5));
int dist = MHelper.floor(1.5F - MHelper.length(mut.getX() - pos.getX(), mut.getZ() - pos.getZ()))
+ random.nextInt(3);
if (dist > 0) {
BlockState state = world.getBlockState(mut);
for (int n = 0; n < 10 && state.isAir(); n++) {
mut.setY(mut.getY() - 1);
state = world.getBlockState(mut);
}
if (state.isIn(EndTags.GEN_TERRAIN) && !world.getBlockState(mut.up()).isOf(crystal.getBlock())) {
if (state.isIn(EndTags.GEN_TERRAIN) && !world.getBlockState(mut.up()).is(crystal.getBlock())) {
for (int j = 0; j <= dist; j++) {
BlocksHelper.setWithoutUpdate(world, mut, crystal);
mut.setY(mut.getY() + 1);
@ -45,7 +48,7 @@ public class SmaragdantCrystalFeature extends DefaultFeature {
}
}
}
return true;
}
}

View file

@ -6,12 +6,12 @@ import java.util.function.Function;
import com.google.common.collect.Lists;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.Material;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.material.Material;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -29,14 +29,16 @@ import ru.betterend.world.features.DefaultFeature;
public class SpireFeature extends DefaultFeature {
protected static final Function<BlockState, Boolean> REPLACE;
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
pos = getPosOnSurfaceWG(world, pos);
if (pos.getY() < 10 || !world.getBlockState(pos.down(3)).isIn(EndTags.GEN_TERRAIN) || !world.getBlockState(pos.down(6)).isIn(EndTags.GEN_TERRAIN)) {
if (pos.getY() < 10 || !world.getBlockState(pos.down(3)).isIn(EndTags.GEN_TERRAIN)
|| !world.getBlockState(pos.down(6)).isIn(EndTags.GEN_TERRAIN)) {
return false;
}
SDF sdf = new SDFSphere().setRadius(MHelper.randRange(2, 3, random)).setBlock(Blocks.END_STONE);
int count = MHelper.randRange(3, 7, random);
for (int i = 0; i < count; i++) {
@ -45,7 +47,8 @@ public class SpireFeature extends DefaultFeature {
}
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
sdf = new SDFDisplacement().setFunction((vec) -> {
return (float) (Math.abs(noise.eval(vec.getX() * 0.1, vec.getY() * 0.1, vec.getZ() * 0.1)) * 3F + Math.abs(noise.eval(vec.getX() * 0.3, vec.getY() * 0.3 + 100, vec.getZ() * 0.3)) * 1.3F);
return (float) (Math.abs(noise.eval(vec.getX() * 0.1, vec.getY() * 0.1, vec.getZ() * 0.1)) * 3F
+ Math.abs(noise.eval(vec.getX() * 0.3, vec.getY() * 0.3 + 100, vec.getZ() * 0.3)) * 1.3F);
}).setSource(sdf);
final BlockPos center = pos;
List<BlockPos> support = Lists.newArrayList();
@ -55,13 +58,12 @@ public class SpireFeature extends DefaultFeature {
support.add(info.getPos().up());
}
return world.getBiome(info.getPos()).getGenerationSettings().getSurfaceConfig().getTopMaterial();
}
else if (info.getState(Direction.UP, 3).isAir()) {
} else if (info.getState(Direction.UP, 3).isAir()) {
return world.getBiome(info.getPos()).getGenerationSettings().getSurfaceConfig().getUnderMaterial();
}
return info.getState();
}).fillRecursive(world, center);
support.forEach((bpos) -> {
if (EndBiomes.getFromBiome(world.getBiome(bpos)) == EndBiomes.BLOSSOMING_SPIRES) {
EndFeatures.TENANEA_BUSH.getFeature().generate(world, chunkGenerator, random, bpos, null);
@ -70,13 +72,14 @@ public class SpireFeature extends DefaultFeature {
return true;
}
protected SDF addSegment(SDF sdf, float radius, Random random) {
SDF sphere = new SDFSphere().setRadius(radius).setBlock(Blocks.END_STONE);
SDF offseted = new SDFTranslate().setTranslate(0, radius + random.nextFloat() * 0.25F * radius, 0).setSource(sdf);
SDF offseted = new SDFTranslate().setTranslate(0, radius + random.nextFloat() * 0.25F * radius, 0)
.setSource(sdf);
return new SDFSmoothUnion().setRadius(radius * 0.5F).setSourceA(sphere).setSourceB(offseted);
}
static {
REPLACE = (state) -> {
if (state.isIn(EndTags.END_GROUND)) {

View file

@ -2,12 +2,12 @@ package ru.betterend.world.features.terrain;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.state.property.Properties;
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.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -20,24 +20,25 @@ public class StalactiteFeature extends DefaultFeature {
private final boolean ceiling;
private final Block[] ground;
private final Block block;
public StalactiteFeature(boolean ceiling, Block block, Block... ground) {
this.ceiling = ceiling;
this.ground = ground;
this.block = block;
}
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
if (!isGround(world.getBlockState(ceiling ? pos.up() : pos.down()).getBlock())) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
if (!isGround(world.getBlockState(ceiling ? pos.up() : pos.below()).getBlock())) {
return false;
}
Mutable mut = new Mutable().set(pos);
MutableBlockPos mut = new MutableBlockPos().set(pos);
int height = random.nextInt(16);
int dir = ceiling ? -1 : 1;
boolean stalagnate = false;
for (int i = 1; i <= height; i++) {
mut.setY(pos.getY() + i * dir);
BlockState state = world.getBlockState(mut);
@ -47,21 +48,23 @@ public class StalactiteFeature extends DefaultFeature {
break;
}
}
if (!stalagnate && height > 7) {
height = random.nextInt(8);
}
float center = height * 0.5F;
for (int i = 0; i < height; i++) {
mut.setY(pos.getY() + i * dir);
int size = stalagnate ? MathHelper.clamp((int) (MathHelper.abs(i - center) + 1), 1, 7) : height - i - 1;
int size = stalagnate ? Mth.clamp((int) (Mth.abs(i - center) + 1), 1, 7) : height - i - 1;
boolean waterlogged = !world.getFluidState(mut).isEmpty();
BlockState base = block.getDefaultState().with(StalactiteBlock.SIZE, size).with(Properties.WATERLOGGED, waterlogged);
BlockState state = stalagnate ? base.with(StalactiteBlock.IS_FLOOR, dir > 0 ? i < center : i > center) : base.with(StalactiteBlock.IS_FLOOR, dir > 0);
BlockState base = block.defaultBlockState().with(StalactiteBlock.SIZE, size).with(Properties.WATERLOGGED,
waterlogged);
BlockState state = stalagnate ? base.with(StalactiteBlock.IS_FLOOR, dir > 0 ? i < center : i > center)
: base.with(StalactiteBlock.IS_FLOOR, dir > 0);
BlocksHelper.setWithoutUpdate(world, mut, state);
}
return true;
}

View file

@ -2,11 +2,11 @@ package ru.betterend.world.features.terrain;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.Direction;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -19,12 +19,13 @@ import ru.betterend.world.features.DefaultFeature;
public class SulphurHillFeature extends DefaultFeature {
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
pos = getPosOnSurfaceWG(world, pos);
if (pos.getY() < 57 || pos.getY() > 70) {
return false;
}
int count = MHelper.randRange(5, 13, random);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
for (int i = 0; i < count; i++) {
@ -38,14 +39,14 @@ public class SulphurHillFeature extends DefaultFeature {
}
return true;
}
private void makeCircle(StructureWorldAccess world, BlockPos pos, OpenSimplexNoise noise, Random random) {
int radius = MHelper.randRange(5, 9, random);
int min = -radius - 3;
int max = radius + 4;
Mutable mut = new Mutable();
BlockState rock = EndBlocks.SULPHURIC_ROCK.stone.getDefaultState();
BlockState brimstone = EndBlocks.BRIMSTONE.getDefaultState().with(BlockProperties.ACTIVE, true);
MutableBlockPos mut = new MutableBlockPos();
BlockState rock = EndBlocks.SULPHURIC_ROCK.stone.defaultBlockState();
BlockState brimstone = EndBlocks.BRIMSTONE.defaultBlockState().with(BlockProperties.ACTIVE, true);
for (int x = min; x < max; x++) {
int x2 = x * x;
int px = pos.getX() + x;
@ -60,7 +61,7 @@ public class SulphurHillFeature extends DefaultFeature {
int d = x2 + z2;
mut.setY(pos.getY());
BlockState state = world.getBlockState(mut);
if (state.getMaterial().isReplaceable() || state.isOf(EndBlocks.HYDROTHERMAL_VENT)) {
if (state.getMaterial().isReplaceable() || state.is(EndBlocks.HYDROTHERMAL_VENT)) {
if (d < r2 * r2) {
BlocksHelper.setWithoutUpdate(world, mut, Blocks.WATER);
mut.move(Direction.DOWN);
@ -76,8 +77,7 @@ public class SulphurHillFeature extends DefaultFeature {
BlocksHelper.setWithoutUpdate(world, mut, rock);
mut.move(Direction.DOWN);
}
}
else if (d < r1 * r1) {
} else if (d < r1 * r1) {
BlocksHelper.setWithoutUpdate(world, mut, brimstone);
mut.move(Direction.DOWN);
state = world.getBlockState(mut);

View file

@ -5,13 +5,13 @@ import java.util.Set;
import com.google.common.collect.Sets;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.block.Material;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.Direction;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.HorizontalFacingBlock;
import net.minecraft.world.level.material.Material;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.Heightmap;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
@ -26,20 +26,21 @@ import ru.betterend.util.MHelper;
import ru.betterend.world.features.DefaultFeature;
public class SulphuricCaveFeature extends DefaultFeature {
private static final BlockState CAVE_AIR = Blocks.CAVE_AIR.getDefaultState();
private static final BlockState WATER = Blocks.WATER.getDefaultState();
private static final BlockState CAVE_AIR = Blocks.CAVE_AIR.defaultBlockState();
private static final BlockState WATER = Blocks.WATER.defaultBlockState();
private static final Direction[] HORIZONTAL = BlocksHelper.makeHorizontal();
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
int radius = MHelper.randRange(10, 30, random);
int top = world.getTopY(Heightmap.Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
Mutable bpos = new Mutable();
MutableBlockPos bpos = new MutableBlockPos();
bpos.setX(pos.getX());
bpos.setZ(pos.getZ());
bpos.setY(top - 1);
BlockState state = world.getBlockState(bpos);
while (!state.isIn(EndTags.GEN_TERRAIN) && bpos.getY() > 5) {
bpos.setY(bpos.getY() - 1);
@ -49,34 +50,34 @@ public class SulphuricCaveFeature extends DefaultFeature {
return false;
}
top = (int) (bpos.getY() - (radius * 1.3F + 5));
while (state.isIn(EndTags.GEN_TERRAIN) || !state.getFluidState().isEmpty() && bpos.getY() > 5) {
bpos.setY(bpos.getY() - 1);
state = world.getBlockState(bpos);
}
int bottom = (int) (bpos.getY() + radius * 1.3F + 5);
if (top <= bottom) {
return false;
}
Mutable mut = new Mutable();
MutableBlockPos mut = new MutableBlockPos();
pos = new BlockPos(pos.getX(), MHelper.randRange(bottom, top, random), pos.getZ());
OpenSimplexNoise noise = new OpenSimplexNoise(MHelper.getSeed(534, pos.getX(), pos.getZ()));
int x1 = pos.getX() - radius - 5;
int z1 = pos.getZ() - radius - 5;
int x2 = pos.getX() + radius + 5;
int z2 = pos.getZ() + radius + 5;
int y1 = MHelper.floor(pos.getY() - (radius + 5) / 1.6);
int y2 = MHelper.floor(pos.getY() + (radius + 5) / 1.6);
double hr = radius * 0.75;
double nr = radius * 0.25;
Set<BlockPos> brimstone = Sets.newHashSet();
BlockState rock = EndBlocks.SULPHURIC_ROCK.stone.getDefaultState();
BlockState rock = EndBlocks.SULPHURIC_ROCK.stone.defaultBlockState();
int waterLevel = pos.getY() + MHelper.randRange(MHelper.floor(radius * 0.8), radius, random);
for (int x = x1; x <= x2; x++) {
int xsq = x - pos.getX();
@ -99,15 +100,14 @@ public class SulphuricCaveFeature extends DefaultFeature {
if (isReplaceable(state)) {
BlocksHelper.setWithoutUpdate(world, mut, y < waterLevel ? WATER : CAVE_AIR);
}
}
else if (dist < r2 * r2) {
} else if (dist < r2 * r2) {
state = world.getBlockState(mut);
if (state.isIn(EndTags.GEN_TERRAIN) || state.isOf(Blocks.AIR)) {
double v = noise.eval(x * 0.1, y * 0.1, z * 0.1) + noise.eval(x * 0.03, y * 0.03, z * 0.03) * 0.5;
if (state.isIn(EndTags.GEN_TERRAIN) || state.is(Blocks.AIR)) {
double v = noise.eval(x * 0.1, y * 0.1, z * 0.1)
+ noise.eval(x * 0.03, y * 0.03, z * 0.03) * 0.5;
if (v > 0.4) {
brimstone.add(mut.toImmutable());
}
else {
} else {
BlocksHelper.setWithoutUpdate(world, mut, rock);
}
}
@ -118,26 +118,30 @@ public class SulphuricCaveFeature extends DefaultFeature {
brimstone.forEach((blockPos) -> {
placeBrimstone(world, blockPos, random);
});
if (random.nextInt(4) == 0) {
int count = MHelper.randRange(5, 20, random);
for (int i = 0; i < count; i++) {
mut.set(pos).move(MHelper.floor(random.nextGaussian() * 2 + 0.5), 0, MHelper.floor(random.nextGaussian() * 2 + 0.5));
int dist = MHelper.floor(3 - MHelper.length(mut.getX() - pos.getX(), mut.getZ() - pos.getZ())) + random.nextInt(2);
mut.set(pos).move(MHelper.floor(random.nextGaussian() * 2 + 0.5), 0,
MHelper.floor(random.nextGaussian() * 2 + 0.5));
int dist = MHelper.floor(3 - MHelper.length(mut.getX() - pos.getX(), mut.getZ() - pos.getZ()))
+ random.nextInt(2);
if (dist > 0) {
state = world.getBlockState(mut);
while (!state.getFluidState().isEmpty() || state.getMaterial().equals(Material.UNDERWATER_PLANT)) {
mut.setY(mut.getY() - 1);
state = world.getBlockState(mut);
}
if (state.isIn(EndTags.GEN_TERRAIN) && !world.getBlockState(mut.up()).isOf(EndBlocks.HYDROTHERMAL_VENT)) {
if (state.isIn(EndTags.GEN_TERRAIN)
&& !world.getBlockState(mut.up()).is(EndBlocks.HYDROTHERMAL_VENT)) {
for (int j = 0; j <= dist; j++) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.SULPHURIC_ROCK.stone);
MHelper.shuffle(HORIZONTAL, random);
for (Direction dir: HORIZONTAL) {
for (Direction dir : HORIZONTAL) {
BlockPos p = mut.offset(dir);
if (random.nextBoolean() && world.getBlockState(p).isOf(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, p, EndBlocks.TUBE_WORM.getDefaultState().with(HorizontalFacingBlock.FACING, dir));
if (random.nextBoolean() && world.getBlockState(p).is(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, p, EndBlocks.TUBE_WORM.defaultBlockState()
.with(HorizontalFacingBlock.FACING, dir));
}
}
mut.setY(mut.getY() + 1);
@ -145,9 +149,10 @@ public class SulphuricCaveFeature extends DefaultFeature {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.HYDROTHERMAL_VENT);
mut.setY(mut.getY() + 1);
state = world.getBlockState(mut);
while (state.isOf(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.VENT_BUBBLE_COLUMN.getDefaultState());
world.getBlockTickScheduler().schedule(mut, EndBlocks.VENT_BUBBLE_COLUMN, MHelper.randRange(8, 32, random));
while (state.is(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.VENT_BUBBLE_COLUMN.defaultBlockState());
world.getBlockTickScheduler().schedule(mut, EndBlocks.VENT_BUBBLE_COLUMN,
MHelper.randRange(8, 32, random));
mut.setY(mut.getY() + 1);
state = world.getBlockState(mut);
}
@ -155,47 +160,42 @@ public class SulphuricCaveFeature extends DefaultFeature {
}
}
}
BlocksHelper.fixBlocks(world, new BlockPos(x1, y1, z1), new BlockPos(x2, y2, z2));
return true;
}
private boolean isReplaceable(BlockState state) {
return state.isIn(EndTags.GEN_TERRAIN)
|| state.isOf(EndBlocks.HYDROTHERMAL_VENT)
|| state.isOf(EndBlocks.VENT_BUBBLE_COLUMN)
|| state.isOf(EndBlocks.SULPHUR_CRYSTAL)
|| state.getMaterial().isReplaceable()
|| state.getMaterial().equals(Material.PLANT)
|| state.getMaterial().equals(Material.UNDERWATER_PLANT)
|| state.getMaterial().equals(Material.LEAVES);
return state.isIn(EndTags.GEN_TERRAIN) || state.is(EndBlocks.HYDROTHERMAL_VENT)
|| state.is(EndBlocks.VENT_BUBBLE_COLUMN) || state.is(EndBlocks.SULPHUR_CRYSTAL)
|| state.getMaterial().isReplaceable() || state.getMaterial().equals(Material.PLANT)
|| state.getMaterial().equals(Material.UNDERWATER_PLANT) || state.getMaterial().equals(Material.LEAVES);
}
private void placeBrimstone(StructureWorldAccess world, BlockPos pos, Random random) {
BlockState state = getBrimstone(world, pos);
BlocksHelper.setWithoutUpdate(world, pos, state);
if (state.get(BlockProperties.ACTIVE)) {
if (state.getValue(BlockProperties.ACTIVE)) {
makeShards(world, pos, random);
}
}
private BlockState getBrimstone(StructureWorldAccess world, BlockPos pos) {
for (Direction dir: BlocksHelper.DIRECTIONS) {
if (world.getBlockState(pos.offset(dir)).isOf(Blocks.WATER)) {
return EndBlocks.BRIMSTONE.getDefaultState().with(BlockProperties.ACTIVE, true);
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (world.getBlockState(pos.relative(dir)).is(Blocks.WATER)) {
return EndBlocks.BRIMSTONE.defaultBlockState().with(BlockProperties.ACTIVE, true);
}
}
return EndBlocks.BRIMSTONE.getDefaultState();
return EndBlocks.BRIMSTONE.defaultBlockState();
}
private void makeShards(StructureWorldAccess world, BlockPos pos, Random random) {
for (Direction dir: BlocksHelper.DIRECTIONS) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
BlockPos side;
if (random.nextInt(16) == 0 && world.getBlockState((side = pos.offset(dir))).isOf(Blocks.WATER)) {
BlockState state = EndBlocks.SULPHUR_CRYSTAL.getDefaultState()
.with(SulphurCrystalBlock.WATERLOGGED, true)
.with(SulphurCrystalBlock.FACING, dir)
if (random.nextInt(16) == 0 && world.getBlockState((side = pos.relative(dir))).is(Blocks.WATER)) {
BlockState state = EndBlocks.SULPHUR_CRYSTAL.defaultBlockState()
.with(SulphurCrystalBlock.WATERLOGGED, true).with(SulphurCrystalBlock.FACING, dir)
.with(SulphurCrystalBlock.AGE, random.nextInt(3));
BlocksHelper.setWithoutUpdate(world, side, state);
}

View file

@ -5,12 +5,12 @@ import java.util.Set;
import com.google.common.collect.Sets;
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.Fluids;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -25,24 +25,25 @@ import ru.betterend.world.features.DefaultFeature;
public class SulphuricLakeFeature extends DefaultFeature {
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(15152);
private static final Mutable POS = new Mutable();
private static final MutableBlockPos POS = new MutableBlockPos();
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig featureConfig) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos,
DefaultFeatureConfig featureConfig) {
blockPos = getPosOnSurfaceWG(world, blockPos);
if (blockPos.getY() < 57) {
return false;
}
double radius = MHelper.randRange(10.0, 20.0, random);
int dist2 = MHelper.floor(radius * 1.5);
int minX = blockPos.getX() - dist2;
int maxX = blockPos.getX() + dist2;
int minZ = blockPos.getZ() - dist2;
int maxZ = blockPos.getZ() + dist2;
Set<BlockPos> brimstone = Sets.newHashSet();
for (int x = minX; x <= maxX; x++) {
POS.setX(x);
@ -64,36 +65,33 @@ public class SulphuricLakeFeature extends DefaultFeature {
if (random.nextInt(8) > 0) {
brimstone.add(POS.toImmutable());
if (random.nextBoolean()) {
brimstone.add(POS.down());
brimstone.add(POS.below());
if (random.nextBoolean()) {
brimstone.add(POS.down(2));
}
}
}
else {
} else {
if (!isAbsoluteBorder(world, POS)) {
BlocksHelper.setWithoutUpdate(world, POS, Blocks.WATER);
world.getFluidTickScheduler().schedule(POS, Fluids.WATER, 0);
brimstone.add(POS.down());
brimstone.add(POS.below());
if (random.nextBoolean()) {
brimstone.add(POS.down(2));
if (random.nextBoolean()) {
brimstone.add(POS.down(3));
}
}
}
else {
} else {
brimstone.add(POS.toImmutable());
if (random.nextBoolean()) {
brimstone.add(POS.down());
brimstone.add(POS.below());
}
}
}
}
else {
} else {
BlocksHelper.setWithoutUpdate(world, POS, Blocks.WATER);
brimstone.remove(POS);
for (Direction dir: BlocksHelper.HORIZONTAL) {
for (Direction dir : BlocksHelper.HORIZONTAL) {
BlockPos offseted = POS.offset(dir);
if (world.getBlockState(offseted).isIn(EndTags.GEN_TERRAIN)) {
brimstone.add(offseted);
@ -102,14 +100,14 @@ public class SulphuricLakeFeature extends DefaultFeature {
if (isDeepWater(world, POS)) {
BlocksHelper.setWithoutUpdate(world, POS.move(Direction.DOWN), Blocks.WATER);
brimstone.remove(POS);
for (Direction dir: BlocksHelper.HORIZONTAL) {
for (Direction dir : BlocksHelper.HORIZONTAL) {
BlockPos offseted = POS.offset(dir);
if (world.getBlockState(offseted).isIn(EndTags.GEN_TERRAIN)) {
brimstone.add(offseted);
}
}
}
brimstone.add(POS.down());
brimstone.add(POS.below());
if (random.nextBoolean()) {
brimstone.add(POS.down(2));
if (random.nextBoolean()) {
@ -118,13 +116,12 @@ public class SulphuricLakeFeature extends DefaultFeature {
}
}
}
}
else if (dist < r2) {
} else if (dist < r2) {
POS.setY(getYOnSurface(world, x, z) - 1);
if (world.getBlockState(POS).isIn(EndTags.GEN_TERRAIN)) {
brimstone.add(POS.toImmutable());
if (random.nextBoolean()) {
brimstone.add(POS.down());
brimstone.add(POS.below());
if (random.nextBoolean()) {
brimstone.add(POS.down(2));
}
@ -133,37 +130,37 @@ public class SulphuricLakeFeature extends DefaultFeature {
}
}
}
brimstone.forEach((bpos) -> {
placeBrimstone(world, bpos, random);
});
return true;
}
private boolean isBorder(StructureWorldAccess world, BlockPos pos) {
int y = pos.getY() + 1;
for (Direction dir: BlocksHelper.DIRECTIONS) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (getYOnSurface(world, pos.getX() + dir.getOffsetX(), pos.getZ() + dir.getOffsetZ()) < y) {
return true;
}
}
return false;
}
private boolean isAbsoluteBorder(StructureWorldAccess world, BlockPos pos) {
int y = pos.getY() - 2;
for (Direction dir: BlocksHelper.DIRECTIONS) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (getYOnSurface(world, pos.getX() + dir.getOffsetX() * 3, pos.getZ() + dir.getOffsetZ() * 3) < y) {
return true;
}
}
return false;
}
private boolean isDeepWater(StructureWorldAccess world, BlockPos pos) {
int y = pos.getY() + 1;
for (Direction dir: BlocksHelper.DIRECTIONS) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (getYOnSurface(world, pos.getX() + dir.getOffsetX(), pos.getZ() + dir.getOffsetZ()) < y
|| getYOnSurface(world, pos.getX() + dir.getOffsetX() * 2, pos.getZ() + dir.getOffsetZ() * 2) < y
|| getYOnSurface(world, pos.getX() + dir.getOffsetX() * 3, pos.getZ() + dir.getOffsetZ() * 3) < y) {
@ -172,31 +169,30 @@ public class SulphuricLakeFeature extends DefaultFeature {
}
return true;
}
private void placeBrimstone(StructureWorldAccess world, BlockPos pos, Random random) {
BlockState state = getBrimstone(world, pos);
BlocksHelper.setWithoutUpdate(world, pos, state);
if (state.get(BlockProperties.ACTIVE)) {
if (state.getValue(BlockProperties.ACTIVE)) {
makeShards(world, pos, random);
}
}
private BlockState getBrimstone(StructureWorldAccess world, BlockPos pos) {
for (Direction dir: BlocksHelper.DIRECTIONS) {
if (world.getBlockState(pos.offset(dir)).isOf(Blocks.WATER)) {
return EndBlocks.BRIMSTONE.getDefaultState().with(BlockProperties.ACTIVE, true);
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (world.getBlockState(pos.relative(dir)).is(Blocks.WATER)) {
return EndBlocks.BRIMSTONE.defaultBlockState().with(BlockProperties.ACTIVE, true);
}
}
return EndBlocks.BRIMSTONE.getDefaultState();
return EndBlocks.BRIMSTONE.defaultBlockState();
}
private void makeShards(StructureWorldAccess world, BlockPos pos, Random random) {
for (Direction dir: BlocksHelper.DIRECTIONS) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
BlockPos side;
if (random.nextInt(16) == 0 && world.getBlockState((side = pos.offset(dir))).isOf(Blocks.WATER)) {
BlockState state = EndBlocks.SULPHUR_CRYSTAL.getDefaultState()
.with(SulphurCrystalBlock.WATERLOGGED, true)
.with(SulphurCrystalBlock.FACING, dir)
if (random.nextInt(16) == 0 && world.getBlockState((side = pos.relative(dir))).is(Blocks.WATER)) {
BlockState state = EndBlocks.SULPHUR_CRYSTAL.defaultBlockState()
.with(SulphurCrystalBlock.WATERLOGGED, true).with(SulphurCrystalBlock.FACING, dir)
.with(SulphurCrystalBlock.AGE, random.nextInt(3));
BlocksHelper.setWithoutUpdate(world, side, state);
}

View file

@ -2,9 +2,9 @@ package ru.betterend.world.features.terrain;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -17,25 +17,30 @@ import ru.betterend.world.features.DefaultFeature;
public class SurfaceVentFeature extends DefaultFeature {
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
pos = getPosOnSurface(world, new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16)));
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
pos = getPosOnSurface(world,
new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16)));
if (!world.getBlockState(pos.down(3)).isIn(EndTags.GEN_TERRAIN)) {
return false;
}
Mutable mut = new Mutable();
MutableBlockPos mut = new MutableBlockPos();
int count = MHelper.randRange(15, 30, random);
BlockState vent = EndBlocks.HYDROTHERMAL_VENT.getDefaultState().with(HydrothermalVentBlock.WATERLOGGED, false);
BlockState vent = EndBlocks.HYDROTHERMAL_VENT.defaultBlockState().with(HydrothermalVentBlock.WATERLOGGED,
false);
for (int i = 0; i < count; i++) {
mut.set(pos).move(MHelper.floor(random.nextGaussian() * 2 + 0.5), 5, MHelper.floor(random.nextGaussian() * 2 + 0.5));
int dist = MHelper.floor(2 - MHelper.length(mut.getX() - pos.getX(), mut.getZ() - pos.getZ())) + random.nextInt(2);
mut.set(pos).move(MHelper.floor(random.nextGaussian() * 2 + 0.5), 5,
MHelper.floor(random.nextGaussian() * 2 + 0.5));
int dist = MHelper.floor(2 - MHelper.length(mut.getX() - pos.getX(), mut.getZ() - pos.getZ()))
+ random.nextInt(2);
if (dist > 0) {
BlockState state = world.getBlockState(mut);
for (int n = 0; n < 10 && state.isAir(); n++) {
mut.setY(mut.getY() - 1);
state = world.getBlockState(mut);
}
if (state.isIn(EndTags.GEN_TERRAIN) && !world.getBlockState(mut.up()).isOf(EndBlocks.HYDROTHERMAL_VENT)) {
if (state.isIn(EndTags.GEN_TERRAIN) && !world.getBlockState(mut.up()).is(EndBlocks.HYDROTHERMAL_VENT)) {
for (int j = 0; j <= dist; j++) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.SULPHURIC_ROCK.stone);
mut.setY(mut.getY() + 1);
@ -44,7 +49,7 @@ public class SurfaceVentFeature extends DefaultFeature {
}
}
}
return true;
}
}

View file

@ -6,10 +6,10 @@ import java.util.function.Supplier;
import com.google.common.collect.Sets;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.chunk.ChunkGenerator;
@ -22,19 +22,20 @@ import ru.betterend.world.features.DefaultFeature;
public class CaveChunkPopulatorFeature extends DefaultFeature {
private Supplier<EndCaveBiome> supplier;
public CaveChunkPopulatorFeature(Supplier<EndCaveBiome> biome) {
this.supplier = biome;
}
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
Set<BlockPos> floorPositions = Sets.newHashSet();
Set<BlockPos> ceilPositions = Sets.newHashSet();
int sx = (pos.getX() >> 4) << 4;
int sz = (pos.getZ() >> 4) << 4;
Mutable min = new Mutable().set(pos);
Mutable max = new Mutable().set(pos);
MutableBlockPos min = new MutableBlockPos().set(pos);
MutableBlockPos max = new MutableBlockPos().set(pos);
fillSets(sx, sz, world.getChunk(pos), floorPositions, ceilPositions, min, max);
EndCaveBiome biome = supplier.get();
BlockState surfaceBlock = biome.getBiome().getGenerationSettings().getSurfaceConfig().getTopMaterial();
@ -43,11 +44,12 @@ public class CaveChunkPopulatorFeature extends DefaultFeature {
BlocksHelper.fixBlocks(world, min, max);
return true;
}
protected void fillSets(int sx, int sz, Chunk chunk, Set<BlockPos> floorPositions, Set<BlockPos> ceilPositions, Mutable min, Mutable max) {
Mutable mut = new Mutable();
Mutable mut2 = new Mutable();
Mutable mut3 = new Mutable();
protected void fillSets(int sx, int sz, Chunk chunk, Set<BlockPos> floorPositions, Set<BlockPos> ceilPositions,
MutableBlockPos min, MutableBlockPos max) {
MutableBlockPos mut = new MutableBlockPos();
MutableBlockPos mut2 = new MutableBlockPos();
MutableBlockPos mut3 = new MutableBlockPos();
for (int x = 0; x < 16; x++) {
mut.setX(x);
mut2.setX(x);
@ -59,13 +61,12 @@ public class CaveChunkPopulatorFeature extends DefaultFeature {
mut.setY(y);
BlockState top = chunk.getBlockState(mut);
BlockState bottom = chunk.getBlockState(mut2);
if (top.isAir() && (bottom.isIn(EndTags.GEN_TERRAIN) || bottom.isOf(Blocks.STONE))) {
if (top.isAir() && (bottom.isIn(EndTags.GEN_TERRAIN) || bottom.is(Blocks.STONE))) {
mut3.set(mut2).move(sx, 0, sz);
floorPositions.add(mut3.toImmutable());
updateMin(mut3, min);
updateMax(mut3, max);
}
else if (bottom.isAir() && (top.isIn(EndTags.GEN_TERRAIN)|| top.isOf(Blocks.STONE))) {
} else if (bottom.isAir() && (top.isIn(EndTags.GEN_TERRAIN) || top.is(Blocks.STONE))) {
mut3.set(mut).move(sx, 0, sz);
ceilPositions.add(mut3.toImmutable());
updateMin(mut3, min);
@ -76,8 +77,8 @@ public class CaveChunkPopulatorFeature extends DefaultFeature {
}
}
}
private void updateMin(BlockPos pos, Mutable min) {
private void updateMin(BlockPos pos, MutableBlockPos min) {
if (pos.getX() < min.getX()) {
min.setX(pos.getX());
}
@ -88,8 +89,8 @@ public class CaveChunkPopulatorFeature extends DefaultFeature {
min.setZ(pos.getZ());
}
}
private void updateMax(BlockPos pos, Mutable max) {
private void updateMax(BlockPos pos, MutableBlockPos max) {
if (pos.getX() > max.getX()) {
max.setX(pos.getX());
}
@ -100,8 +101,9 @@ public class CaveChunkPopulatorFeature extends DefaultFeature {
max.setZ(pos.getZ());
}
}
protected void placeFloor(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> floorPositions, Random random, BlockState surfaceBlock) {
protected void placeFloor(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> floorPositions,
Random random, BlockState surfaceBlock) {
float density = biome.getFloorDensity();
floorPositions.forEach((pos) -> {
BlocksHelper.setWithoutUpdate(world, pos, surfaceBlock);
@ -113,8 +115,9 @@ public class CaveChunkPopulatorFeature extends DefaultFeature {
}
});
}
protected void placeCeil(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> ceilPositions, Random random) {
protected void placeCeil(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> ceilPositions,
Random random) {
float density = biome.getCeilDensity();
ceilPositions.forEach((pos) -> {
BlockState ceilBlock = biome.getCeil(pos);
@ -124,7 +127,7 @@ public class CaveChunkPopulatorFeature extends DefaultFeature {
if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getCeilFeature(random);
if (feature != null) {
feature.generate(world, null, random, pos.down(), null);
feature.generate(world, null, random, pos.below(), null);
}
}
});

View file

@ -5,11 +5,11 @@ import java.util.Set;
import com.google.common.collect.Sets;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.Direction;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.Heightmap;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.biome.Biome;
@ -27,27 +27,29 @@ import ru.betterend.world.features.DefaultFeature;
import ru.betterend.world.generator.GeneratorOptions;
public abstract class EndCaveFeature extends DefaultFeature {
protected static final BlockState CAVE_AIR = Blocks.CAVE_AIR.getDefaultState();
protected static final BlockState END_STONE = Blocks.END_STONE.getDefaultState();
protected static final BlockState WATER = Blocks.WATER.getDefaultState();
protected static final BlockState CAVE_AIR = Blocks.CAVE_AIR.defaultBlockState();
protected static final BlockState END_STONE = Blocks.END_STONE.defaultBlockState();
protected static final BlockState WATER = Blocks.WATER.defaultBlockState();
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
if (!(GeneratorOptions.useNewGenerator() && GeneratorOptions.noRingVoid()) || pos.getX() * pos.getX() + pos.getZ() * pos.getZ() <= 22500) {
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
DefaultFeatureConfig config) {
if (!(GeneratorOptions.useNewGenerator() && GeneratorOptions.noRingVoid())
|| pos.getX() * pos.getX() + pos.getZ() * pos.getZ() <= 22500) {
return false;
}
if (biomeMissingCaves(world, pos)) {
return false;
}
int radius = MHelper.randRange(10, 30, random);
BlockPos center = findPos(world, pos, radius, random);
if (center == null) {
return false;
}
EndCaveBiome biome = EndBiomes.getCaveBiome(random);
Set<BlockPos> caveBlocks = generate(world, center, radius, random);
if (!caveBlocks.isEmpty()) {
@ -55,7 +57,7 @@ public abstract class EndCaveFeature extends DefaultFeature {
setBiomes(world, biome, caveBlocks);
Set<BlockPos> floorPositions = Sets.newHashSet();
Set<BlockPos> ceilPositions = Sets.newHashSet();
Mutable mut = new Mutable();
MutableBlockPos mut = new MutableBlockPos();
caveBlocks.forEach((bpos) -> {
mut.set(bpos);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
@ -75,13 +77,14 @@ public abstract class EndCaveFeature extends DefaultFeature {
}
fixBlocks(world, caveBlocks);
}
return true;
}
protected abstract Set<BlockPos> generate(StructureWorldAccess world, BlockPos center, int radius, Random random);
protected void placeFloor(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> floorPositions, Random random, BlockState surfaceBlock) {
protected void placeFloor(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> floorPositions,
Random random, BlockState surfaceBlock) {
float density = biome.getFloorDensity();
floorPositions.forEach((pos) -> {
BlocksHelper.setWithoutUpdate(world, pos, surfaceBlock);
@ -93,8 +96,9 @@ public abstract class EndCaveFeature extends DefaultFeature {
}
});
}
protected void placeCeil(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> ceilPositions, Random random) {
protected void placeCeil(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> ceilPositions,
Random random) {
float density = biome.getCeilDensity();
ceilPositions.forEach((pos) -> {
BlockState ceilBlock = biome.getCeil(pos);
@ -104,30 +108,30 @@ public abstract class EndCaveFeature extends DefaultFeature {
if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getCeilFeature(random);
if (feature != null) {
feature.generate(world, null, random, pos.down(), null);
feature.generate(world, null, random, pos.below(), null);
}
}
});
}
protected void setBiomes(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> blocks) {
blocks.forEach((pos) -> setBiome(world, pos, biome));
}
private void setBiome(StructureWorldAccess world, BlockPos pos, EndCaveBiome biome) {
IBiomeArray array = (IBiomeArray) world.getChunk(pos).getBiomeArray();
if (array != null) {
array.setBiome(biome.getActualBiome(), pos);
}
}
private BlockPos findPos(StructureWorldAccess world, BlockPos pos, int radius, Random random) {
int top = world.getTopY(Heightmap.Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
Mutable bpos = new Mutable();
MutableBlockPos bpos = new MutableBlockPos();
bpos.setX(pos.getX());
bpos.setZ(pos.getZ());
bpos.setY(top - 1);
BlockState state = world.getBlockState(bpos);
while (!state.isIn(EndTags.GEN_TERRAIN) && bpos.getY() > 5) {
bpos.setY(bpos.getY() - 1);
@ -137,24 +141,24 @@ public abstract class EndCaveFeature extends DefaultFeature {
return null;
}
top = (int) (bpos.getY() - (radius * 1.3F + 5));
while (state.isIn(EndTags.GEN_TERRAIN) || !state.getFluidState().isEmpty() && bpos.getY() > 5) {
bpos.setY(bpos.getY() - 1);
state = world.getBlockState(bpos);
}
int bottom = (int) (bpos.getY() + radius * 1.3F + 5);
if (top <= bottom) {
return null;
}
return new BlockPos(pos.getX(), MHelper.randRange(bottom, top, random), pos.getZ());
}
private void fixBlocks(StructureWorldAccess world, Set<BlockPos> caveBlocks) {
BlockPos pos = caveBlocks.iterator().next();
Mutable start = new Mutable().set(pos);
Mutable end = new Mutable().set(pos);
MutableBlockPos start = new MutableBlockPos().set(pos);
MutableBlockPos end = new MutableBlockPos().set(pos);
caveBlocks.forEach((bpos) -> {
if (bpos.getX() < start.getX()) {
start.setX(bpos.getX());
@ -162,14 +166,14 @@ public abstract class EndCaveFeature extends DefaultFeature {
if (bpos.getX() > end.getX()) {
end.setX(bpos.getX());
}
if (bpos.getY() < start.getY()) {
start.setY(bpos.getY());
}
if (bpos.getY() > end.getY()) {
end.setY(bpos.getY());
}
if (bpos.getZ() < start.getZ()) {
start.setZ(bpos.getZ());
}
@ -179,20 +183,20 @@ public abstract class EndCaveFeature extends DefaultFeature {
});
BlocksHelper.fixBlocks(world, start.add(-5, -5, -5), end.add(5, 5, 5));
}
protected boolean isWaterNear(StructureWorldAccess world, BlockPos pos) {
for (Direction dir: BlocksHelper.DIRECTIONS) {
if (!world.getFluidState(pos.offset(dir, 5)).isEmpty()) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (!world.getFluidState(pos.relative(dir, 5)).isEmpty()) {
return true;
}
}
return false;
}
protected boolean biomeMissingCaves(StructureWorldAccess world, BlockPos pos) {
for (int x = -2; x < 3; x++) {
for (int z = -2; z < 3; z++) {
Biome biome = world.getBiome(pos.add(x << 4, 0, z << 4));
Biome biome = world.getBiome(pos.offset(x << 4, 0, z << 4));
EndBiome endBiome = EndBiomes.getFromBiome(biome);
if (!endBiome.hasCaves()) {
return true;

View file

@ -5,10 +5,10 @@ import java.util.Set;
import com.google.common.collect.Sets;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.world.StructureWorldAccess;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.EndTags;
@ -19,19 +19,19 @@ public class RoundCaveFeature extends EndCaveFeature {
@Override
protected Set<BlockPos> generate(StructureWorldAccess world, BlockPos center, int radius, Random random) {
OpenSimplexNoise noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ()));
int x1 = center.getX() - radius - 5;
int z1 = center.getZ() - radius - 5;
int x2 = center.getX() + radius + 5;
int z2 = center.getZ() + radius + 5;
int y1 = MHelper.floor(center.getY() - (radius + 5) / 1.6);
int y2 = MHelper.floor(center.getY() + (radius + 5) / 1.6);
double hr = radius * 0.75;
double nr = radius * 0.25;
BlockState state;
Mutable bpos = new Mutable();
MutableBlockPos bpos = new MutableBlockPos();
Set<BlockPos> blocks = Sets.newHashSet();
for (int x = x1; x <= x2; x++) {
int xsq = x - center.getX();
@ -53,13 +53,13 @@ public class RoundCaveFeature extends EndCaveFeature {
if (isReplaceable(state) && !isWaterNear(world, bpos)) {
BlocksHelper.setWithoutUpdate(world, bpos, CAVE_AIR);
blocks.add(bpos.toImmutable());
while (state.getMaterial().equals(Material.LEAVES)) {
BlocksHelper.setWithoutUpdate(world, bpos, CAVE_AIR);
bpos.setY(bpos.getY() + 1);
state = world.getBlockState(bpos);
}
bpos.setY(y - 1);
while (state.getMaterial().equals(Material.LEAVES)) {
BlocksHelper.setWithoutUpdate(world, bpos, CAVE_AIR);
@ -71,14 +71,12 @@ public class RoundCaveFeature extends EndCaveFeature {
}
}
}
return blocks;
}
private boolean isReplaceable(BlockState state) {
return state.isIn(EndTags.GEN_TERRAIN)
|| state.getMaterial().isReplaceable()
|| state.getMaterial().equals(Material.PLANT)
|| state.getMaterial().equals(Material.LEAVES);
return state.isIn(EndTags.GEN_TERRAIN) || state.getMaterial().isReplaceable()
|| state.getMaterial().equals(Material.PLANT) || state.getMaterial().equals(Material.LEAVES);
}
}

View file

@ -5,12 +5,12 @@ import java.util.Random;
import java.util.Set;
import java.util.function.Function;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Material;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.StructureWorldAccess;
import ru.betterend.registry.EndTags;
import ru.betterend.util.BlocksHelper;
@ -19,36 +19,35 @@ import ru.betterend.util.sdf.SDF;
public class TunelCaveFeature extends EndCaveFeature {
private static final Function<BlockState, Boolean> REPLACE;
@Override
protected Set<BlockPos> generate(StructureWorldAccess world, BlockPos center, int radius, Random random) {
//OpenSimplexNoise noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ()));
// OpenSimplexNoise noise = new OpenSimplexNoise(MHelper.getSeed(534,
// center.getX(), center.getZ()));
float rad = radius * 0.15F;
int min = MathHelper.ceil(rad) - 15;
int max = 31 - MathHelper.floor(rad);
int min = Mth.ceil(rad) - 15;
int max = 31 - Mth.floor(rad);
List<Vector3f> spline = SplineHelper.makeSpline(0, 0, 0, 0, 0, 0, radius / 3);
spline = SplineHelper.smoothSpline(spline, 5);
SplineHelper.offsetParts(spline, random, 5, radius * 0.4F, 5);
for (Vector3f vec: spline) {
float x = MathHelper.clamp(vec.getX(), min, max);
float y = MathHelper.clamp(vec.getY(), -radius, radius);
float z = MathHelper.clamp(vec.getZ(), min, max);
for (Vector3f vec : spline) {
float x = Mth.clamp(vec.getX(), min, max);
float y = Mth.clamp(vec.getY(), -radius, radius);
float z = Mth.clamp(vec.getZ(), min, max);
vec.set(x, y, z);
}
SDF sdf = SplineHelper.buildSDF(spline, rad, rad, (vec) -> Blocks.AIR.getDefaultState());
SDF sdf = SplineHelper.buildSDF(spline, rad, rad, (vec) -> Blocks.AIR.defaultBlockState());
Set<BlockPos> positions = sdf.setReplaceFunction(REPLACE).getPositions(world, center);
for (BlockPos p: positions) {
for (BlockPos p : positions) {
BlocksHelper.setWithoutUpdate(world, p, CAVE_AIR);
}
return positions;
}
static {
REPLACE = (state) -> {
return state.isIn(EndTags.GEN_TERRAIN)
|| state.getMaterial().isReplaceable()
|| state.getMaterial().equals(Material.PLANT)
|| state.getMaterial().equals(Material.LEAVES);
return state.isIn(EndTags.GEN_TERRAIN) || state.getMaterial().isReplaceable()
|| state.getMaterial().equals(Material.PLANT) || state.getMaterial().equals(Material.LEAVES);
};
}
}