Added cloud slabs

This commit is contained in:
Sollace 2023-10-18 19:41:58 +01:00
parent b9318547db
commit fa8b1e485c
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
17 changed files with 242 additions and 12 deletions

View file

@ -7,6 +7,7 @@ import java.util.List;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.block.cloud.CloudBlock; import com.minelittlepony.unicopia.block.cloud.CloudBlock;
import com.minelittlepony.unicopia.block.cloud.CloudPillarBlock; import com.minelittlepony.unicopia.block.cloud.CloudPillarBlock;
import com.minelittlepony.unicopia.block.cloud.CloudSlabBlock;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.item.group.ItemGroupRegistry; import com.minelittlepony.unicopia.item.group.ItemGroupRegistry;
import com.minelittlepony.unicopia.server.world.UTreeGen; import com.minelittlepony.unicopia.server.world.UTreeGen;
@ -127,8 +128,10 @@ public interface UBlocks {
Block MYSTERIOUS_EGG = register("mysterious_egg", new PileBlock(Settings.copy(Blocks.SLIME_BLOCK), PileBlock.MYSTERIOUS_EGG_SHAPES), ItemGroups.NATURAL); Block MYSTERIOUS_EGG = register("mysterious_egg", new PileBlock(Settings.copy(Blocks.SLIME_BLOCK), PileBlock.MYSTERIOUS_EGG_SHAPES), ItemGroups.NATURAL);
Block SLIME_PUSTULE = register("slime_pustule", new SlimePustuleBlock(Settings.copy(Blocks.SLIME_BLOCK)), ItemGroups.NATURAL); Block SLIME_PUSTULE = register("slime_pustule", new SlimePustuleBlock(Settings.copy(Blocks.SLIME_BLOCK)), ItemGroups.NATURAL);
Block CLOUD = register("cloud", new CloudBlock(Settings.create().mapColor(MapColor.OFF_WHITE).replaceable().hardness(0.3F).resistance(0).sounds(BlockSoundGroup.WOOL))); Block CLOUD = register("cloud", new CloudBlock(Settings.create().mapColor(MapColor.OFF_WHITE).replaceable().hardness(0.3F).resistance(0).sounds(BlockSoundGroup.WOOL), true));
Block DENSE_CLOUD = register("dense_cloud", new CloudBlock(Settings.create().mapColor(MapColor.GRAY).replaceable().hardness(0.5F).resistance(0).sounds(BlockSoundGroup.WOOL))); Block CLOUD_SLAB = register("cloud_slab", new CloudSlabBlock(Settings.copy(CLOUD), true));
Block DENSE_CLOUD = register("dense_cloud", new CloudBlock(Settings.create().mapColor(MapColor.GRAY).replaceable().hardness(0.5F).resistance(0).sounds(BlockSoundGroup.WOOL), false));
Block DENSE_CLOUD_SLAB = register("dense_cloud_slab", new CloudSlabBlock(Settings.copy(DENSE_CLOUD), false));
Block CLOUD_PILLAR = register("cloud_pillar", new CloudPillarBlock(Settings.create().mapColor(MapColor.GRAY).replaceable().hardness(0.5F).resistance(0).sounds(BlockSoundGroup.WOOL))); Block CLOUD_PILLAR = register("cloud_pillar", new CloudPillarBlock(Settings.create().mapColor(MapColor.GRAY).replaceable().hardness(0.5F).resistance(0).sounds(BlockSoundGroup.WOOL)));
SegmentedCropBlock OATS = register("oats", SegmentedCropBlock.create(11, 5, AbstractBlock.Settings.copy(Blocks.WHEAT), () -> UItems.OAT_SEEDS, null, null)); SegmentedCropBlock OATS = register("oats", SegmentedCropBlock.create(11, 5, AbstractBlock.Settings.copy(Blocks.WHEAT), () -> UItems.OAT_SEEDS, null, null));

View file

@ -16,17 +16,24 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.pathing.NavigationType; import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemPlacementContext;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes; import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.EmptyBlockView; import net.minecraft.world.EmptyBlockView;
import net.minecraft.world.LightType;
import net.minecraft.world.World; import net.minecraft.world.World;
public class CloudBlock extends TransparentBlock { public class CloudBlock extends TransparentBlock {
public CloudBlock(Settings settings) {
super(settings.nonOpaque()); private final boolean meltable;
public CloudBlock(Settings settings, boolean meltable) {
super((meltable ? settings.ticksRandomly() : settings).nonOpaque());
this.meltable = meltable;
} }
@Override @Override
@ -101,7 +108,7 @@ public class CloudBlock extends TransparentBlock {
@Deprecated @Deprecated
@Override @Override
public boolean canReplace(BlockState state, ItemPlacementContext context) { public final boolean canReplace(BlockState state, ItemPlacementContext context) {
EquineContext equineContext = EquineContext.of(context); EquineContext equineContext = EquineContext.of(context);
if (canInteract(state, context.getWorld(), context.getBlockPos(), equineContext)) { if (canInteract(state, context.getWorld(), context.getBlockPos(), equineContext)) {
return canReplace(state, context, equineContext); return canReplace(state, context, equineContext);
@ -112,9 +119,6 @@ public class CloudBlock extends TransparentBlock {
@Deprecated @Deprecated
@Override @Override
public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) { public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) {
if (stateFrom.isOf(this)) {
return true;
}
VoxelShape shape = state.getCullingShape(EmptyBlockView.INSTANCE, BlockPos.ORIGIN); VoxelShape shape = state.getCullingShape(EmptyBlockView.INSTANCE, BlockPos.ORIGIN);
VoxelShape shapeFrom = stateFrom.getCullingShape(EmptyBlockView.INSTANCE, BlockPos.ORIGIN); VoxelShape shapeFrom = stateFrom.getCullingShape(EmptyBlockView.INSTANCE, BlockPos.ORIGIN);
return !shape.isEmpty() && !shapeFrom.isEmpty() && VoxelShapes.isSideCovered(shape, shapeFrom, direction); return !shape.isEmpty() && !shapeFrom.isEmpty() && VoxelShapes.isSideCovered(shape, shapeFrom, direction);
@ -143,4 +147,12 @@ public class CloudBlock extends TransparentBlock {
protected BlockState getPlacementState(ItemPlacementContext placementContext, EquineContext equineContext) { protected BlockState getPlacementState(ItemPlacementContext placementContext, EquineContext equineContext) {
return super.getPlacementState(placementContext); return super.getPlacementState(placementContext);
} }
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (meltable && world.getLightLevel(LightType.BLOCK, pos) > 11) {
dropStacks(state, world, pos);
world.removeBlock(pos, false);
}
}
} }

View file

@ -41,7 +41,7 @@ public class CloudPillarBlock extends CloudBlock {
// [1,0] [1,1] // [1,0] [1,1]
public CloudPillarBlock(Settings settings) { public CloudPillarBlock(Settings settings) {
super(settings); super(settings, false);
setDefaultState(getDefaultState().with(NORTH, true).with(SOUTH, true)); setDefaultState(getDefaultState().with(NORTH, true).with(SOUTH, true));
} }

View file

@ -0,0 +1,95 @@
package com.minelittlepony.unicopia.block.cloud;
import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.EquineContext;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.SlabBlock;
import net.minecraft.block.enums.SlabType;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldAccess;
public class CloudSlabBlock extends WaterloggableCloudBlock {
private static final VoxelShape BOTTOM_SHAPE = Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 8.0, 16.0);
private static final VoxelShape TOP_SHAPE = Block.createCuboidShape(0.0, 8.0, 0.0, 16.0, 16.0, 16.0);
public CloudSlabBlock(Settings settings, boolean meltable) {
super(settings, meltable);
}
@Override
public boolean hasSidedTransparency(BlockState state) {
return state.get(SlabBlock.TYPE) != SlabType.DOUBLE;
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(SlabBlock.TYPE);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, EquineContext equineContext) {
return switch (state.get(SlabBlock.TYPE)) {
case DOUBLE -> VoxelShapes.fullCube();
case TOP -> TOP_SHAPE;
case BOTTOM -> BOTTOM_SHAPE;
};
}
@Override
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx, EquineContext equineContext) {
BlockPos blockPos = ctx.getBlockPos();
BlockState blockState = ctx.getWorld().getBlockState(blockPos);
if (blockState.isOf(this)) {
return blockState.with(SlabBlock.TYPE, SlabType.DOUBLE).with(WATERLOGGED, false);
}
BlockState state = super.getPlacementState(ctx, equineContext).with(SlabBlock.TYPE, SlabType.BOTTOM);
Direction direction = ctx.getSide();
if (direction == Direction.DOWN || direction != Direction.UP && ctx.getHitPos().y - blockPos.getY() > 0.5) {
return state.with(SlabBlock.TYPE, SlabType.TOP);
}
return state;
}
@Override
public boolean canReplace(BlockState state, ItemPlacementContext context, EquineContext equineContext) {
SlabType slabType = state.get(SlabBlock.TYPE);
if (slabType == SlabType.DOUBLE || !context.getStack().isOf(asItem())) {
return false;
}
if (!context.canReplaceExisting()) {
return true;
}
boolean hitTop = context.getHitPos().y - context.getBlockPos().getY() > 0.5;
Direction side = context.getSide();
if (slabType == SlabType.BOTTOM) {
return side == Direction.UP || hitTop && side.getAxis().isHorizontal();
}
return side == Direction.DOWN || !hitTop && side.getAxis().isHorizontal();
}
@Override
public boolean tryFillWithFluid(WorldAccess world, BlockPos pos, BlockState state, FluidState fluidState) {
return state.get(SlabBlock.TYPE) != SlabType.DOUBLE && super.tryFillWithFluid(world, pos, state, fluidState);
}
@Override
public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) {
return state.get(SlabBlock.TYPE) != SlabType.DOUBLE && super.canFillWithFluid(world, pos, state, fluid);
}
}

View file

@ -12,8 +12,8 @@ public class StormyCloudBlock extends CloudBlock {
private static final int MAX_CHARGE = 6; private static final int MAX_CHARGE = 6;
private static final IntProperty CHARGE = IntProperty.of("charge", 0, MAX_CHARGE); private static final IntProperty CHARGE = IntProperty.of("charge", 0, MAX_CHARGE);
public StormyCloudBlock(Settings settings) { public StormyCloudBlock(Settings settings, boolean meltable) {
super(settings); super(settings, meltable);
setDefaultState(getDefaultState().with(CHARGE, 0)); setDefaultState(getDefaultState().with(CHARGE, 0));
} }

View file

@ -0,0 +1,63 @@
package com.minelittlepony.unicopia.block.cloud;
import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.EquineContext;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Waterloggable;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.registry.tag.FluidTags;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldAccess;
public class WaterloggableCloudBlock extends CloudBlock implements Waterloggable {
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public WaterloggableCloudBlock(Settings settings, boolean meltable) {
super(settings, meltable);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(WATERLOGGED);
}
@Override
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx, EquineContext equineContext) {
return getDefaultState().with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);
}
@Deprecated
@Override
public FluidState getFluidState(BlockState state) {
if (state.get(WATERLOGGED).booleanValue()) {
return Fluids.WATER.getStill(false);
}
return super.getFluidState(state);
}
@Deprecated
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (state.get(WATERLOGGED).booleanValue()) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}
@Override
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
return (type == NavigationType.WATER) == world.getFluidState(pos).isIn(FluidTags.WATER);
}
}

View file

@ -174,7 +174,8 @@ public interface URenderers {
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), UBlocks.TRANSLUCENT_BLOCKS.stream().toArray(Block[]::new)); BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), UBlocks.TRANSLUCENT_BLOCKS.stream().toArray(Block[]::new));
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getTranslucent(), BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getTranslucent(),
UBlocks.MYSTERIOUS_EGG, UBlocks.SLIME_PUSTULE, UBlocks.MYSTERIOUS_EGG, UBlocks.SLIME_PUSTULE,
UBlocks.CLOUD, UBlocks.DENSE_CLOUD, UBlocks.CLOUD_PILLAR UBlocks.CLOUD, UBlocks.DENSE_CLOUD, UBlocks.CLOUD_PILLAR,
UBlocks.CLOUD_SLAB, UBlocks.DENSE_CLOUD_SLAB
); );
// for lava boats // for lava boats
BlockRenderLayerMap.INSTANCE.putFluids(RenderLayer.getTranslucent(), Fluids.LAVA, Fluids.FLOWING_LAVA); BlockRenderLayerMap.INSTANCE.putFluids(RenderLayer.getTranslucent(), Fluids.LAVA, Fluids.FLOWING_LAVA);

