End lily water fix, some cleanup

This commit is contained in:
paulevsGitch 2020-10-22 22:55:24 +03:00
parent 04eb5f9dff
commit 11a0d52061
8 changed files with 118 additions and 31 deletions

View file

@ -9,6 +9,7 @@ import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.block.ShapeContext;
import net.minecraft.fluid.FluidState;
@ -19,9 +20,11 @@ import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import ru.betterend.blocks.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.BlockUnderwaterPlant;
@ -43,6 +46,16 @@ public class BlockEndLily extends BlockUnderwaterPlant {
.noCollision());
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (!canPlaceAt(state, world, pos)) {
return state.get(SHAPE) == TripleShape.TOP ? Blocks.AIR.getDefaultState() : Blocks.WATER.getDefaultState();
}
else {
return state;
}
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
Vec3d vec3d = state.getModelOffset(view, pos);

View file

@ -24,8 +24,7 @@ public class LocateCommandMixin {
private static SimpleCommandExceptionType FAILED_EXCEPTION;
@Shadow
public static int sendCoordinates(ServerCommandSource source, String structure, BlockPos sourcePos,
BlockPos structurePos, String successMessage) {
public static int sendCoordinates(ServerCommandSource source, String structure, BlockPos sourcePos, BlockPos structurePos, String successMessage) {
return 0;
}
@ -36,7 +35,8 @@ public class LocateCommandMixin {
BlockPos blockPos2 = StructureHelper.getNearestStructure(structureFeature, source.getWorld(), blockPos, 100);
if (blockPos2 == null) {
throw FAILED_EXCEPTION.create();
} else {
}
else {
info.setReturnValue(sendCoordinates(source, structureFeature.getName(), blockPos, blockPos2, "commands.locate.success"));
info.cancel();
}

View file

@ -140,7 +140,19 @@ public class BlocksHelper {
// Liquids
if (!state.getFluidState().isEmpty()) {
continue;
POS.setY(y - 1);
if (world.isAir(POS)) {
POS.setY(y);
while (!world.getFluidState(POS).isEmpty()) {
setWithoutUpdate(world, POS, AIR);
POS.setY(POS.getY() + 1);
}
}
else for (Direction dir: HORIZONTAL) {
if (world.getBlockState(POS.offset(dir)).getMaterial().isReplaceable()) {
world.getFluidTickScheduler().schedule(POS, state.getFluidState().getFluid(), 0);
}
}
}
// Falling blocks
else if (state.getBlock() instanceof FallingBlock) {

View file

@ -158,9 +158,9 @@ public class EndLakeFeature extends DefaultFeature {
state = world.getBlockState(POS.up());
state = canReplace(state) ? (y < waterLevel ? WATER : AIR) : state;
BlocksHelper.setWithoutUpdate(world, POS, state);
if (y == waterLevel - 1 && !state.getFluidState().isEmpty()) {
/*if (y == waterLevel - 1 && !state.getFluidState().isEmpty()) {
world.getFluidTickScheduler().schedule(POS, state.getFluidState().getFluid(), 0);
}
}*/
}
pos = POS.down();
if (world.getBlockState(pos).getBlock().isIn(BlockTagRegistry.GEN_TERRAIN)) {
@ -169,9 +169,9 @@ public class EndLakeFeature extends DefaultFeature {
pos = POS.up();
while (canReplace(state = world.getBlockState(pos)) && !state.isAir() && state.getFluidState().isEmpty()) {
BlocksHelper.setWithoutUpdate(world, pos, pos.getY() < waterLevel ? WATER : AIR);
if (y == waterLevel - 1) {
/*if (y == waterLevel - 1) {
world.getFluidTickScheduler().schedule(POS, WATER.getFluidState().getFluid(), 0);
}
}*/
pos = pos.up();
}
}

View file

@ -6,6 +6,7 @@ import java.util.Set;
import com.google.common.collect.Sets;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.BlockPos;
@ -37,8 +38,8 @@ public class RoundCaveFeature extends DefaultFeature {
}
int radius = MHelper.randRange(10, 30, random);
int bottom = BlocksHelper.upRay(world, new BlockPos(pos.getX(), 0, pos.getZ()), 32) + radius;
int top = world.getTopY(Heightmap.Type.WORLD_SURFACE, pos.getX(), pos.getZ()) - radius;
int bottom = BlocksHelper.upRay(world, new BlockPos(pos.getX(), 0, pos.getZ()), 32) + radius + 5;
int top = world.getTopY(Heightmap.Type.WORLD_SURFACE, pos.getX(), pos.getZ()) - radius - 5;
Mutable bpos = new Mutable();
bpos.setX(pos.getX());
@ -56,12 +57,12 @@ public class RoundCaveFeature extends DefaultFeature {
OpenSimplexNoise noise = new OpenSimplexNoise(MHelper.getSeed(534, pos.getX(), pos.getZ()));
int x1 = pos.getX() - radius;
int z1 = pos.getZ() - radius;
int x2 = pos.getX() + radius;
int z2 = pos.getZ() + radius;
int y1 = MHelper.floor(pos.getY() - radius / 1.6);
int y2 = MHelper.floor(pos.getY() + radius / 1.6);
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;
@ -82,6 +83,7 @@ public class RoundCaveFeature extends DefaultFeature {
ysq *= ysq;
bpos.setY(y);
double r = noise.eval(x * 0.1, y * 0.1, z * 0.1) * nr + hr;
double r2 = r + 5;
double dist = xsq + ysq + zsq;
if (dist < r * r) {
BlockState state = world.getBlockState(bpos);
@ -106,6 +108,11 @@ public class RoundCaveFeature extends DefaultFeature {
BlocksHelper.setWithoutUpdate(world, bpos, terrain);
}
}
else if (dist < r2 * r2) {
BlockState state = world.getBlockState(bpos);
if (!state.getFluidState().isEmpty()) {
BlocksHelper.setWithoutUpdate(world, bpos, Blocks.END_STONE.getDefaultState());
}
else if (world.getBlockState(bpos).isIn(BlockTagRegistry.GEN_TERRAIN)) {
if (world.isAir(bpos.down())) {
int h = BlocksHelper.downRay(world, bpos.down(), 64);
@ -123,6 +130,7 @@ public class RoundCaveFeature extends DefaultFeature {
}
}
}
}
bushes.forEach((cpos) -> {
if (random.nextInt(32) == 0) {
generateBush(world, random, cpos);

View file

@ -1,7 +1,10 @@
package ru.betterend.world.structures.piece;
import java.util.Map;
import java.util.Random;
import com.google.common.collect.Maps;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.nbt.CompoundTag;
@ -27,6 +30,7 @@ import ru.betterend.util.MHelper;
public class LakePiece extends BasePiece {
private static final BlockState WATER = Blocks.WATER.getDefaultState();
private Map<Integer, Integer> heightmap = Maps.newHashMap();
private OpenSimplexNoise noise;
private BlockPos center;
private float radius;
@ -136,14 +140,31 @@ public class LakePiece extends BasePiece {
}
private int getHeight(StructureWorldAccess world, BlockPos pos) {
int p = ((pos.getX() & 2047) << 11) | (pos.getZ() & 2047);
int h = heightmap.getOrDefault(p, Integer.MIN_VALUE);
if (h > Integer.MIN_VALUE) {
return h;
}
if (BiomeRegistry.getFromBiome(world.getBiome(pos)) != BiomeRegistry.MEGALAKE) {
heightmap.put(p, -4);
return -4;
}
int h = world.getTopY(Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
h = world.getTopY(Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
if (h < 57) {
heightmap.put(p, 0);
return 0;
}
return h - 57;
h -= 57;
if (h < 0) {
heightmap.put(p, 0);
return 0;
}
heightmap.put(p, h);
return h;
}
private float getHeightClamp(StructureWorldAccess world, int radius, int posX, int posZ) {

View file

@ -1,7 +1,10 @@
package ru.betterend.world.structures.piece;
import java.util.Map;
import java.util.Random;
import com.google.common.collect.Maps;
import net.minecraft.block.Blocks;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtHelper;
@ -20,10 +23,12 @@ import net.minecraft.world.gen.chunk.ChunkGenerator;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.BiomeRegistry;
import ru.betterend.registry.BlockRegistry;
import ru.betterend.registry.BlockTagRegistry;
import ru.betterend.registry.StructureRegistry;
import ru.betterend.util.MHelper;
public class MountainPiece extends BasePiece {
private Map<Integer, Integer> heightmap = Maps.newHashMap();
private OpenSimplexNoise noise;
private BlockPos center;
private float radius;
@ -140,14 +145,39 @@ public class MountainPiece extends BasePiece {
}
private int getHeight(StructureWorldAccess world, BlockPos pos) {
int p = ((pos.getX() & 2047) << 11) | (pos.getZ() & 2047);
int h = heightmap.getOrDefault(p, Integer.MIN_VALUE);
if (h > Integer.MIN_VALUE) {
return h;
}
if (BiomeRegistry.getFromBiome(world.getBiome(pos)) != BiomeRegistry.END_HIGHLANDS) {
heightmap.put(p, -4);
return -4;
}
int h = world.getTopY(Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
h = world.getTopY(Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
if (h < 57) {
heightmap.put(p, 0);
return 0;
}
return h - 57;
Mutable m = new Mutable();
m.set(pos.getX(), h - 1, pos.getZ());
while (h > 56 && world.getBlockState(pos).isIn(BlockTagRegistry.GEN_TERRAIN)) {
m.setY(m.getY() - 1);
}
h = m.getY();
h -= 57;
if (h < 0) {
heightmap.put(p, 0);
return 0;
}
heightmap.put(p, h);
return h;
}
private float getHeightClamp(StructureWorldAccess world, int radius, int posX, int posZ) {

View file

@ -181,5 +181,8 @@
"block.betterend.end_lotus_stairs": "End Lotus Stairs",
"block.betterend.end_lotus_stripped_bark": "End Lotus Stripped Bark",
"block.betterend.end_lotus_stripped_log": "End Lotus Stripped Log",
"block.betterend.end_lotus_trapdoor": "End Lotus Trapdoor"
"block.betterend.end_lotus_trapdoor": "End Lotus Trapdoor",
"block.betterend.flavolite_runed": "Runed Flavolite",
"block.betterend.flavolite_runed_eternal": "Eternal Runed Flavolite"
}