package ru.betterend.blocks; import java.util.EnumMap; import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.FluidFillable; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.block.ShapeContext; import net.minecraft.world.level.block.Waterloggable; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.FluidState; import net.minecraft.world.level.material.Fluids; import net.minecraft.world.item.ItemPlacementContext; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.WorldView; import ru.betterend.blocks.basis.AttachedBlock; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; public class SmaragdantCrystalShardBlock extends AttachedBlock implements IRenderTypeable, Waterloggable, FluidFillable { private static final EnumMap BOUNDING_SHAPES = Maps.newEnumMap(Direction.class); public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; public SmaragdantCrystalShardBlock() { super(FabricBlockSettings.of(Material.STONE).materialColor(MaterialColor.COLOR_GREEN) .breakByTool(FabricToolTags.PICKAXES).sounds(SoundType.GLASS).luminance(15).requiresTool() .noCollision()); } @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { super.createBlockStateDefinition(stateManager); stateManager.add(WATERLOGGED); } @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } @Override public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) { return !state.getValue(WATERLOGGED); } @Override public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { return !state.getValue(WATERLOGGED); } @Override public BlockState getPlacementState(ItemPlacementContext ctx) { BlockState state = super.getPlacementState(ctx); if (state != null) { WorldView worldView = ctx.getLevel(); BlockPos blockPos = ctx.getBlockPos(); boolean water = worldView.getFluidState(blockPos).getFluid() == Fluids.WATER; return state.with(WATERLOGGED, water); } return null; } @Override public FluidState getFluidState(BlockState state) { return state.getValue(WATERLOGGED) ? Fluids.WATER.getStill(false) : Fluids.EMPTY.defaultBlockState(); } @Override public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { return BOUNDING_SHAPES.get(state.getValue(FACING)); } @Override public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { Direction direction = (Direction) state.getValue(FACING); BlockPos blockPos = pos.relative(direction.getOpposite()); return world.getBlockState(blockPos).isSideSolidFullSquare(world, blockPos, direction); } static { BOUNDING_SHAPES.put(Direction.UP, VoxelShapes.cuboid(0.125, 0.0, 0.125, 0.875F, 0.875F, 0.875F)); BOUNDING_SHAPES.put(Direction.DOWN, VoxelShapes.cuboid(0.125, 0.125, 0.125, 0.875F, 1.0, 0.875F)); BOUNDING_SHAPES.put(Direction.NORTH, VoxelShapes.cuboid(0.125, 0.125, 0.125, 0.875F, 0.875F, 1.0)); BOUNDING_SHAPES.put(Direction.SOUTH, VoxelShapes.cuboid(0.125, 0.125, 0.0, 0.875F, 0.875F, 0.875F)); BOUNDING_SHAPES.put(Direction.WEST, VoxelShapes.cuboid(0.125, 0.125, 0.125, 1.0, 0.875F, 0.875F)); BOUNDING_SHAPES.put(Direction.EAST, VoxelShapes.cuboid(0.0, 0.125, 0.125, 0.875F, 0.875F, 0.875F)); } }