mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Tweak the cloud carver to set the top layer to soggy clouds
This commit is contained in:
parent
991a2407bb
commit
8779c5f1a6
9 changed files with 82 additions and 25 deletions
|
@ -35,7 +35,7 @@ public class CloudBedBlock extends FancyBedBlock implements CloudLike {
|
||||||
private final CloudBlock baseBlock;
|
private final CloudBlock baseBlock;
|
||||||
|
|
||||||
public CloudBedBlock(String base, BlockState baseState, Settings settings) {
|
public CloudBedBlock(String base, BlockState baseState, Settings settings) {
|
||||||
super(base, settings.dynamicBounds());
|
super(base, CloudLike.applyCloudProperties(settings));
|
||||||
this.baseState = baseState;
|
this.baseState = baseState;
|
||||||
this.baseBlock = (CloudBlock)baseState.getBlock();
|
this.baseBlock = (CloudBlock)baseState.getBlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class CloudBlock extends Block implements CloudLike {
|
||||||
protected final boolean meltable;
|
protected final boolean meltable;
|
||||||
|
|
||||||
public CloudBlock(boolean meltable, Settings settings) {
|
public CloudBlock(boolean meltable, Settings settings) {
|
||||||
super((meltable ? settings.ticksRandomly() : settings).nonOpaque().dynamicBounds());
|
super(CloudLike.applyCloudProperties(meltable ? settings.ticksRandomly() : settings));
|
||||||
this.meltable = meltable;
|
this.meltable = meltable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,17 @@ public class CloudBlock extends Block implements CloudLike {
|
||||||
return CODEC;
|
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
|
@Override
|
||||||
public void onEntityLand(BlockView world, Entity entity) {
|
public void onEntityLand(BlockView world, Entity entity) {
|
||||||
boolean bounce = Math.abs(entity.getVelocity().y) > 0.3;
|
boolean bounce = Math.abs(entity.getVelocity().y) > 0.3;
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class CloudChestBlock extends ChestBlock implements CloudLike {
|
||||||
};
|
};
|
||||||
|
|
||||||
public CloudChestBlock(BlockState baseState, Settings settings) {
|
public CloudChestBlock(BlockState baseState, Settings settings) {
|
||||||
super(settings.dynamicBounds(), () -> UBlockEntities.CLOUD_CHEST);
|
super(CloudLike.applyCloudProperties(settings), () -> UBlockEntities.CLOUD_CHEST);
|
||||||
this.baseState = baseState;
|
this.baseState = baseState;
|
||||||
this.baseBlock = (CloudBlock)baseState.getBlock();
|
this.baseBlock = (CloudBlock)baseState.getBlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class CloudDoorBlock extends DoorBlock implements CloudLike {
|
||||||
private final CloudBlock baseBlock;
|
private final CloudBlock baseBlock;
|
||||||
|
|
||||||
public CloudDoorBlock(BlockState baseState, BlockSetType blockSet, Settings settings) {
|
public CloudDoorBlock(BlockState baseState, BlockSetType blockSet, Settings settings) {
|
||||||
super(blockSet, settings.dynamicBounds());
|
super(blockSet, CloudLike.applyCloudProperties(settings));
|
||||||
this.baseState = baseState;
|
this.baseState = baseState;
|
||||||
this.baseBlock = (CloudBlock)baseState.getBlock();
|
this.baseBlock = (CloudBlock)baseState.getBlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
package com.minelittlepony.unicopia.block.cloud;
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class CloudStairsBlock extends StairsBlock implements CloudLike {
|
||||||
private final CloudBlock baseBlock;
|
private final CloudBlock baseBlock;
|
||||||
|
|
||||||
public CloudStairsBlock(BlockState baseState, Settings settings) {
|
public CloudStairsBlock(BlockState baseState, Settings settings) {
|
||||||
super(baseState, settings.dynamicBounds());
|
super(baseState, CloudLike.applyCloudProperties(settings));
|
||||||
this.baseBlock = (CloudBlock)baseState.getBlock();
|
this.baseBlock = (CloudBlock)baseState.getBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,17 @@ public class CloudStairsBlock extends StairsBlock implements CloudLike {
|
||||||
return CODEC;
|
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
|
@Override
|
||||||
public void onEntityLand(BlockView world, Entity entity) {
|
public void onEntityLand(BlockView world, Entity entity) {
|
||||||
baseBlock.onEntityLand(world, entity);
|
baseBlock.onEntityLand(world, entity);
|
||||||
|
|
|
@ -12,8 +12,6 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
import net.minecraft.block.BedBlock;
|
import net.minecraft.block.BedBlock;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.SpawnGroup;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
|
@ -25,7 +23,6 @@ import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.BlockView;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class NaturalCloudBlock extends PoreousCloudBlock {
|
public class NaturalCloudBlock extends PoreousCloudBlock {
|
||||||
|
@ -42,9 +39,7 @@ public class NaturalCloudBlock extends PoreousCloudBlock {
|
||||||
@Nullable Supplier<Soakable> soggyBlock,
|
@Nullable Supplier<Soakable> soggyBlock,
|
||||||
Supplier<Block> compactedBlock,
|
Supplier<Block> compactedBlock,
|
||||||
Settings settings) {
|
Settings settings) {
|
||||||
super(meltable, soggyBlock, settings.nonOpaque().allowsSpawning((state, world, pos, type) -> {
|
super(meltable, soggyBlock, settings.nonOpaque());
|
||||||
return type == EntityType.PHANTOM || type == EntityType.PARROT || type.getSpawnGroup() == SpawnGroup.AMBIENT;
|
|
||||||
}));
|
|
||||||
this.compactedBlock = compactedBlock;
|
this.compactedBlock = compactedBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,17 +48,6 @@ public class NaturalCloudBlock extends PoreousCloudBlock {
|
||||||
return CODEC;
|
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
|
@Override
|
||||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||||
ItemStack stack = player.getStackInHand(hand);
|
ItemStack stack = player.getStackInHand(hand);
|
||||||
|
|
|
@ -82,7 +82,7 @@ public interface Soakable {
|
||||||
if (moisture < 7) {
|
if (moisture < 7) {
|
||||||
world.setBlockState(pos, soakable.getStateWithMoisture(state, moisture + 1));
|
world.setBlockState(pos, soakable.getStateWithMoisture(state, moisture + 1));
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!world.isAir(pos.up())) {
|
||||||
if (moisture > 1) {
|
if (moisture > 1) {
|
||||||
BlockPos neighborPos = pos.offset(Util.getRandom(Soakable.DIRECTIONS, random));
|
BlockPos neighborPos = pos.offset(Util.getRandom(Soakable.DIRECTIONS, random));
|
||||||
BlockState neighborState = world.getBlockState(neighborPos);
|
BlockState neighborState = world.getBlockState(neighborPos);
|
||||||
|
|
|
@ -2,12 +2,18 @@ package com.minelittlepony.unicopia.server.world.gen;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.block.UBlocks;
|
import com.minelittlepony.unicopia.block.UBlocks;
|
||||||
import com.mojang.serialization.Codec;
|
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.block.BlockState;
|
||||||
import net.minecraft.registry.entry.RegistryEntry;
|
import net.minecraft.registry.entry.RegistryEntry;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.ChunkPos;
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.random.Random;
|
import net.minecraft.util.math.random.Random;
|
||||||
import net.minecraft.world.biome.Biome;
|
import net.minecraft.world.biome.Biome;
|
||||||
|
@ -24,6 +30,8 @@ public class CloudCarver extends CaveCarver {
|
||||||
|
|
||||||
private Random random;
|
private Random random;
|
||||||
|
|
||||||
|
private final LongSet topWrittenPositions = new LongOpenHashSet();
|
||||||
|
|
||||||
public CloudCarver(Codec<CaveCarverConfig> codec) {
|
public CloudCarver(Codec<CaveCarverConfig> codec) {
|
||||||
super(codec);
|
super(codec);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +63,7 @@ public class CloudCarver extends CaveCarver {
|
||||||
CarvingMask carvingMask
|
CarvingMask carvingMask
|
||||||
) {
|
) {
|
||||||
this.random = random;
|
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
|
@Override
|
||||||
public BlockState apply(NoisePos pos, double density) {
|
public BlockState apply(NoisePos pos, double density) {
|
||||||
BlockState state = sampler.apply(pos, density);
|
BlockState state = sampler.apply(pos, density);
|
||||||
|
@ -68,6 +76,12 @@ public class CloudCarver extends CaveCarver {
|
||||||
}
|
}
|
||||||
|
|
||||||
}, chunkPos, carvingMask);
|
}, chunkPos, carvingMask);
|
||||||
|
BlockPos.Mutable mutable = new BlockPos.Mutable();
|
||||||
|
topWrittenPositions.forEach(l -> {
|
||||||
|
processSurfaceBlocks(mutable.set(l), context, config, chunk, random);
|
||||||
|
});
|
||||||
|
topWrittenPositions.clear();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
//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