/* * 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 net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.util.RandomSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.InsideBlockEffectApplier; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.BonemealableBlock; import net.minecraft.world.level.block.VegetationBlock; 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.IntegerProperty; import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.level.storage.loot.BuiltInLootTables; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; public class SweetBerryBushBlock extends VegetationBlock implements BonemealableBlock { public static final MapCodec CODEC = SweetBerryBushBlock.simpleCodec(SweetBerryBushBlock::new); private static final float HURT_SPEED_THRESHOLD = 0.003f; public static final int MAX_AGE = 3; public static final IntegerProperty AGE = BlockStateProperties.AGE_3; private static final VoxelShape SHAPE_SAPLING = Block.column(10.0, 0.0, 8.0); private static final VoxelShape SHAPE_GROWING = Block.column(14.0, 0.0, 16.0); public MapCodec codec() { return CODEC; } public SweetBerryBushBlock(BlockBehaviour.Properties properties) { super(properties); this.registerDefaultState((BlockState)((BlockState)this.stateDefinition.any()).setValue(AGE, 0)); } @Override protected ItemStack getCloneItemStack(LevelReader level, BlockPos pos, BlockState state, boolean includeData) { return new ItemStack(Items.SWEET_BERRIES); } @Override protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { return switch (state.getValue(AGE)) { case 0 -> SHAPE_SAPLING; case 3 -> Shapes.block(); default -> SHAPE_GROWING; }; } @Override protected boolean isRandomlyTicking(BlockState state) { return state.getValue(AGE) < 3; } @Override protected void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { int age = state.getValue(AGE); if (age < 3 && random.nextInt(5) == 0 && level.getRawBrightness(pos.above(), 0) >= 9) { BlockState newState = (BlockState)state.setValue(AGE, age + 1); level.setBlock(pos, newState, 2); level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(newState)); } } @Override protected void entityInside(BlockState state, Level level, BlockPos pos, Entity entity, InsideBlockEffectApplier effectApplier, boolean isPrecise) { Vec3 movement; ServerLevel serverLevel; block7: { block6: { if (!(entity instanceof LivingEntity) || entity.getType() == EntityType.FOX || entity.getType() == EntityType.BEE) { return; } entity.makeStuckInBlock(state, new Vec3(0.8f, 0.75, 0.8f)); if (!(level instanceof ServerLevel)) break block6; serverLevel = (ServerLevel)level; if (state.getValue(AGE) != 0) break block7; } return; } Vec3 vec3 = movement = entity.isClientAuthoritative() ? entity.getKnownMovement() : entity.oldPosition().subtract(entity.position()); if (movement.horizontalDistanceSqr() > 0.0) { double xs = Math.abs(movement.x()); double zs = Math.abs(movement.z()); if (xs >= (double)0.003f || zs >= (double)0.003f) { entity.hurtServer(serverLevel, level.damageSources().sweetBerryBush(), 1.0f); } } } @Override protected InteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) { boolean isMaxAge; int age = state.getValue(AGE); boolean bl = isMaxAge = age == 3; if (!isMaxAge && itemStack.is(Items.BONE_MEAL)) { return InteractionResult.PASS; } return super.useItemOn(itemStack, state, level, pos, player, hand, hitResult); } @Override protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) { if (state.getValue(AGE) > 1) { if (level instanceof ServerLevel) { ServerLevel serverLevel = (ServerLevel)level; Block.dropFromBlockInteractLootTable(serverLevel, BuiltInLootTables.HARVEST_SWEET_BERRY_BUSH, state, level.getBlockEntity(pos), null, player, (serverlvl, itemStack) -> Block.popResource((Level)serverlvl, pos, itemStack)); serverLevel.playSound(null, pos, SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES, SoundSource.BLOCKS, 1.0f, 0.8f + serverLevel.random.nextFloat() * 0.4f); BlockState newState = (BlockState)state.setValue(AGE, 1); serverLevel.setBlock(pos, newState, 2); serverLevel.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(player, newState)); } return InteractionResult.SUCCESS; } return super.useWithoutItem(state, level, pos, player, hitResult); } @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(AGE); } @Override public boolean isValidBonemealTarget(LevelReader level, BlockPos pos, BlockState state) { return state.getValue(AGE) < 3; } @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) { int newAge = Math.min(3, state.getValue(AGE) + 1); level.setBlock(pos, (BlockState)state.setValue(AGE, newAge), 2); } }