1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
--- a/net/minecraft/world/entity/projectile/FishingHook.java
+++ b/net/minecraft/world/entity/projectile/FishingHook.java
@@ -46,6 +45,12 @@
import net.minecraft.world.phys.Vec3;
import org.slf4j.Logger;
+// CraftBukkit start
+import org.bukkit.entity.Player;
+import org.bukkit.entity.FishHook;
+import org.bukkit.event.player.PlayerFishEvent;
+// CraftBukkit end
+
public class FishingHook extends Projectile {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -67,8 +72,20 @@
private final int luck;
private final int lureSpeed;
- private FishingHook(EntityType<? extends FishingHook> entitytype, Level level, int i, int j) {
- super(entitytype, level);
+ // CraftBukkit start - Extra variables to enable modification of fishing wait time, values are minecraft defaults
+ public int minWaitTime = 100;
+ public int maxWaitTime = 600;
+ public int minLureTime = 20;
+ public int maxLureTime = 80;
+ public float minLureAngle = 0.0F;
+ public float maxLureAngle = 360.0F;
+ public boolean applyLure = true;
+ public boolean rainInfluenced = true;
+ public boolean skyInfluenced = true;
+ // CraftBukkit end
+
+ private FishingHook(EntityType<? extends FishingHook> entityType, Level level, int luck, int lureSpeed) {
+ super(entityType, level);
this.syncronizedRandom = RandomSource.create();
this.openWater = true;
this.currentState = FishingHook.FishHookState.FLYING;
@@ -266,7 +278,7 @@
private void checkCollision() {
HitResult hitresult = ProjectileUtil.getHitResultOnMoveVector(this, this::canHitEntity);
- this.onHit(hitresult);
+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
}
@Override
@@ -302,11 +311,11 @@
int i = 1;
BlockPos blockpos1 = blockpos.above();
- if (this.random.nextFloat() < 0.25F && this.level().isRainingAt(blockpos1)) {
+ if (this.rainInfluenced && this.random.nextFloat() < 0.25F && this.level().isRainingAt(blockposition1)) { // CraftBukkit
++i;
}
- if (this.random.nextFloat() < 0.5F && !this.level().canSeeSky(blockpos1)) {
+ if (this.skyInfluenced && this.random.nextFloat() < 0.5F && !this.level().canSeeSky(blockposition1)) { // CraftBukkit
--i;
}
@@ -316,6 +325,10 @@
this.timeUntilLured = 0;
this.timeUntilHooked = 0;
this.getEntityData().set(FishingHook.DATA_BITING, false);
+ // CraftBukkit start
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.getPlayerOwner().getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT);
+ this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
+ // CraftBukkit end
}
} else {
float f;
@@ -349,6 +362,13 @@
serverlevel.sendParticles(ParticleTypes.FISHING, d0, d1, d2, 0, (double) (-f4), 0.01D, (double) f3, 1.0D);
}
} else {
+ // CraftBukkit start
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.getPlayerOwner().getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.BITE);
+ this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
+ if (playerFishEvent.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
this.playSound(SoundEvents.FISHING_BOBBER_SPLASH, 0.25F, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
double d3 = this.getY() + 0.5D;
@@ -381,12 +401,16 @@
}
if (this.timeUntilLured <= 0) {
- this.fishAngle = Mth.nextFloat(this.random, 0.0F, 360.0F);
- this.timeUntilHooked = Mth.nextInt(this.random, 20, 80);
+ // CraftBukkit start - logic to modify fishing wait time, lure time, and lure angle
+ this.fishAngle = Mth.nextFloat(this.random, this.minLureAngle, this.maxLureAngle);
+ this.timeUntilHooked = Mth.nextInt(this.random, this.minLureTime, this.maxLureTime);
+ // CraftBukkit end
}
} else {
- this.timeUntilLured = Mth.nextInt(this.random, 100, 600);
- this.timeUntilLured -= this.lureSpeed * 20 * 5;
+ // CraftBukkit start - logic to modify fishing wait time
+ this.timeUntilLured = Mth.nextInt(this.random, this.minWaitTime, this.maxWaitTime);
+ this.timeUntilLured -= (this.applyLure) ? this.lureSpeed * 20 * 5 : 0;
+ // CraftBukkit end
}
}
@@ -455,6 +477,14 @@
int i = 0;
if (this.hookedIn != null) {
+ // CraftBukkit start
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), this.hookedIn.getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY);
+ this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
+
+ if (playerFishEvent.isCancelled()) {
+ return 0;
+ }
+ // CraftBukkit end
this.pullEntity(this.hookedIn);
CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayer) player, itemstack, this, Collections.emptyList());
this.level().broadcastEntityEvent(this, (byte) 31);
@@ -469,15 +499,28 @@
while (iterator.hasNext()) {
ItemStack itemstack1 = (ItemStack) iterator.next();
- ItemEntity itementity = new ItemEntity(this.level(), this.getX(), this.getY(), this.getZ(), itemstack1);
- double d0 = player.getX() - this.getX();
- double d1 = player.getY() - this.getY();
- double d2 = player.getZ() - this.getZ();
+ ItemEntity entityitem = new ItemEntity(this.level(), this.getX(), this.getY(), this.getZ(), itemstack1);
+ // CraftBukkit start
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), entityitem.getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH);
+ playerFishEvent.setExpToDrop(this.random.nextInt(6) + 1);
+ this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
+
+ if (playerFishEvent.isCancelled()) {
+ return 0;
+ }
+ // CraftBukkit end
+ double d0 = entityhuman.getX() - this.getX();
+ double d1 = entityhuman.getY() - this.getY();
+ double d2 = entityhuman.getZ() - this.getZ();
double d3 = 0.1D;
- itementity.setDeltaMovement(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
- this.level().addFreshEntity(itementity);
- player.level().addFreshEntity(new ExperienceOrb(player.level(), player.getX(), player.getY() + 0.5D, player.getZ() + 0.5D, this.random.nextInt(6) + 1));
+ entityitem.setDeltaMovement(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
+ this.level().addFreshEntity(entityitem);
+ // CraftBukkit start - this.random.nextInt(6) + 1 -> playerFishEvent.getExpToDrop()
+ if (playerFishEvent.getExpToDrop() > 0) {
+ entityhuman.level().addFreshEntity(new ExperienceOrb(entityhuman.level(), entityhuman.getX(), entityhuman.getY() + 0.5D, entityhuman.getZ() + 0.5D, playerFishEvent.getExpToDrop()));
+ }
+ // CraftBukkit end
if (itemstack1.is(ItemTags.FISHES)) {
player.awardStat(Stats.FISH_CAUGHT, 1);
}
@@ -487,8 +530,25 @@
}
if (this.onGround()) {
+ // CraftBukkit start
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.IN_GROUND);
+ this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
+
+ if (playerFishEvent.isCancelled()) {
+ return 0;
+ }
+ // CraftBukkit end
i = 2;
}
+ // CraftBukkit start
+ if (i == 0) {
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.REEL_IN);
+ this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
+ if (playerFishEvent.isCancelled()) {
+ return 0;
+ }
+ }
+ // CraftBukkit end
this.discard();
return i;
|