/* * Decompiled with CFR 0.152. */ package net.minecraft.world.item; import java.util.List; import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.core.BlockPos; import net.minecraft.core.HolderGetter; import net.minecraft.core.HolderSet; import net.minecraft.core.component.DataComponents; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.tags.BlockTags; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.component.Tool; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.GrowingPlantHeadBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.gameevent.GameEvent; public class ShearsItem extends Item { public ShearsItem(Item.Properties properties) { super(properties); } public static Tool createToolProperties() { HolderGetter registrationLookup = BuiltInRegistries.acquireBootstrapRegistrationLookup(BuiltInRegistries.BLOCK); return new Tool(List.of(Tool.Rule.minesAndDrops(HolderSet.direct(Blocks.COBWEB.builtInRegistryHolder()), 15.0f), Tool.Rule.overrideSpeed(registrationLookup.getOrThrow(BlockTags.LEAVES), 15.0f), Tool.Rule.overrideSpeed(registrationLookup.getOrThrow(BlockTags.WOOL), 5.0f), Tool.Rule.overrideSpeed(HolderSet.direct(Blocks.VINE.builtInRegistryHolder(), Blocks.GLOW_LICHEN.builtInRegistryHolder()), 2.0f)), 1.0f, 1, true); } @Override public boolean mineBlock(ItemStack itemStack, Level level, BlockState state, BlockPos pos, LivingEntity miner) { Tool tool = itemStack.get(DataComponents.TOOL); if (tool == null) { return false; } if (!level.isClientSide() && !state.is(BlockTags.FIRE) && tool.damagePerBlock() > 0) { itemStack.hurtAndBreak(tool.damagePerBlock(), miner, EquipmentSlot.MAINHAND); } return true; } @Override public InteractionResult useOn(UseOnContext context) { GrowingPlantHeadBlock plantBlock; BlockPos pos; Level level = context.getLevel(); BlockState state = level.getBlockState(pos = context.getClickedPos()); Block block = state.getBlock(); if (block instanceof GrowingPlantHeadBlock && !(plantBlock = (GrowingPlantHeadBlock)block).isMaxAge(state)) { Player player = context.getPlayer(); ItemStack itemInHand = context.getItemInHand(); if (player instanceof ServerPlayer) { CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger((ServerPlayer)player, pos, itemInHand); } level.playSound((Entity)player, pos, SoundEvents.GROWING_PLANT_CROP, SoundSource.BLOCKS, 1.0f, 1.0f); BlockState newState = plantBlock.getMaxAgeState(state); level.setBlockAndUpdate(pos, newState); level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(context.getPlayer(), newState)); if (player != null) { itemInHand.hurtAndBreak(1, (LivingEntity)player, context.getHand().asEquipmentSlot()); } return InteractionResult.SUCCESS; } return super.useOn(context); } }