From 11a0d5206177ceb0b81a086f48a41b59829fb1ed Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Thu, 22 Oct 2020 22:55:24 +0300 Subject: [PATCH] End lily water fix, some cleanup --- .../ru/betterend/blocks/BlockEndLily.java | 13 ++++++ .../mixin/common/LocateCommandMixin.java | 6 +-- .../java/ru/betterend/util/BlocksHelper.java | 14 +++++- .../world/features/EndLakeFeature.java | 8 ++-- .../world/features/RoundCaveFeature.java | 44 +++++++++++-------- .../world/structures/piece/LakePiece.java | 25 ++++++++++- .../world/structures/piece/MountainPiece.java | 34 +++++++++++++- .../assets/betterend/lang/en_us.json | 5 ++- 8 files changed, 118 insertions(+), 31 deletions(-) diff --git a/src/main/java/ru/betterend/blocks/BlockEndLily.java b/src/main/java/ru/betterend/blocks/BlockEndLily.java index bace52e4..8b9b99b2 100644 --- a/src/main/java/ru/betterend/blocks/BlockEndLily.java +++ b/src/main/java/ru/betterend/blocks/BlockEndLily.java @@ -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); diff --git a/src/main/java/ru/betterend/mixin/common/LocateCommandMixin.java b/src/main/java/ru/betterend/mixin/common/LocateCommandMixin.java index 331df4e3..85ce9490 100644 --- a/src/main/java/ru/betterend/mixin/common/LocateCommandMixin.java +++ b/src/main/java/ru/betterend/mixin/common/LocateCommandMixin.java @@ -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(); } diff --git a/src/main/java/ru/betterend/util/BlocksHelper.java b/src/main/java/ru/betterend/util/BlocksHelper.java index bea63167..3f021fac 100644 --- a/src/main/java/ru/betterend/util/BlocksHelper.java +++ b/src/main/java/ru/betterend/util/BlocksHelper.java @@ -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) { diff --git a/src/main/java/ru/betterend/world/features/EndLakeFeature.java b/src/main/java/ru/betterend/world/features/EndLakeFeature.java index 335522a1..2fca8be0 100644 --- a/src/main/java/ru/betterend/world/features/EndLakeFeature.java +++ b/src/main/java/ru/betterend/world/features/EndLakeFeature.java @@ -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(); } } diff --git a/src/main/java/ru/betterend/world/features/RoundCaveFeature.java b/src/main/java/ru/betterend/world/features/RoundCaveFeature.java index d1481221..de750494 100644 --- a/src/main/java/ru/betterend/world/features/RoundCaveFeature.java +++ b/src/main/java/ru/betterend/world/features/RoundCaveFeature.java @@ -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,17 +108,23 @@ public class RoundCaveFeature extends DefaultFeature { BlocksHelper.setWithoutUpdate(world, bpos, terrain); } } - else if (world.getBlockState(bpos).isIn(BlockTagRegistry.GEN_TERRAIN)) { - if (world.isAir(bpos.down())) { - int h = BlocksHelper.downRay(world, bpos.down(), 64); - if (h > 6 && h < 32 && world.getBlockState(bpos.down(h + 3)).isIn(BlockTagRegistry.GEN_TERRAIN)) { - bushes.add(bpos.down()); - } + 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.isAir(bpos.up())) { - int h = BlocksHelper.upRay(world, bpos.up(), 64); - if (h > 6 && h < 32 && world.getBlockState(bpos.up(h + 3)).isIn(BlockTagRegistry.GEN_TERRAIN)) { - bushes.add(bpos.up()); + else if (world.getBlockState(bpos).isIn(BlockTagRegistry.GEN_TERRAIN)) { + if (world.isAir(bpos.down())) { + int h = BlocksHelper.downRay(world, bpos.down(), 64); + if (h > 6 && h < 32 && world.getBlockState(bpos.down(h + 3)).isIn(BlockTagRegistry.GEN_TERRAIN)) { + bushes.add(bpos.down()); + } + } + else if (world.isAir(bpos.up())) { + int h = BlocksHelper.upRay(world, bpos.up(), 64); + if (h > 6 && h < 32 && world.getBlockState(bpos.up(h + 3)).isIn(BlockTagRegistry.GEN_TERRAIN)) { + bushes.add(bpos.up()); + } } } } diff --git a/src/main/java/ru/betterend/world/structures/piece/LakePiece.java b/src/main/java/ru/betterend/world/structures/piece/LakePiece.java index 422de1b1..ccefd126 100644 --- a/src/main/java/ru/betterend/world/structures/piece/LakePiece.java +++ b/src/main/java/ru/betterend/world/structures/piece/LakePiece.java @@ -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 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) { diff --git a/src/main/java/ru/betterend/world/structures/piece/MountainPiece.java b/src/main/java/ru/betterend/world/structures/piece/MountainPiece.java index 5f314de0..913fae5a 100644 --- a/src/main/java/ru/betterend/world/structures/piece/MountainPiece.java +++ b/src/main/java/ru/betterend/world/structures/piece/MountainPiece.java @@ -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 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) { diff --git a/src/main/resources/assets/betterend/lang/en_us.json b/src/main/resources/assets/betterend/lang/en_us.json index f2da930d..bc02c3ef 100644 --- a/src/main/resources/assets/betterend/lang/en_us.json +++ b/src/main/resources/assets/betterend/lang/en_us.json @@ -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" } \ No newline at end of file