mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-07 22:16:44 +01:00
Tweak the cloud carver to set the top layer to soggy clouds
This commit is contained in:
parent
a987e9612a
commit
c32bf4c099
9 changed files with 82 additions and 25 deletions
|
@ -24,7 +24,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();
|
||||
}
|
||||
|
|
|
@ -30,10 +30,21 @@ public class CloudBlock extends Block implements CloudLike {
|
|||
protected final boolean meltable;
|
||||
|
||||
public CloudBlock(Settings settings, boolean meltable) {
|
||||
super((meltable ? settings.ticksRandomly() : settings).nonOpaque().dynamicBounds());
|
||||
super(CloudLike.applyCloudProperties(meltable ? settings.ticksRandomly() : settings));
|
||||
this.meltable = meltable;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
|
|
@ -77,7 +77,7 @@ public class CloudChestBlock extends ChestBlock implements CloudLike {
|
|||
};
|
||||
|
||||
public CloudChestBlock(Settings settings, BlockState baseState) {
|
||||
super(settings.dynamicBounds(), () -> UBlockEntities.CLOUD_CHEST);
|
||||
super(CloudLike.applyCloudProperties(settings), () -> UBlockEntities.CLOUD_CHEST);
|
||||
this.baseState = baseState;
|
||||
this.baseBlock = (CloudBlock)baseState.getBlock();
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class CloudDoorBlock extends DoorBlock implements CloudLike {
|
|||
private final CloudBlock baseBlock;
|
||||
|
||||
public CloudDoorBlock(Settings settings, BlockState baseState, BlockSetType blockSet) {
|
||||
super(settings.dynamicBounds(), blockSet);
|
||||
super(CloudLike.applyCloudProperties(settings), blockSet);
|
||||
this.baseState = baseState;
|
||||
this.baseBlock = (CloudBlock)baseState.getBlock();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,10 +21,21 @@ 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();
|
||||
}
|
||||
|
||||
@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);
|
||||
|
|
|
@ -6,8 +6,6 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
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.tag.ItemTags;
|
||||
|
@ -18,7 +16,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 {
|
||||
|
@ -28,23 +25,10 @@ public class NaturalCloudBlock extends PoreousCloudBlock {
|
|||
public NaturalCloudBlock(Settings settings, boolean meltable,
|
||||
@Nullable Supplier<Soakable> soggyBlock,
|
||||
Supplier<Block> compactedBlock) {
|
||||
super(settings.nonOpaque().allowsSpawning((state, world, pos, type) -> {
|
||||
return type == EntityType.PHANTOM || type == EntityType.PARROT || type.getSpawnGroup() == SpawnGroup.AMBIENT;
|
||||
}), meltable, soggyBlock);
|
||||
super(settings, meltable, soggyBlock);
|
||||
this.compactedBlock = compactedBlock;
|
||||
}
|
||||
|
||||
@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);
|
||||
|
|
|
@ -78,7 +78,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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue