craftbukkit/nms-patches/net/minecraft/world/entity/projectile/EntityFishingHook.patch

146 lines
7.3 KiB
Diff
Raw Normal View History

2021-03-16 09:00:00 +11:00
--- a/net/minecraft/world/entity/projectile/EntityFishingHook.java
+++ b/net/minecraft/world/entity/projectile/EntityFishingHook.java
2022-03-01 02:00:00 +11:00
@@ -45,6 +45,12 @@
2021-03-16 09:00:00 +11:00
import net.minecraft.world.phys.Vec3D;
2022-03-01 02:00:00 +11:00
import org.slf4j.Logger;
2021-03-09 08:47:33 +11:00
+// CraftBukkit start
+import org.bukkit.entity.Player;
2018-07-15 10:00:00 +10:00
+import org.bukkit.entity.FishHook;
+import org.bukkit.event.player.PlayerFishEvent;
+// CraftBukkit end
2021-03-09 08:47:33 +11:00
+
2020-06-25 10:00:00 +10:00
public class EntityFishingHook extends IProjectile {
2022-03-01 02:00:00 +11:00
private static final Logger LOGGER = LogUtils.getLogger();
@@ -66,6 +72,12 @@
2021-06-11 15:00:00 +10:00
private final int luck;
private final int lureSpeed;
+ // CraftBukkit start - Extra variables to enable modification of fishing wait time, values are minecraft defaults
+ public int minWaitTime = 100;
+ public int maxWaitTime = 600;
+ public boolean applyLure = true;
+ // CraftBukkit end
+
2021-06-11 15:00:00 +10:00
private EntityFishingHook(EntityTypes<? extends EntityFishingHook> entitytypes, World world, int i, int j) {
super(entitytypes, world);
this.syncronizedRandom = new Random();
2022-03-01 02:00:00 +11:00
@@ -260,7 +272,7 @@
2021-11-22 09:00:00 +11:00
private void checkCollision() {
MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResult(this, this::canHitEntity);
2021-11-22 09:00:00 +11:00
- this.onHit(movingobjectposition);
+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
}
@Override
2022-03-01 02:00:00 +11:00
@@ -307,6 +319,10 @@
2021-06-11 15:00:00 +10:00
this.timeUntilLured = 0;
this.timeUntilHooked = 0;
2021-11-22 09:00:00 +11:00
this.getEntityData().set(EntityFishingHook.DATA_BITING, false);
2016-11-17 12:41:03 +11:00
+ // CraftBukkit start
2021-11-22 09:00:00 +11:00
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.getPlayerOwner().getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT);
+ this.level.getCraftServer().getPluginManager().callEvent(playerFishEvent);
2016-11-17 12:41:03 +11:00
+ // CraftBukkit end
}
2020-06-25 10:00:00 +10:00
} else {
float f;
2022-03-01 02:00:00 +11:00
@@ -340,6 +356,13 @@
2021-11-22 09:00:00 +11:00
worldserver.sendParticles(Particles.FISHING, d0, d1, d2, 0, (double) (-f4), 0.01D, (double) f3, 1.0D);
2016-11-17 12:41:03 +11:00
}
} else {
+ // CraftBukkit start
2021-11-22 09:00:00 +11:00
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.getPlayerOwner().getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.BITE);
+ this.level.getCraftServer().getPluginManager().callEvent(playerFishEvent);
2016-11-17 12:41:03 +11:00
+ if (playerFishEvent.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
2021-06-11 15:00:00 +10:00
this.playSound(SoundEffects.FISHING_BOBBER_SPLASH, 0.25F, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
2021-11-22 09:00:00 +11:00
double d3 = this.getY() + 0.5D;
2019-04-23 12:00:00 +10:00
2022-03-01 02:00:00 +11:00
@@ -376,8 +399,10 @@
2021-06-11 15:00:00 +10:00
this.timeUntilHooked = MathHelper.nextInt(this.random, 20, 80);
}
} else {
2021-06-11 15:00:00 +10:00
- this.timeUntilLured = MathHelper.nextInt(this.random, 100, 600);
- this.timeUntilLured -= this.lureSpeed * 20 * 5;
+ // CraftBukkit start - logic to modify fishing wait time
2021-06-11 15:00:00 +10:00
+ this.timeUntilLured = MathHelper.nextInt(this.random, this.minWaitTime, this.maxWaitTime);
+ this.timeUntilLured -= (this.applyLure) ? this.lureSpeed * 20 * 5 : 0;
+ // CraftBukkit end
}
}
2022-03-01 02:00:00 +11:00
@@ -444,6 +469,14 @@
int i = 0;
2021-06-11 15:00:00 +10:00
if (this.hookedIn != null) {
+ // CraftBukkit start
2021-06-11 15:00:00 +10:00
+ 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
2021-11-22 09:00:00 +11:00
this.pullEntity(this.hookedIn);
CriterionTriggers.FISHING_ROD_HOOKED.trigger((EntityPlayer) entityhuman, itemstack, this, Collections.emptyList());
this.level.broadcastEntityEvent(this, (byte) 31);
2022-03-01 02:00:00 +11:00
@@ -459,6 +492,15 @@
2016-03-01 08:32:46 +11:00
while (iterator.hasNext()) {
2018-07-15 10:00:00 +10:00
ItemStack itemstack1 = (ItemStack) iterator.next();
2021-11-22 09:00:00 +11:00
EntityItem entityitem = new EntityItem(this.level, this.getX(), this.getY(), this.getZ(), itemstack1);
2016-03-01 08:32:46 +11:00
+ // CraftBukkit start
2020-06-25 10:00:00 +10:00
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), entityitem.getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH);
2016-03-01 08:32:46 +11:00
+ playerFishEvent.setExpToDrop(this.random.nextInt(6) + 1);
+ this.level.getCraftServer().getPluginManager().callEvent(playerFishEvent);
+
2016-03-01 08:32:46 +11:00
+ if (playerFishEvent.isCancelled()) {
+ return 0;
+ }
+ // CraftBukkit end
2021-11-22 09:00:00 +11:00
double d0 = entityhuman.getX() - this.getX();
double d1 = entityhuman.getY() - this.getY();
double d2 = entityhuman.getZ() - this.getZ();
2022-03-01 02:00:00 +11:00
@@ -466,7 +508,11 @@
2019-04-23 12:00:00 +10:00
2021-11-22 09:00:00 +11:00
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);
- entityhuman.level.addFreshEntity(new EntityExperienceOrb(entityhuman.level, entityhuman.getX(), entityhuman.getY() + 0.5D, entityhuman.getZ() + 0.5D, this.random.nextInt(6) + 1));
2016-03-01 08:32:46 +11:00
+ // CraftBukkit start - this.random.nextInt(6) + 1 -> playerFishEvent.getExpToDrop()
+ if (playerFishEvent.getExpToDrop() > 0) {
2021-11-22 09:00:00 +11:00
+ entityhuman.level.addFreshEntity(new EntityExperienceOrb(entityhuman.level, entityhuman.getX(), entityhuman.getY() + 0.5D, entityhuman.getZ() + 0.5D, playerFishEvent.getExpToDrop()));
2016-03-01 08:32:46 +11:00
+ }
2016-11-17 12:41:03 +11:00
+ // CraftBukkit end
2022-03-01 02:00:00 +11:00
if (itemstack1.is(TagsItem.FISHES)) {
2021-11-22 09:00:00 +11:00
entityhuman.awardStat(StatisticList.FISH_CAUGHT, 1);
2018-07-15 10:00:00 +10:00
}
2022-03-01 02:00:00 +11:00
@@ -476,8 +522,25 @@
}
2020-06-25 10:00:00 +10:00
if (this.onGround) {
+ // CraftBukkit start
2020-06-25 10:00:00 +10:00
+ 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
2016-03-01 08:32:46 +11:00
i = 2;
}
+ // CraftBukkit start
+ if (i == 0) {
2020-06-25 10:00:00 +10:00
+ 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
2015-02-26 22:41:06 +00:00
2021-11-22 09:00:00 +11:00
this.discard();
2016-11-17 12:41:03 +11:00
return i;