minecraft-source/src/net/minecraft/world/item/HoeItem.java

72 lines
3.3 KiB
Java

package net.minecraft.world.item;
import com.google.common.collect.Maps;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.entity.monster.SharedMonsterAttributes;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import com.google.common.collect.Multimap;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.player.Player;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Block;
import java.util.Map;
public class HoeItem extends TieredItem {
private final float attackSpeed;
protected static final Map<Block, BlockState> TILLABLES;
public HoeItem(final Tier bfp, final float float2, final Properties a) {
super(bfp, a);
this.attackSpeed = float2;
}
@Override
public InteractionResult useOn(final UseOnContext bfw) {
final Level bjt3 = bfw.getLevel();
final BlockPos fk4 = bfw.getClickedPos();
if (bfw.getClickedFace() != Direction.DOWN && bjt3.getBlockState(fk4.above()).isAir()) {
final BlockState byg5 = HoeItem.TILLABLES.get(bjt3.getBlockState(fk4).getBlock());
if (byg5 != null) {
final Player ayg2 = bfw.getPlayer();
bjt3.playSound(ayg2, fk4, SoundEvents.HOE_TILL, SoundSource.BLOCKS, 1.0f, 1.0f);
if (!bjt3.isClientSide) {
bjt3.setBlock(fk4, byg5, 11);
if (ayg2 != null) {
bfw.getItemInHand().<Player>hurtAndBreak(1, ayg2, ayg -> ayg.broadcastBreakEvent(bfw.getHand()));
}
}
return InteractionResult.SUCCESS;
}
}
return InteractionResult.PASS;
}
@Override
public boolean hurtEnemy(final ItemStack bek, final LivingEntity akw2, final LivingEntity akw3) {
bek.<LivingEntity>hurtAndBreak(1, akw3, akw -> akw.broadcastBreakEvent(EquipmentSlot.MAINHAND));
return true;
}
@Override
public Multimap<String, AttributeModifier> getDefaultAttributeModifiers(final EquipmentSlot aks) {
final Multimap<String, AttributeModifier> multimap3 = super.getDefaultAttributeModifiers(aks);
if (aks == EquipmentSlot.MAINHAND) {
multimap3.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(HoeItem.BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", 0.0, AttributeModifier.Operation.ADDITION));
multimap3.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(HoeItem.BASE_ATTACK_SPEED_UUID, "Weapon modifier", this.attackSpeed, AttributeModifier.Operation.ADDITION));
}
return multimap3;
}
static {
TILLABLES = Maps.newHashMap(ImmutableMap.<Block, BlockState>of(Blocks.GRASS_BLOCK, Blocks.FARMLAND.defaultBlockState(), Blocks.GRASS_PATH, Blocks.FARMLAND.defaultBlockState(), Blocks.DIRT, Blocks.FARMLAND.defaultBlockState(), Blocks.COARSE_DIRT, Blocks.DIRT.defaultBlockState()));
}
}