Lake water mask

This commit is contained in:
paulevsGitch 2020-10-03 23:39:35 +03:00
parent 8beabd0f96
commit 06788313a1
2 changed files with 106 additions and 68 deletions

View file

@ -4,6 +4,7 @@ import java.util.Random;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.fluid.FluidState;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable; import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.world.StructureWorldAccess; import net.minecraft.world.StructureWorldAccess;
@ -53,35 +54,65 @@ public class EndLakeFeature extends DefaultFeature {
int maxX = blockPos.getX() + dist2; int maxX = blockPos.getX() + dist2;
int minZ = blockPos.getZ() - dist2; int minZ = blockPos.getZ() - dist2;
int maxZ = blockPos.getZ() + dist2; int maxZ = blockPos.getZ() + dist2;
int maskMinX = minX - 1;
int maskMinZ = minZ - 1;
for (int y = blockPos.getY(); y <= blockPos.getY() + 10; y++) { boolean[][] mask = new boolean[maxX - minX + 3][maxZ - minZ + 3];
POS.setY(y); for (int x = minX; x <= maxX; x++) {
int add = y - blockPos.getY(); POS.setX(x);
for (int x = minX; x <= maxX; x++) { int mx = x - maskMinX;
POS.setX(x); for (int z = minZ; z <= maxZ; z++) {
int x2 = x - blockPos.getX(); POS.setZ(z);
x2 *= x2; int mz = z - maskMinZ;
for (int z = minZ; z <= maxZ; z++) { if (!mask[mx][mz]) {
POS.setZ(z); for (int y = waterLevel; y <= blockPos.getY() + 10; y++) {
int z2 = z - blockPos.getZ(); POS.setY(y);
z2 *= z2; FluidState fluid = world.getFluidState(POS);
double r = add * 1.8 + radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75); if (!fluid.isEmpty()) {
r *= r; mask[mx][mz] = true;
if (x2 + z2 <= r) { mask[mx + 1][mz] = true;
state = world.getBlockState(POS); mask[mx - 1][mz] = true;
if (state.isIn(BlockTagRegistry.END_GROUND)) { mask[mx][mz + 1] = true;
BlocksHelper.setWithoutUpdate(world, POS, AIR); mask[mx][mz - 1] = true;
break;
} }
pos = POS.down(); }
if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) }
{ }
state = world.getBiome(pos).getGenerationSettings().getSurfaceConfig().getTopMaterial(); }
if (y > waterLevel + 1)
BlocksHelper.setWithoutUpdate(world, pos, state);
else if (y > waterLevel) for (int x = minX; x <= maxX; x++) {
BlocksHelper.setWithoutUpdate(world, pos, random.nextBoolean() ? state : BlockRegistry.ENDSTONE_DUST.getDefaultState()); POS.setX(x);
else int x2 = x - blockPos.getX();
BlocksHelper.setWithoutUpdate(world, pos, BlockRegistry.ENDSTONE_DUST.getDefaultState()); x2 *= x2;
int mx = x - maskMinX;
for (int z = minZ; z <= maxZ; z++) {
POS.setZ(z);
int z2 = z - blockPos.getZ();
z2 *= z2;
int mz = z - maskMinZ;
if (!mask[mx][mz]) {
for (int y = blockPos.getY(); y <= blockPos.getY() + 10; y++) {
POS.setY(y);
int add = y - blockPos.getY();
double r = add * 1.8 + radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75);
r *= r;
if (x2 + z2 <= r) {
state = world.getBlockState(POS);
if (state.isIn(BlockTagRegistry.END_GROUND)) {
BlocksHelper.setWithoutUpdate(world, POS, AIR);
}
pos = POS.down();
if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
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 : BlockRegistry.ENDSTONE_DUST.getDefaultState());
else
BlocksHelper.setWithoutUpdate(world, pos, BlockRegistry.ENDSTONE_DUST.getDefaultState());
}
} }
} }
} }
@ -89,48 +120,56 @@ public class EndLakeFeature extends DefaultFeature {
} }
double aspect = ((double) radius / (double) depth); double aspect = ((double) radius / (double) depth);
for (int y = blockPos.getY() - bott; y < blockPos.getY(); y++) {
POS.setY(y); for (int x = blockPos.getX() - dist; x <= blockPos.getX() + dist; x++) {
double y2 = (double) (y - blockPos.getY()) * aspect; POS.setX(x);
y2 *= y2; int x2 = x - blockPos.getX();
for (int x = blockPos.getX() - dist; x <= blockPos.getX() + dist; x++) { x2 *= x2;
POS.setX(x); int mx = x - maskMinX;
int x2 = x - blockPos.getX(); for (int z = blockPos.getZ() - dist; z <= blockPos.getZ() + dist; z++) {
x2 *= x2; POS.setZ(z);
for (int z = blockPos.getZ() - dist; z <= blockPos.getZ() + dist; z++) { int z2 = z - blockPos.getZ();
POS.setZ(z); z2 *= z2;
int z2 = z - blockPos.getZ(); int mz = z - maskMinZ;
z2 *= z2; if (!mask[mx][mz]) {
double r = radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75); for (int y = blockPos.getY() - bott; y < blockPos.getY(); y++) {
double rb = r * 1.2; POS.setY(y);
r *= r; double y2 = (double) (y - blockPos.getY()) * aspect;
rb *= rb; y2 *= y2;
if (y2 + x2 + z2 <= r) { double r = radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75);
state = world.getBlockState(POS); double rb = r * 1.2;
if (state.isIn(BlockTagRegistry.END_GROUND) || state.getBlock() == BlockRegistry.ENDSTONE_DUST) { r *= r;
BlocksHelper.setWithoutUpdate(world, POS, y < waterLevel ? WATER : AIR); rb *= rb;
} if (y2 + x2 + z2 <= r) {
pos = POS.down(); state = world.getBlockState(POS);
if (world.getBlockState(pos).getBlock().isIn(BlockTagRegistry.END_GROUND)) if (state.isIn(BlockTagRegistry.END_GROUND)
BlocksHelper.setWithoutUpdate(world, POS.down(), BlockRegistry.ENDSTONE_DUST.getDefaultState()); || state.getBlock() == BlockRegistry.ENDSTONE_DUST) {
pos = POS.up(); BlocksHelper.setWithoutUpdate(world, POS, y < waterLevel ? WATER : AIR);
if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
while (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
BlocksHelper.setWithoutUpdate(world, pos, pos.getY() < waterLevel ? WATER : AIR);
pos = pos.up();
} }
} pos = POS.down();
} if (world.getBlockState(pos).getBlock().isIn(BlockTagRegistry.END_GROUND))
else if (y <= waterLevel && y2 + x2 + z2 <= rb) { BlocksHelper.setWithoutUpdate(world, POS.down(),
if (world.getBlockState(POS).getMaterial().isReplaceable()) { BlockRegistry.ENDSTONE_DUST.getDefaultState());
if (world.isAir(POS.up())) { pos = POS.up();
state = world.getBiome(POS).getGenerationSettings().getSurfaceConfig().getTopMaterial(); if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
BlocksHelper.setWithoutUpdate(world, POS, random.nextBoolean() ? state : BlockRegistry.ENDSTONE_DUST.getDefaultState()); while (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
BlocksHelper.setWithoutUpdate(world, POS.down(), END_STONE); BlocksHelper.setWithoutUpdate(world, pos, pos.getY() < waterLevel ? WATER : AIR);
pos = pos.up();
}
} }
else { } else if (y <= waterLevel && y2 + x2 + z2 <= rb) {
BlocksHelper.setWithoutUpdate(world, POS, BlockRegistry.ENDSTONE_DUST.getDefaultState()); if (world.getBlockState(POS).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, POS.down(), END_STONE); if (world.isAir(POS.up())) {
state = world.getBiome(POS).getGenerationSettings().getSurfaceConfig()
.getTopMaterial();
BlocksHelper.setWithoutUpdate(world, POS, random.nextBoolean() ? state
: BlockRegistry.ENDSTONE_DUST.getDefaultState());
BlocksHelper.setWithoutUpdate(world, POS.down(), END_STONE);
} else {
BlocksHelper.setWithoutUpdate(world, POS,
BlockRegistry.ENDSTONE_DUST.getDefaultState());
BlocksHelper.setWithoutUpdate(world, POS.down(), END_STONE);
}
} }
} }
} }

View file

@ -6,7 +6,6 @@ import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material; import net.minecraft.block.Material;
import net.minecraft.client.util.math.Vector3f; import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;