/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.serialization.MapCodec */ package net.minecraft.world.level.block; import com.mojang.serialization.MapCodec; import java.util.Map; import java.util.Optional; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; import net.minecraft.tags.BlockTags; import net.minecraft.util.BlockUtil; import net.minecraft.util.RandomSource; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.ScheduledTickAccess; import net.minecraft.world.level.block.BigDripleafBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.BonemealableBlock; import net.minecraft.world.level.block.HorizontalDirectionalBlock; import net.minecraft.world.level.block.SimpleWaterloggedBlock; import net.minecraft.world.level.block.state.BlockBehaviour; 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.material.FluidState; import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; public class BigDripleafStemBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock, BonemealableBlock { public static final MapCodec CODEC = BigDripleafStemBlock.simpleCodec(BigDripleafStemBlock::new); private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; private static final Map SHAPES = Shapes.rotateHorizontal(Block.column(6.0, 0.0, 16.0).move(0.0, 0.0, 0.25).optimize()); public MapCodec codec() { return CODEC; } protected BigDripleafStemBlock(BlockBehaviour.Properties properties) { super(properties); this.registerDefaultState((BlockState)((BlockState)((BlockState)this.stateDefinition.any()).setValue(WATERLOGGED, false)).setValue(FACING, Direction.NORTH)); } @Override protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { return SHAPES.get(state.getValue(FACING)); } @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(WATERLOGGED, FACING); } @Override protected FluidState getFluidState(BlockState state) { if (state.getValue(WATERLOGGED).booleanValue()) { return Fluids.WATER.getSource(false); } return super.getFluidState(state); } @Override protected boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) { BlockPos belowPos = pos.below(); BlockState belowState = level.getBlockState(belowPos); BlockState aboveState = level.getBlockState(pos.above()); return !(!belowState.is(this) && !belowState.is(BlockTags.BIG_DRIPLEAF_PLACEABLE) || !aboveState.is(this) && !aboveState.is(Blocks.BIG_DRIPLEAF)); } protected static boolean place(LevelAccessor level, BlockPos pos, FluidState fluidState, Direction facing) { BlockState newState = (BlockState)((BlockState)Blocks.BIG_DRIPLEAF_STEM.defaultBlockState().setValue(WATERLOGGED, fluidState.isSourceOfType(Fluids.WATER))).setValue(FACING, facing); return level.setBlock(pos, newState, 3); } @Override protected BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess ticks, BlockPos pos, Direction directionToNeighbour, BlockPos neighbourPos, BlockState neighbourState, RandomSource random) { if (!(directionToNeighbour != Direction.DOWN && directionToNeighbour != Direction.UP || state.canSurvive(level, pos))) { ticks.scheduleTick(pos, this, 1); } if (state.getValue(WATERLOGGED).booleanValue()) { ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); } return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random); } @Override protected void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { if (!state.canSurvive(level, pos)) { level.destroyBlock(pos, true); } } @Override public boolean isValidBonemealTarget(LevelReader level, BlockPos pos, BlockState state) { Optional headPos = BlockUtil.getTopConnectedBlock(level, pos, state.getBlock(), Direction.UP, Blocks.BIG_DRIPLEAF); if (headPos.isEmpty()) { return false; } BlockPos abovePos = headPos.get().above(); BlockState aboveState = level.getBlockState(abovePos); return BigDripleafBlock.canPlaceAt(level, abovePos, aboveState); } @Override public boolean isBonemealSuccess(Level level, RandomSource random, BlockPos pos, BlockState state) { return true; } @Override public void performBonemeal(ServerLevel level, RandomSource random, BlockPos pos, BlockState state) { Optional forwardPos = BlockUtil.getTopConnectedBlock(level, pos, state.getBlock(), Direction.UP, Blocks.BIG_DRIPLEAF); if (forwardPos.isEmpty()) { return; } BlockPos headPos = forwardPos.get(); BlockPos placeHeadPos = headPos.above(); Direction facing = (Direction)state.getValue(FACING); BigDripleafStemBlock.place(level, headPos, level.getFluidState(headPos), facing); BigDripleafBlock.place(level, placeHeadPos, level.getFluidState(placeHeadPos), facing); } @Override protected ItemStack getCloneItemStack(LevelReader level, BlockPos pos, BlockState state, boolean includeData) { return new ItemStack(Blocks.BIG_DRIPLEAF); } }