Improve concrete with bars and parquet
This commit is contained in:
parent
cb857a028b
commit
f2373e0971
65 changed files with 803 additions and 328 deletions
|
@ -1,13 +1,14 @@
|
|||
package su.a71.new_soviet.blocks;
|
||||
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.enums.WallMountLocation;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
@ -15,38 +16,53 @@ import net.minecraft.util.shape.VoxelShape;
|
|||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.a71.new_soviet.util.Shapes;
|
||||
|
||||
public class ConcreteWithBarsBlock extends HorizontalFacingBlock implements Waterloggable {
|
||||
public static final DirectionProperty VERTICAL_DIRECTION;
|
||||
import java.util.List;
|
||||
|
||||
public class ConcreteWithBarsBlock extends WallMountedBlock implements Waterloggable {
|
||||
public static final BooleanProperty WATERLOGGED;
|
||||
public static final VoxelShape SHAPE_UP;
|
||||
public static final VoxelShape SHAPE_DOWN;
|
||||
public static final Shapes.HorizontalShape SHAPE_WALL;
|
||||
public static final Shapes.HorizontalShape SHAPE_FLOOR;
|
||||
public static final Shapes.HorizontalShape SHAPE_CEILING;
|
||||
public static final EnumProperty<WallMountLocation> FACE;
|
||||
|
||||
public ConcreteWithBarsBlock(Settings settings) {
|
||||
super(settings);
|
||||
setDefaultState(getDefaultState()
|
||||
.with(Properties.HORIZONTAL_FACING, Direction.NORTH)
|
||||
.with(VERTICAL_DIRECTION, Direction.UP)
|
||||
.with(FACE, WallMountLocation.FLOOR)
|
||||
.with(WATERLOGGED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(Properties.HORIZONTAL_FACING, VERTICAL_DIRECTION, WATERLOGGED);
|
||||
builder.add(Properties.HORIZONTAL_FACING, FACE, WATERLOGGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
|
||||
|
||||
return super.getPlacementState(ctx)
|
||||
.with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite())
|
||||
.with(VERTICAL_DIRECTION, ctx.getVerticalPlayerLookDirection().getOpposite())
|
||||
.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
|
||||
for (Direction direction : ctx.getPlacementDirections()) {
|
||||
BlockState blockState;
|
||||
if (direction.getAxis() == Direction.Axis.Y) {
|
||||
blockState = this.getDefaultState().with(FACE, direction == Direction.UP ? WallMountLocation.CEILING : WallMountLocation.FLOOR).with(FACING, ctx.getHorizontalPlayerFacing());
|
||||
} else {
|
||||
blockState = this.getDefaultState().with(FACE, WallMountLocation.WALL).with(FACING, direction.getOpposite());
|
||||
}
|
||||
|
||||
if (blockState.canPlaceAt(ctx.getWorld(), ctx.getBlockPos())) {
|
||||
return blockState.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity entity, float fallDistance) {
|
||||
if (state.get(VERTICAL_DIRECTION) == Direction.UP) {
|
||||
if (state.get(FACE) == WallMountLocation.CEILING) {
|
||||
entity.handleFallDamage(fallDistance + 2.0F, 2.0F, world.getDamageSources().stalagmite());
|
||||
} else {
|
||||
super.onLandedUpon(world, state, pos, entity, fallDistance);
|
||||
|
@ -54,10 +70,16 @@ public class ConcreteWithBarsBlock extends HorizontalFacingBlock implements Wate
|
|||
}
|
||||
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
if (state.get(VERTICAL_DIRECTION) == Direction.DOWN) {
|
||||
return SHAPE_UP;
|
||||
}
|
||||
return SHAPE_DOWN;
|
||||
return switch (state.get(FACE)) {
|
||||
case FLOOR -> SHAPE_FLOOR.north();
|
||||
case WALL -> switch (state.get(FACING)) {
|
||||
case NORTH -> SHAPE_WALL.north();
|
||||
case SOUTH -> SHAPE_WALL.south();
|
||||
case WEST -> SHAPE_WALL.west();
|
||||
default -> SHAPE_WALL.east();
|
||||
};
|
||||
default -> SHAPE_CEILING.north();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -73,9 +95,10 @@ public class ConcreteWithBarsBlock extends HorizontalFacingBlock implements Wate
|
|||
}
|
||||
|
||||
static {
|
||||
VERTICAL_DIRECTION = Properties.VERTICAL_DIRECTION;
|
||||
FACE = Properties.WALL_MOUNT_LOCATION;
|
||||
WATERLOGGED = Properties.WATERLOGGED;
|
||||
SHAPE_DOWN = Block.createCuboidShape(0, 0, 0, 16, 8, 16);
|
||||
SHAPE_UP = Block.createCuboidShape(0, 8, 0, 16, 16, 16);
|
||||
SHAPE_FLOOR = new Shapes.HorizontalShape(List.of(List.of(0.01, 0.0, 0.01, 15.99, 8.0, 15.99)));
|
||||
SHAPE_CEILING = new Shapes.HorizontalShape(List.of(List.of(0.01, 8.0, 0.01, 15.99, 15.99, 15.99)));
|
||||
SHAPE_WALL = new Shapes.HorizontalShape(List.of(List.of(0.01, 0.01, 8.0, 15.99, 15.99, 15.99)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue