package eu.midnightdust.motschen.rocks.block; import eu.midnightdust.motschen.rocks.RocksMain; import eu.midnightdust.motschen.rocks.blockstates.SeashellVariation; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.block.*; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.fluid.FluidState; import net.minecraft.fluid.Fluids; import net.minecraft.item.ItemPlacementContext; import net.minecraft.sound.BlockSoundGroup; import net.minecraft.state.StateManager; import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.EnumProperty; import net.minecraft.state.property.Properties; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.BlockView; import net.minecraft.world.World; import net.minecraft.world.WorldView; public class Seashell extends Block implements Waterloggable { private static final VoxelShape SHAPE; private static final EnumProperty SEASHELL_VARIATION = RocksMain.SEASHELL_VARIATION; public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; public Seashell() { super(FabricBlockSettings.copy(Blocks.POPPY).nonOpaque().sounds(BlockSoundGroup.STONE)); this.setDefaultState(this.stateManager.getDefaultState().with(SEASHELL_VARIATION, SeashellVariation.PINK).with(WATERLOGGED, false)); } @Override public FluidState getFluidState(BlockState blockState_1) { return blockState_1.get(WATERLOGGED) ? Fluids.WATER.getStill(true) : super.getFluidState(blockState_1); } @Override public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) { FluidState fluidState = itemPlacementContext.getWorld().getFluidState(itemPlacementContext.getBlockPos()); return super.getPlacementState(itemPlacementContext) .with(SEASHELL_VARIATION, SeashellVariation.PINK).with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER); } public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if (player.isCreative()) { if (state.get(SEASHELL_VARIATION) == SeashellVariation.YELLOW) { world.setBlockState(pos, state.with(SEASHELL_VARIATION, SeashellVariation.WHITE)); } if (state.get(SEASHELL_VARIATION) == SeashellVariation.WHITE) { world.setBlockState(pos, state.with(SEASHELL_VARIATION, SeashellVariation.PINK)); } if (state.get(SEASHELL_VARIATION) == SeashellVariation.PINK) { world.setBlockState(pos, state.with(SEASHELL_VARIATION, SeashellVariation.YELLOW)); } return ActionResult.SUCCESS; } else return ActionResult.FAIL; } @Override protected void appendProperties(StateManager.Builder builder) { builder.add(SEASHELL_VARIATION, WATERLOGGED); } @Override public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) { return SHAPE; } static { VoxelShape shape = createCuboidShape(0, 0, 0, 16, 3, 16); SHAPE = shape; } public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP); } }