Tweak the cloud carver to set the top layer to soggy clouds

This commit is contained in:
Sollace 2024-09-25 19:41:50 +01:00
parent 991a2407bb
commit 8779c5f1a6
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
9 changed files with 82 additions and 25 deletions

View file

@ -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();
}

View file

@ -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;

View file

@ -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();
}

View file

@ -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();
}

View file

@ -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;
});
}
}

View file

@ -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);

View file

@ -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<Soakable> soggyBlock,
Supplier<Block> 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);

View file

@ -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);

View file

@ -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<CaveCarverConfig> 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<BlockPos, RegistryEntry<Biome>> 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);
}
}
}