From cec37f10d6f939b0c5f3fc27f2ca31d60998b98d Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 4 Dec 2020 15:52:44 +0300 Subject: [PATCH] More fixes, vents generation prototype --- .../blocks/BlockHydrothermalVent.java | 10 +++++- .../entities/BlockEntityHydrothermalVent.java | 32 +++++++++++++++++ .../ru/betterend/particle/ParticleGeyser.java | 4 +-- .../betterend/registry/EndBlockEntities.java | 3 ++ .../world/features/terrain/GeyserFeature.java | 35 ++++++++++++++----- 5 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 src/main/java/ru/betterend/blocks/entities/BlockEntityHydrothermalVent.java diff --git a/src/main/java/ru/betterend/blocks/BlockHydrothermalVent.java b/src/main/java/ru/betterend/blocks/BlockHydrothermalVent.java index bcdba01a..8c267d17 100644 --- a/src/main/java/ru/betterend/blocks/BlockHydrothermalVent.java +++ b/src/main/java/ru/betterend/blocks/BlockHydrothermalVent.java @@ -7,12 +7,14 @@ import net.fabricmc.api.Environment; 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.BlockEntityProvider; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.FluidFillable; import net.minecraft.block.Material; import net.minecraft.block.ShapeContext; import net.minecraft.block.Waterloggable; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.FluidState; import net.minecraft.fluid.Fluids; @@ -30,10 +32,11 @@ import net.minecraft.world.World; import net.minecraft.world.WorldAccess; import net.minecraft.world.WorldView; import ru.betterend.blocks.basis.BlockBaseNotFull; +import ru.betterend.blocks.entities.BlockEntityHydrothermalVent; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndParticles; -public class BlockHydrothermalVent extends BlockBaseNotFull implements FluidFillable, Waterloggable { +public class BlockHydrothermalVent extends BlockBaseNotFull implements BlockEntityProvider, FluidFillable, Waterloggable { public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; private static final VoxelShape SHAPE = Block.createCuboidShape(1, 1, 1, 15, 16, 15); @@ -107,4 +110,9 @@ public class BlockHydrothermalVent extends BlockBaseNotFull implements FluidFill world.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0); } } + + @Override + public BlockEntity createBlockEntity(BlockView world) { + return new BlockEntityHydrothermalVent(); + } } diff --git a/src/main/java/ru/betterend/blocks/entities/BlockEntityHydrothermalVent.java b/src/main/java/ru/betterend/blocks/entities/BlockEntityHydrothermalVent.java new file mode 100644 index 00000000..c3fe022a --- /dev/null +++ b/src/main/java/ru/betterend/blocks/entities/BlockEntityHydrothermalVent.java @@ -0,0 +1,32 @@ +package ru.betterend.blocks.entities; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.particle.ParticleTypes; +import net.minecraft.util.Tickable; +import ru.betterend.blocks.BlockHydrothermalVent; +import ru.betterend.registry.EndBlockEntities; +import ru.betterend.registry.EndBlocks; +import ru.betterend.registry.EndParticles; + +public class BlockEntityHydrothermalVent extends BlockEntity implements Tickable { + public BlockEntityHydrothermalVent() { + super(EndBlockEntities.HYDROTHERMAL_VENT); + } + + @Override + public void tick() { + double x = pos.getX() + world.random.nextDouble(); + double y = pos.getY() + 0.9 + world.random.nextDouble() * 0.3; + double z = pos.getZ() + world.random.nextDouble(); + BlockState state = getCachedState(); + if (state.isOf(EndBlocks.HYDROTHERMAL_VENT)) { + if (getCachedState().get(BlockHydrothermalVent.WATERLOGGED)) { + world.addParticle(EndParticles.GEYSER_PARTICLE, x, y, z, 0, 0, 0); + } + else { + world.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0); + } + } + } +} diff --git a/src/main/java/ru/betterend/particle/ParticleGeyser.java b/src/main/java/ru/betterend/particle/ParticleGeyser.java index e63c8bcc..d7c5276e 100644 --- a/src/main/java/ru/betterend/particle/ParticleGeyser.java +++ b/src/main/java/ru/betterend/particle/ParticleGeyser.java @@ -28,8 +28,8 @@ public class ParticleGeyser extends SpriteBillboardParticle { if (this.age >= this.maxAge + 40) { this.setColorAlpha((this.maxAge - this.age) / 40F); } - this.velocityX = 0; - this.velocityZ = 0; + //this.velocityX = 0; + //this.velocityZ = 0; this.velocityY = 0.125; super.tick(); } diff --git a/src/main/java/ru/betterend/registry/EndBlockEntities.java b/src/main/java/ru/betterend/registry/EndBlockEntities.java index f83b0d0c..38e9f40c 100644 --- a/src/main/java/ru/betterend/registry/EndBlockEntities.java +++ b/src/main/java/ru/betterend/registry/EndBlockEntities.java @@ -17,6 +17,7 @@ import ru.betterend.blocks.basis.BlockBarrel; import ru.betterend.blocks.basis.BlockChest; import ru.betterend.blocks.basis.BlockPedestal; import ru.betterend.blocks.basis.BlockSign; +import ru.betterend.blocks.entities.BlockEntityHydrothermalVent; import ru.betterend.blocks.entities.EBarrelBlockEntity; import ru.betterend.blocks.entities.EChestBlockEntity; import ru.betterend.blocks.entities.ESignBlockEntity; @@ -40,6 +41,8 @@ public class EndBlockEntities { BlockEntityType.Builder.create(EBarrelBlockEntity::new, getBarrels())); public static final BlockEntityType SIGN = registerBlockEntity("sign", BlockEntityType.Builder.create(ESignBlockEntity::new, getSigns())); + public final static BlockEntityType HYDROTHERMAL_VENT = registerBlockEntity("hydrother_malvent", + BlockEntityType.Builder.create(BlockEntityHydrothermalVent::new, EndBlocks.HYDROTHERMAL_VENT)); public static BlockEntityType registerBlockEntity(String id, BlockEntityType.Builder builder) { return Registry.register(Registry.BLOCK_ENTITY_TYPE, BetterEnd.makeID(id), builder.build(null)); diff --git a/src/main/java/ru/betterend/world/features/terrain/GeyserFeature.java b/src/main/java/ru/betterend/world/features/terrain/GeyserFeature.java index af1ea389..5b4dc75e 100644 --- a/src/main/java/ru/betterend/world/features/terrain/GeyserFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/GeyserFeature.java @@ -10,6 +10,7 @@ import net.minecraft.block.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.world.StructureWorldAccess; import net.minecraft.world.gen.chunk.ChunkGenerator; @@ -128,23 +129,39 @@ public class GeyserFeature extends DefaultFeature { obj2.setBlock(EndBlocks.SULPHURIC_ROCK.stone); new SDFDisplacement().setFunction((vec) -> { return -4F; - }).setSource(sdf).setReplaceFunction(REPLACE1).fillRecursiveIgnore(world, pos, IGNORE); + }).setSource(cave).setReplaceFunction(REPLACE1).fillRecursiveIgnore(world, pos, IGNORE); obj1.setBlock(Blocks.END_STONE); obj2.setBlock(Blocks.END_STONE); new SDFDisplacement().setFunction((vec) -> { return -6F; - }).setSource(sdf).setReplaceFunction(REPLACE1).fillRecursiveIgnore(world, pos, IGNORE); + }).setSource(cave).setReplaceFunction(REPLACE1).fillRecursiveIgnore(world, pos, IGNORE); + BlocksHelper.setWithoutUpdate(world, pos, WATER); Mutable mut = new Mutable().set(pos); - for (int i = 0; i < halfHeight + 5; i++) { - BlockState state = world.getBlockState(mut); - if (state.isIn(EndTags.GEN_TERRAIN) || state.isOf(Blocks.WATER)) { - BlocksHelper.setWithoutUpdate(world, mut, WATER); - mut.setY(mut.getY() + 1); + count = getYOnSurface(world, pos.getX(), pos.getZ()) - pos.getY(); + for (int i = 0; i < count; i++) { + BlocksHelper.setWithoutUpdate(world, mut, WATER); + for (Direction dir: BlocksHelper.HORIZONTAL) { + BlocksHelper.setWithoutUpdate(world, mut.offset(dir), WATER); } - else { - break; + mut.setY(mut.getY() + 1); + } + + for (int i = 0; i < 30; i++) { + mut.set(pos).add(random.nextGaussian() * 2, -halfHeight - 10, random.nextGaussian() * 2); + int dist = MHelper.floor(6 - MHelper.length(mut.getX() - pos.getX(), mut.getZ() - pos.getZ())) + random.nextInt(2); + BlockState state = world.getBlockState(mut); + while (state.isOf(Blocks.WATER)) { + mut.setY(mut.getY() - 1); + state = world.getBlockState(mut); + } + if (state.isIn(EndTags.GEN_TERRAIN)) { + for (int j = 0; j < dist; j++) { + BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.SULPHURIC_ROCK.stone); + mut.setY(mut.getY() + 1); + } + BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.HYDROTHERMAL_VENT); } }