Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MinecraftForge
GitHub Repository: MinecraftForge/MinecraftForge
Path: blob/1.21.x/src/main/java/net/minecraftforge/event/entity/player/ItemFishedEvent.java
7412 views
1
/*
2
* Copyright (c) Forge Development LLC and contributors
3
* SPDX-License-Identifier: LGPL-2.1-only
4
*/
5
6
package net.minecraftforge.event.entity.player;
7
8
import com.google.common.base.Preconditions;
9
import net.minecraft.world.entity.player.Player;
10
import net.minecraft.world.entity.projectile.FishingHook;
11
import net.minecraft.world.item.ItemStack;
12
import net.minecraft.core.NonNullList;
13
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
14
import net.minecraftforge.eventbus.api.event.MutableEvent;
15
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
16
17
import javax.annotation.Nonnegative;
18
import java.util.List;
19
20
/**
21
* This event is called when a player fishes an item.
22
* <br>
23
* This event is {@linkplain Cancellable cancellable}. If cancelled, the player will not receive any items, but the hook
24
* will still take the damage specified
25
*/
26
public final class ItemFishedEvent extends MutableEvent implements Cancellable, PlayerEvent {
27
public static final CancellableEventBus<ItemFishedEvent> BUS = CancellableEventBus.create(ItemFishedEvent.class);
28
29
private final Player player;
30
private final NonNullList<ItemStack> stacks = NonNullList.create();
31
private final FishingHook hook;
32
private int rodDamage;
33
34
public ItemFishedEvent(List<ItemStack> stacks, int rodDamage, FishingHook hook) {
35
this.player = hook.getPlayerOwner();
36
this.stacks.addAll(stacks);
37
this.rodDamage = rodDamage;
38
this.hook = hook;
39
}
40
41
@Override
42
public Player getEntity() {
43
return player;
44
}
45
46
/**
47
* Get the damage the rod will take.
48
* @return The damage the rod will take
49
*/
50
public int getRodDamage() {
51
return rodDamage;
52
}
53
54
/**
55
* Specifies the amount of damage that the fishing rod should take.
56
* This is not added to the pre-existing damage to be taken.
57
* @param rodDamage The damage the rod will take. Must be nonnegative
58
*/
59
public void damageRodBy(@Nonnegative int rodDamage) {
60
Preconditions.checkArgument(rodDamage >= 0);
61
this.rodDamage = rodDamage;
62
}
63
64
/**
65
* Use this to get the items the player will receive.
66
* You cannot use this to modify the drops the player will get.
67
* If you want to affect the loot, you should use LootTables.
68
*/
69
public NonNullList<ItemStack> getDrops() {
70
return stacks;
71
}
72
73
/**
74
* Use this to stuff related to the hook itself, like the position of the bobber.
75
*/
76
public FishingHook getHookEntity() {
77
return hook;
78
}
79
}
80
81