View file

@ -145,7 +145,9 @@ public interface UItems {
Item GIANT_BALLOON = register("giant_balloon", new HotAirBalloonItem(new Item.Settings().maxCount(1)), ItemGroups.TOOLS); Item GIANT_BALLOON = register("giant_balloon", new HotAirBalloonItem(new Item.Settings().maxCount(1)), ItemGroups.TOOLS);
Item CLOUD = register("cloud", new CloudBlockItem(UBlocks.CLOUD, new Item.Settings()), ItemGroups.NATURAL); Item CLOUD = register("cloud", new CloudBlockItem(UBlocks.CLOUD, new Item.Settings()), ItemGroups.NATURAL);
Item CLOUD_SLAB = register("cloud_slab", new CloudBlockItem(UBlocks.CLOUD_SLAB, new Item.Settings()), ItemGroups.NATURAL);
Item DENSE_CLOUD = register("dense_cloud", new CloudBlockItem(UBlocks.DENSE_CLOUD, new Item.Settings()), ItemGroups.NATURAL); Item DENSE_CLOUD = register("dense_cloud", new CloudBlockItem(UBlocks.DENSE_CLOUD, new Item.Settings()), ItemGroups.NATURAL);
Item DENSE_CLOUD_SLAB = register("dense_cloud_slab", new CloudBlockItem(UBlocks.DENSE_CLOUD_SLAB, new Item.Settings()), ItemGroups.NATURAL);
Item CLOUD_PILLAR = register("cloud_pillar", new CloudBlockItem(UBlocks.CLOUD_PILLAR, new Item.Settings()), ItemGroups.NATURAL); Item CLOUD_PILLAR = register("cloud_pillar", new CloudBlockItem(UBlocks.CLOUD_PILLAR, new Item.Settings()), ItemGroups.NATURAL);
AmuletItem PEGASUS_AMULET = register("pegasus_amulet", new PegasusAmuletItem(new FabricItemSettings() AmuletItem PEGASUS_AMULET = register("pegasus_amulet", new PegasusAmuletItem(new FabricItemSettings()

View file

@ -0,0 +1,7 @@
{
"variants": {
"type=double": { "model": "unicopia:block/cloud" },
"type=bottom": { "model": "unicopia:block/cloud_slab" },
"type=top": { "model": "unicopia:block/cloud_slab_top" }
}
}

View file

@ -0,0 +1,7 @@
{
"variants": {
"type=double": { "model": "unicopia:block/cloud" },
"type=bottom": { "model": "unicopia:block/cloud_slab" },
"type=top": { "model": "unicopia:block/cloud_slab_top" }
}
}

View file

@ -218,8 +218,10 @@
"block.unicopia.chiselled_chitin_stairs": "Chiselled Chitin Stairs", "block.unicopia.chiselled_chitin_stairs": "Chiselled Chitin Stairs",
"block.unicopia.cloud": "Cloud", "block.unicopia.cloud": "Cloud",
"block.unicopia.cloud_slab": "Cloud Slab",
"block.unicopia.cloud_pillar": "Cloud Pillar", "block.unicopia.cloud_pillar": "Cloud Pillar",
"block.unicopia.dense_cloud": "Dense Cloud", "block.unicopia.dense_cloud": "Dense Cloud",
"block.unicopia.dense_cloud_slab": "Dense Cloud Slab",
"block.unicopia.oats": "Oats", "block.unicopia.oats": "Oats",
"block.unicopia.oats_stem": "Oats", "block.unicopia.oats_stem": "Oats",

View file

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/slab",
"textures": {
"bottom": "unicopia:block/cloud",
"side": "unicopia:block/cloud",
"top": "unicopia:block/cloud"
}
}

View file

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/slab_top",
"textures": {
"bottom": "unicopia:block/cloud",
"side": "unicopia:block/cloud",
"top": "unicopia:block/cloud"
}
}

View file

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/slab",
"textures": {
"bottom": "unicopia:block/dense_cloud",
"side": "unicopia:block/dense_cloud",
"top": "unicopia:block/dense_cloud"
}
}

View file

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/slab_top",
"textures": {
"bottom": "unicopia:block/dense_cloud",
"side": "unicopia:block/dense_cloud",
"top": "unicopia:block/dense_cloud"
}
}

View file

@ -0,0 +1,3 @@
{
"parent": "unicopia:block/cloud_slab"
}

View file

@ -0,0 +1,3 @@
{
"parent": "unicopia:block/dense_cloud_slab"
}