Commits

Airtheon Thesalion authored and md_5 committed bc6a175eff6
#767: Add wait time modification for FishHook
No tags

nms-patches/EntityFishingHook.patch

Modified
5 5 import java.util.Random;
6 6 import javax.annotation.Nullable;
7 7 +// CraftBukkit start
8 8 +import org.bukkit.entity.Player;
9 9 +import org.bukkit.entity.FishHook;
10 10 +import org.bukkit.event.player.PlayerFishEvent;
11 11 +// CraftBukkit end
12 12
13 13 public class EntityFishingHook extends IProjectile {
14 14
15 -@@ -253,6 +258,10 @@
15 +@@ -25,6 +30,12 @@
16 + private final int an;
17 + private final int ao;
18 +
19 ++ // CraftBukkit start - Extra variables to enable modification of fishing wait time, values are minecraft defaults
20 ++ public int minWaitTime = 100;
21 ++ public int maxWaitTime = 600;
22 ++ public boolean applyLure = true;
23 ++ // CraftBukkit end
24 ++
25 + private EntityFishingHook(World world, EntityHuman entityhuman, int i, int j) {
26 + super(EntityTypes.FISHING_BOBBER, world);
27 + this.b = new Random();
28 +@@ -253,6 +264,10 @@
16 29 this.ah = 0;
17 30 this.ai = 0;
18 31 this.getDataWatcher().set(EntityFishingHook.f, false);
19 32 + // CraftBukkit start
20 33 + PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.getOwner().getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT);
21 34 + this.world.getServer().getPluginManager().callEvent(playerFishEvent);
22 35 + // CraftBukkit end
23 36 }
24 37 } else {
25 38 float f;
26 -@@ -286,6 +295,13 @@
39 +@@ -286,6 +301,13 @@
27 40 worldserver.a(Particles.FISHING, d0, d1, d2, 0, (double) (-f4), 0.01D, (double) f3, 1.0D);
28 41 }
29 42 } else {
30 43 + // CraftBukkit start
31 44 + PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.getOwner().getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.BITE);
32 45 + this.world.getServer().getPluginManager().callEvent(playerFishEvent);
33 46 + if (playerFishEvent.isCancelled()) {
34 47 + return;
35 48 + }
36 49 + // CraftBukkit end
37 50 this.playSound(SoundEffects.ENTITY_FISHING_BOBBER_SPLASH, 0.25F, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
38 51 double d3 = this.locY() + 0.5D;
39 52
40 -@@ -390,6 +406,14 @@
53 +@@ -322,8 +344,10 @@
54 + this.ai = MathHelper.nextInt(this.random, 20, 80);
55 + }
56 + } else {
57 +- this.ah = MathHelper.nextInt(this.random, 100, 600);
58 +- this.ah -= this.ao * 20 * 5;
59 ++ // CraftBukkit start - logic to modify fishing wait time
60 ++ this.ah = MathHelper.nextInt(this.random, this.minWaitTime, this.maxWaitTime); // PAIL rename waitTime
61 ++ this.ah -= (this.applyLure) ? this.ao * 20 * 5 : 0; // PAIL rename waitTime, lureLevel
62 ++ // CraftBukkit end
63 + }
64 + }
65 +
66 +@@ -390,6 +414,14 @@
41 67 int i = 0;
42 68
43 69 if (this.hooked != null) {
44 70 + // CraftBukkit start
45 71 + PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), this.hooked.getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY);
46 72 + this.world.getServer().getPluginManager().callEvent(playerFishEvent);
47 73 +
48 74 + if (playerFishEvent.isCancelled()) {
49 75 + return 0;
50 76 + }
51 77 + // CraftBukkit end
52 78 this.reel();
53 79 CriterionTriggers.D.a((EntityPlayer) entityhuman, itemstack, this, (Collection) Collections.emptyList());
54 80 this.world.broadcastEntityEffect(this, (byte) 31);
55 -@@ -405,6 +429,15 @@
81 +@@ -405,6 +437,15 @@
56 82 while (iterator.hasNext()) {
57 83 ItemStack itemstack1 = (ItemStack) iterator.next();
58 84 EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY(), this.locZ(), itemstack1);
59 85 + // CraftBukkit start
60 86 + PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), entityitem.getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH);
61 87 + playerFishEvent.setExpToDrop(this.random.nextInt(6) + 1);
62 88 + this.world.getServer().getPluginManager().callEvent(playerFishEvent);
63 89 +
64 90 + if (playerFishEvent.isCancelled()) {
65 91 + return 0;
66 92 + }
67 93 + // CraftBukkit end
68 94 double d0 = entityhuman.locX() - this.locX();
69 95 double d1 = entityhuman.locY() - this.locY();
70 96 double d2 = entityhuman.locZ() - this.locZ();
71 -@@ -412,7 +445,11 @@
97 +@@ -412,7 +453,11 @@
72 98
73 99 entityitem.setMot(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
74 100 this.world.addEntity(entityitem);
75 101 - entityhuman.world.addEntity(new EntityExperienceOrb(entityhuman.world, entityhuman.locX(), entityhuman.locY() + 0.5D, entityhuman.locZ() + 0.5D, this.random.nextInt(6) + 1));
76 102 + // CraftBukkit start - this.random.nextInt(6) + 1 -> playerFishEvent.getExpToDrop()
77 103 + if (playerFishEvent.getExpToDrop() > 0) {
78 104 + entityhuman.world.addEntity(new EntityExperienceOrb(entityhuman.world, entityhuman.locX(), entityhuman.locY() + 0.5D, entityhuman.locZ() + 0.5D, playerFishEvent.getExpToDrop()));
79 105 + }
80 106 + // CraftBukkit end
81 107 if (itemstack1.getItem().a((Tag) TagsItem.FISHES)) {
82 108 entityhuman.a(StatisticList.FISH_CAUGHT, 1);
83 109 }
84 -@@ -422,8 +459,25 @@
110 +@@ -422,8 +467,25 @@
85 111 }
86 112
87 113 if (this.onGround) {
88 114 + // CraftBukkit start
89 115 + PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.IN_GROUND);
90 116 + this.world.getServer().getPluginManager().callEvent(playerFishEvent);
91 117 +
92 118 + if (playerFishEvent.isCancelled()) {
93 119 + return 0;
94 120 + }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut