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,18 +54,48 @@ 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];
for (int x = minX; x <= maxX; x++) {
POS.setX(x);
int mx = x - maskMinX;
for (int z = minZ; z <= maxZ; z++) {
POS.setZ(z);
int mz = z - maskMinZ;
if (!mask[mx][mz]) {
for (int y = waterLevel; y <= blockPos.getY() + 10; y++) {
POS.setY(y); POS.setY(y);
int add = y - blockPos.getY(); FluidState fluid = world.getFluidState(POS);
if (!fluid.isEmpty()) {
mask[mx][mz] = true;
mask[mx + 1][mz] = true;
mask[mx - 1][mz] = true;
mask[mx][mz + 1] = true;
mask[mx][mz - 1] = true;
break;
}
}
}
}
}
for (int x = minX; x <= maxX; x++) { for (int x = minX; x <= maxX; x++) {
POS.setX(x); POS.setX(x);
int x2 = x - blockPos.getX(); int x2 = x - blockPos.getX();
x2 *= x2; x2 *= x2;
int mx = x - maskMinX;
for (int z = minZ; z <= maxZ; z++) { for (int z = minZ; z <= maxZ; z++) {
POS.setZ(z); POS.setZ(z);
int z2 = z - blockPos.getZ(); int z2 = z - blockPos.getZ();
z2 *= z2; 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); double r = add * 1.8 + radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75);
r *= r; r *= r;
if (x2 + z2 <= r) { if (x2 + z2 <= r) {
@ -73,8 +104,7 @@ public class EndLakeFeature extends DefaultFeature {
BlocksHelper.setWithoutUpdate(world, POS, AIR); BlocksHelper.setWithoutUpdate(world, POS, AIR);
} }
pos = POS.down(); pos = POS.down();
if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
{
state = world.getBiome(pos).getGenerationSettings().getSurfaceConfig().getTopMaterial(); state = world.getBiome(pos).getGenerationSettings().getSurfaceConfig().getTopMaterial();
if (y > waterLevel + 1) if (y > waterLevel + 1)
BlocksHelper.setWithoutUpdate(world, pos, state); BlocksHelper.setWithoutUpdate(world, pos, state);
@ -87,32 +117,39 @@ 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);
double y2 = (double) (y - blockPos.getY()) * aspect;
y2 *= y2;
for (int x = blockPos.getX() - dist; x <= blockPos.getX() + dist; x++) { for (int x = blockPos.getX() - dist; x <= blockPos.getX() + dist; x++) {
POS.setX(x); POS.setX(x);
int x2 = x - blockPos.getX(); int x2 = x - blockPos.getX();
x2 *= x2; x2 *= x2;
int mx = x - maskMinX;
for (int z = blockPos.getZ() - dist; z <= blockPos.getZ() + dist; z++) { for (int z = blockPos.getZ() - dist; z <= blockPos.getZ() + dist; z++) {
POS.setZ(z); POS.setZ(z);
int z2 = z - blockPos.getZ(); int z2 = z - blockPos.getZ();
z2 *= z2; z2 *= z2;
int mz = z - maskMinZ;
if (!mask[mx][mz]) {
for (int y = blockPos.getY() - bott; y < blockPos.getY(); y++) {
POS.setY(y);
double y2 = (double) (y - blockPos.getY()) * aspect;
y2 *= y2;
double r = radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75); double r = radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75);
double rb = r * 1.2; double rb = r * 1.2;
r *= r; r *= r;
rb *= rb; rb *= rb;
if (y2 + x2 + z2 <= r) { if (y2 + x2 + z2 <= r) {
state = world.getBlockState(POS); state = world.getBlockState(POS);
if (state.isIn(BlockTagRegistry.END_GROUND) || state.getBlock() == BlockRegistry.ENDSTONE_DUST) { if (state.isIn(BlockTagRegistry.END_GROUND)
|| state.getBlock() == BlockRegistry.ENDSTONE_DUST) {
BlocksHelper.setWithoutUpdate(world, POS, y < waterLevel ? WATER : AIR); BlocksHelper.setWithoutUpdate(world, POS, y < waterLevel ? WATER : AIR);
} }
pos = POS.down(); pos = POS.down();
if (world.getBlockState(pos).getBlock().isIn(BlockTagRegistry.END_GROUND)) if (world.getBlockState(pos).getBlock().isIn(BlockTagRegistry.END_GROUND))
BlocksHelper.setWithoutUpdate(world, POS.down(), BlockRegistry.ENDSTONE_DUST.getDefaultState()); BlocksHelper.setWithoutUpdate(world, POS.down(),
BlockRegistry.ENDSTONE_DUST.getDefaultState());
pos = POS.up(); pos = POS.up();
if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) { if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
while (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) { while (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
@ -120,17 +157,19 @@ public class EndLakeFeature extends DefaultFeature {
pos = pos.up(); pos = pos.up();
} }
} }
} } else if (y <= waterLevel && y2 + x2 + z2 <= rb) {
else if (y <= waterLevel && y2 + x2 + z2 <= rb) {
if (world.getBlockState(POS).getMaterial().isReplaceable()) { if (world.getBlockState(POS).getMaterial().isReplaceable()) {
if (world.isAir(POS.up())) { if (world.isAir(POS.up())) {
state = world.getBiome(POS).getGenerationSettings().getSurfaceConfig().getTopMaterial(); state = world.getBiome(POS).getGenerationSettings().getSurfaceConfig()
BlocksHelper.setWithoutUpdate(world, POS, random.nextBoolean() ? state : BlockRegistry.ENDSTONE_DUST.getDefaultState()); .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); 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;