package ru.betterend.blocks; import java.util.Map; import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Mirror; import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.block.SimpleWaterloggedBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.util.BlocksHelper; public class EndLotusStemBlock extends BlockBase implements SimpleWaterloggedBlock, IRenderTypeable { public static final EnumProperty FACING = BlockStateProperties.FACING; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public static final BooleanProperty LEAF = BooleanProperty.create("leaf"); public static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; private static final Map SHAPES = Maps.newEnumMap(Axis.class); public EndLotusStemBlock() { super(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS)); this.registerDefaultState(defaultBlockState().setValue(WATERLOGGED, false).setValue(SHAPE, TripleShape.MIDDLE).setValue(LEAF, false).setValue(FACING, Direction.UP)); } @Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return state.getValue(LEAF) ? SHAPES.get(Axis.Y) : SHAPES.get(state.getValue(FACING).getAxis()); } @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(FACING, WATERLOGGED, SHAPE, LEAF); } @Override public FluidState getFluidState(BlockState state) { return (Boolean) state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } @Override public BlockState getStateForPlacement(BlockPlaceContext ctx) { LevelAccessor worldAccess = ctx.getLevel(); BlockPos blockPos = ctx.getClickedPos(); return this.defaultBlockState().setValue(WATERLOGGED, worldAccess.getFluidState(blockPos).getType() == Fluids.WATER).setValue(FACING, ctx.getClickedFace()); } @Override public BlockState rotate(BlockState state, Rotation rotation) { return BlocksHelper.rotateHorizontal(state, rotation, FACING); } @Override public BlockState mirror(BlockState state, Mirror mirror) { return BlocksHelper.mirrorHorizontal(state, mirror, FACING); } @Override public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) { if ((Boolean) state.getValue(WATERLOGGED)) { world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); } return state; } @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } static { SHAPES.put(Axis.X, Block.box(0, 6, 6, 16, 10, 10)); SHAPES.put(Axis.Y, Block.box(6, 0, 6, 10, 16, 10)); SHAPES.put(Axis.Z, Block.box(6, 6, 0, 10, 10, 16)); } }