Path: blob/1.21.x/src/main/java/net/minecraftforge/event/entity/player/ItemFishedEvent.java
7412 views
/*1* Copyright (c) Forge Development LLC and contributors2* SPDX-License-Identifier: LGPL-2.1-only3*/45package net.minecraftforge.event.entity.player;67import com.google.common.base.Preconditions;8import net.minecraft.world.entity.player.Player;9import net.minecraft.world.entity.projectile.FishingHook;10import net.minecraft.world.item.ItemStack;11import net.minecraft.core.NonNullList;12import net.minecraftforge.eventbus.api.bus.CancellableEventBus;13import net.minecraftforge.eventbus.api.event.MutableEvent;14import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;1516import javax.annotation.Nonnegative;17import java.util.List;1819/**20* This event is called when a player fishes an item.21* <br>22* This event is {@linkplain Cancellable cancellable}. If cancelled, the player will not receive any items, but the hook23* will still take the damage specified24*/25public final class ItemFishedEvent extends MutableEvent implements Cancellable, PlayerEvent {26public static final CancellableEventBus<ItemFishedEvent> BUS = CancellableEventBus.create(ItemFishedEvent.class);2728private final Player player;29private final NonNullList<ItemStack> stacks = NonNullList.create();30private final FishingHook hook;31private int rodDamage;3233public ItemFishedEvent(List<ItemStack> stacks, int rodDamage, FishingHook hook) {34this.player = hook.getPlayerOwner();35this.stacks.addAll(stacks);36this.rodDamage = rodDamage;37this.hook = hook;38}3940@Override41public Player getEntity() {42return player;43}4445/**46* Get the damage the rod will take.47* @return The damage the rod will take48*/49public int getRodDamage() {50return rodDamage;51}5253/**54* Specifies the amount of damage that the fishing rod should take.55* This is not added to the pre-existing damage to be taken.56* @param rodDamage The damage the rod will take. Must be nonnegative57*/58public void damageRodBy(@Nonnegative int rodDamage) {59Preconditions.checkArgument(rodDamage >= 0);60this.rodDamage = rodDamage;61}6263/**64* Use this to get the items the player will receive.65* You cannot use this to modify the drops the player will get.66* If you want to affect the loot, you should use LootTables.67*/68public NonNullList<ItemStack> getDrops() {69return stacks;70}7172/**73* Use this to stuff related to the hook itself, like the position of the bobber.74*/75public FishingHook getHookEntity() {76return hook;77}78}798081