From 8779c5f1a61849466c576d0e9d3a11aaaffaf73c Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 25 Sep 2024 19:41:50 +0100 Subject: [PATCH] Tweak the cloud carver to set the top layer to soggy clouds --- .../unicopia/block/cloud/CloudBedBlock.java | 2 +- .../unicopia/block/cloud/CloudBlock.java | 13 +++++- .../unicopia/block/cloud/CloudChestBlock.java | 2 +- .../unicopia/block/cloud/CloudDoorBlock.java | 2 +- .../unicopia/block/cloud/CloudLike.java | 10 ++++- .../block/cloud/CloudStairsBlock.java | 13 +++++- .../block/cloud/NaturalCloudBlock.java | 18 +------- .../unicopia/block/cloud/Soakable.java | 2 +- .../server/world/gen/CloudCarver.java | 45 ++++++++++++++++++- 9 files changed, 82 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBedBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBedBlock.java index 15b5dace..2ce5bddd 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBedBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBedBlock.java @@ -35,7 +35,7 @@ public class CloudBedBlock extends FancyBedBlock implements CloudLike { private final CloudBlock baseBlock; public CloudBedBlock(String base, BlockState baseState, Settings settings) { - super(base, settings.dynamicBounds()); + super(base, CloudLike.applyCloudProperties(settings)); this.baseState = baseState; this.baseBlock = (CloudBlock)baseState.getBlock(); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBlock.java index 6216e09f..1cab503e 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBlock.java @@ -39,7 +39,7 @@ public class CloudBlock extends Block implements CloudLike { protected final boolean meltable; public CloudBlock(boolean meltable, Settings settings) { - super((meltable ? settings.ticksRandomly() : settings).nonOpaque().dynamicBounds()); + super(CloudLike.applyCloudProperties(meltable ? settings.ticksRandomly() : settings)); this.meltable = meltable; } @@ -48,6 +48,17 @@ public class CloudBlock extends Block implements CloudLike { return CODEC; } + @Override + @Deprecated + public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) { + return 0.9F; + } + + @Override + public boolean isTransparent(BlockState state, BlockView world, BlockPos pos) { + return true; + } + @Override public void onEntityLand(BlockView world, Entity entity) { boolean bounce = Math.abs(entity.getVelocity().y) > 0.3; diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudChestBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudChestBlock.java index b43226d8..f0ee4149 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudChestBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudChestBlock.java @@ -85,7 +85,7 @@ public class CloudChestBlock extends ChestBlock implements CloudLike { }; public CloudChestBlock(BlockState baseState, Settings settings) { - super(settings.dynamicBounds(), () -> UBlockEntities.CLOUD_CHEST); + super(CloudLike.applyCloudProperties(settings), () -> UBlockEntities.CLOUD_CHEST); this.baseState = baseState; this.baseBlock = (CloudBlock)baseState.getBlock(); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudDoorBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudDoorBlock.java index 499c8e74..eb30c220 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudDoorBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudDoorBlock.java @@ -33,7 +33,7 @@ public class CloudDoorBlock extends DoorBlock implements CloudLike { private final CloudBlock baseBlock; public CloudDoorBlock(BlockState baseState, BlockSetType blockSet, Settings settings) { - super(blockSet, settings.dynamicBounds()); + super(blockSet, CloudLike.applyCloudProperties(settings)); this.baseState = baseState; this.baseBlock = (CloudBlock)baseState.getBlock(); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudLike.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudLike.java index ec9ef4fd..3684c890 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudLike.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudLike.java @@ -1,5 +1,13 @@ package com.minelittlepony.unicopia.block.cloud; -public interface CloudLike { +import net.minecraft.block.Block; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnGroup; +public interface CloudLike { + static Block.Settings applyCloudProperties(Block.Settings settings) { + return settings.nonOpaque().dynamicBounds().allowsSpawning((state, world, pos, type) -> { + return type == EntityType.PHANTOM || type == EntityType.PARROT || type.getSpawnGroup() == SpawnGroup.AMBIENT; + }); + } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudStairsBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudStairsBlock.java index dcf3d7b4..743640b0 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudStairsBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudStairsBlock.java @@ -28,7 +28,7 @@ public class CloudStairsBlock extends StairsBlock implements CloudLike { private final CloudBlock baseBlock; public CloudStairsBlock(BlockState baseState, Settings settings) { - super(baseState, settings.dynamicBounds()); + super(baseState, CloudLike.applyCloudProperties(settings)); this.baseBlock = (CloudBlock)baseState.getBlock(); } @@ -37,6 +37,17 @@ public class CloudStairsBlock extends StairsBlock implements CloudLike { return CODEC; } + @Override + @Deprecated + public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) { + return baseBlock.getAmbientOcclusionLightLevel(state, world, pos); + } + + @Override + public boolean isTransparent(BlockState state, BlockView world, BlockPos pos) { + return baseBlock.isTransparent(state, world, pos); + } + @Override public void onEntityLand(BlockView world, Entity entity) { baseBlock.onEntityLand(world, entity); diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/NaturalCloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/NaturalCloudBlock.java index 6d8b8438..de0ec27e 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/NaturalCloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/NaturalCloudBlock.java @@ -12,8 +12,6 @@ import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.block.BedBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries; @@ -25,7 +23,6 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; import net.minecraft.world.World; public class NaturalCloudBlock extends PoreousCloudBlock { @@ -42,9 +39,7 @@ public class NaturalCloudBlock extends PoreousCloudBlock { @Nullable Supplier soggyBlock, Supplier compactedBlock, Settings settings) { - super(meltable, soggyBlock, settings.nonOpaque().allowsSpawning((state, world, pos, type) -> { - return type == EntityType.PHANTOM || type == EntityType.PARROT || type.getSpawnGroup() == SpawnGroup.AMBIENT; - })); + super(meltable, soggyBlock, settings.nonOpaque()); this.compactedBlock = compactedBlock; } @@ -53,17 +48,6 @@ public class NaturalCloudBlock extends PoreousCloudBlock { return CODEC; } - @Override - @Deprecated - public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) { - return 0.9F; - } - - @Override - public boolean isTransparent(BlockState state, BlockView world, BlockPos pos) { - return true; - } - @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { ItemStack stack = player.getStackInHand(hand); diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/Soakable.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/Soakable.java index 866d5a29..a385788f 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/Soakable.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/Soakable.java @@ -82,7 +82,7 @@ public interface Soakable { if (moisture < 7) { world.setBlockState(pos, soakable.getStateWithMoisture(state, moisture + 1)); } - } else { + } else if (!world.isAir(pos.up())) { if (moisture > 1) { BlockPos neighborPos = pos.offset(Util.getRandom(Soakable.DIRECTIONS, random)); BlockState neighborState = world.getBlockState(neighborPos); diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/gen/CloudCarver.java b/src/main/java/com/minelittlepony/unicopia/server/world/gen/CloudCarver.java index 21356298..41736d0d 100644 --- a/src/main/java/com/minelittlepony/unicopia/server/world/gen/CloudCarver.java +++ b/src/main/java/com/minelittlepony/unicopia/server/world/gen/CloudCarver.java @@ -2,12 +2,18 @@ package com.minelittlepony.unicopia.server.world.gen; import java.util.function.Function; +import org.apache.commons.lang3.mutable.MutableBoolean; + import com.minelittlepony.unicopia.block.UBlocks; import com.mojang.serialization.Codec; + +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import it.unimi.dsi.fastutil.longs.LongSet; import net.minecraft.block.BlockState; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.Direction; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.random.Random; import net.minecraft.world.biome.Biome; @@ -24,6 +30,8 @@ public class CloudCarver extends CaveCarver { private Random random; + private final LongSet topWrittenPositions = new LongOpenHashSet(); + public CloudCarver(Codec codec) { super(codec); } @@ -55,7 +63,7 @@ public class CloudCarver extends CaveCarver { CarvingMask carvingMask ) { this.random = random; - return super.carve(context, config, chunk, function, random, new AquiferSampler() { + boolean result = super.carve(context, config, chunk, function, random, new AquiferSampler() { @Override public BlockState apply(NoisePos pos, double density) { BlockState state = sampler.apply(pos, density); @@ -68,6 +76,12 @@ public class CloudCarver extends CaveCarver { } }, chunkPos, carvingMask); + BlockPos.Mutable mutable = new BlockPos.Mutable(); + topWrittenPositions.forEach(l -> { + processSurfaceBlocks(mutable.set(l), context, config, chunk, random); + }); + topWrittenPositions.clear(); + return result; } @Override @@ -139,4 +153,33 @@ public class CloudCarver extends CaveCarver { } //super.carveTunnels(context, config, chunk, posToBiome, seed, aquiferSampler, x, y, z, horizontalScale, verticalScale, w, yaw, pitch, branchStartIndex, branchCount, yawPitchRatio, mask, skipPredicate); } + + @Override + protected boolean carveAtPoint( + CarverContext context, + CaveCarverConfig config, + Chunk chunk, + Function> posToBiome, + CarvingMask mask, + BlockPos.Mutable pos, + BlockPos.Mutable tmp, + AquiferSampler aquiferSampler, + MutableBoolean replacedGrassy + ) { + if (super.carveAtPoint(context, config, chunk, posToBiome, mask, pos, tmp, aquiferSampler, replacedGrassy)) { + topWrittenPositions.remove(tmp.set(pos).move(Direction.DOWN).asLong()); + topWrittenPositions.add(pos.asLong()); + if (chunk.getBlockState(tmp).isOf(UBlocks.SOGGY_CLOUD)) { + chunk.setBlockState(tmp, UBlocks.CLOUD.getDefaultState(), false); + } + return true; + } + return false; + } + + protected void processSurfaceBlocks(BlockPos.Mutable pos, CarverContext context, CaveCarverConfig config, Chunk chunk, Random random) { + if (chunk.getBlockState(pos.move(Direction.UP)).isAir()) { + chunk.setBlockState(pos.move(Direction.DOWN), UBlocks.SOGGY_CLOUD.getDefaultState(), false); + } + } } \ No newline at end of file