2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/entity/projectile/EntityFishingHook.java
|
|
|
|
+++ b/net/minecraft/world/entity/projectile/EntityFishingHook.java
|
2024-02-21 10:55:34 +01:00
|
|
|
@@ -46,6 +46,13 @@
|
2021-03-15 23:00:00 +01:00
|
|
|
import net.minecraft.world.phys.Vec3D;
|
2022-02-28 16:00:00 +01:00
|
|
|
import org.slf4j.Logger;
|
2021-03-08 22:47:33 +01:00
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
+// CraftBukkit start
|
|
|
|
+import org.bukkit.entity.Player;
|
2018-07-15 02:00:00 +02:00
|
|
|
+import org.bukkit.entity.FishHook;
|
2024-02-21 10:55:34 +01:00
|
|
|
+import org.bukkit.event.entity.EntityRemoveEvent;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.event.player.PlayerFishEvent;
|
|
|
|
+// CraftBukkit end
|
2021-03-08 22:47:33 +01:00
|
|
|
+
|
2020-06-25 02:00:00 +02:00
|
|
|
public class EntityFishingHook extends IProjectile {
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2022-02-28 16:00:00 +01:00
|
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
2024-02-21 10:55:34 +01:00
|
|
|
@@ -67,6 +74,18 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
private final int luck;
|
|
|
|
private final int lureSpeed;
|
2020-11-06 08:49:15 +01:00
|
|
|
|
|
|
|
+ // CraftBukkit start - Extra variables to enable modification of fishing wait time, values are minecraft defaults
|
|
|
|
+ public int minWaitTime = 100;
|
|
|
|
+ public int maxWaitTime = 600;
|
2023-04-16 02:10:27 +02:00
|
|
|
+ public int minLureTime = 20;
|
|
|
|
+ public int maxLureTime = 80;
|
|
|
|
+ public float minLureAngle = 0.0F;
|
|
|
|
+ public float maxLureAngle = 360.0F;
|
2020-11-06 08:49:15 +01:00
|
|
|
+ public boolean applyLure = true;
|
2023-04-16 02:10:27 +02:00
|
|
|
+ public boolean rainInfluenced = true;
|
|
|
|
+ public boolean skyInfluenced = true;
|
2020-11-06 08:49:15 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
+
|
2021-06-11 07:00:00 +02:00
|
|
|
private EntityFishingHook(EntityTypes<? extends EntityFishingHook> entitytypes, World world, int i, int j) {
|
|
|
|
super(entitytypes, world);
|
2022-06-07 18:00:00 +02:00
|
|
|
this.syncronizedRandom = RandomSource.create();
|
2024-02-21 10:55:34 +01:00
|
|
|
@@ -147,12 +166,12 @@
|
|
|
|
EntityHuman entityhuman = this.getPlayerOwner();
|
|
|
|
|
|
|
|
if (entityhuman == null) {
|
|
|
|
- this.discard();
|
|
|
|
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
|
|
|
} else if (this.level().isClientSide || !this.shouldStopFishing(entityhuman)) {
|
|
|
|
if (this.onGround()) {
|
|
|
|
++this.life;
|
|
|
|
if (this.life >= 1200) {
|
|
|
|
- this.discard();
|
|
|
|
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
@@ -253,7 +272,7 @@
|
|
|
|
if (!entityhuman.isRemoved() && entityhuman.isAlive() && (flag || flag1) && this.distanceToSqr((Entity) entityhuman) <= 1024.0D) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
- this.discard();
|
|
|
|
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -261,7 +280,7 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
private void checkCollision() {
|
2023-06-07 17:30:00 +02:00
|
|
|
MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity);
|
2021-05-09 08:51:44 +02:00
|
|
|
|
2024-04-23 17:15:00 +02:00
|
|
|
- this.hitTargetOrDeflectSelf(movingobjectposition);
|
|
|
|
+ this.preHitTargetOrDeflectSelf(movingobjectposition); // CraftBukkit - projectile hit event
|
2021-05-09 08:51:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-02-21 10:55:34 +01:00
|
|
|
@@ -294,11 +313,11 @@
|
2023-04-16 02:10:27 +02:00
|
|
|
int i = 1;
|
|
|
|
BlockPosition blockposition1 = blockposition.above();
|
|
|
|
|
2023-06-07 17:30:00 +02:00
|
|
|
- if (this.random.nextFloat() < 0.25F && this.level().isRainingAt(blockposition1)) {
|
|
|
|
+ if (this.rainInfluenced && this.random.nextFloat() < 0.25F && this.level().isRainingAt(blockposition1)) { // CraftBukkit
|
2023-04-16 02:10:27 +02:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2023-06-07 17:30:00 +02:00
|
|
|
- if (this.random.nextFloat() < 0.5F && !this.level().canSeeSky(blockposition1)) {
|
|
|
|
+ if (this.skyInfluenced && this.random.nextFloat() < 0.5F && !this.level().canSeeSky(blockposition1)) { // CraftBukkit
|
2023-04-16 02:10:27 +02:00
|
|
|
--i;
|
|
|
|
}
|
|
|
|
|
2024-02-21 10:55:34 +01:00
|
|
|
@@ -308,6 +327,10 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
this.timeUntilLured = 0;
|
|
|
|
this.timeUntilHooked = 0;
|
2021-11-21 23:00:00 +01:00
|
|
|
this.getEntityData().set(EntityFishingHook.DATA_BITING, false);
|
2016-11-17 02:41:03 +01:00
|
|
|
+ // CraftBukkit start
|
2021-11-21 23:00:00 +01:00
|
|
|
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.getPlayerOwner().getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT);
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
|
2016-11-17 02:41:03 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
2020-06-25 02:00:00 +02:00
|
|
|
} else {
|
|
|
|
float f;
|
2024-02-21 10:55:34 +01:00
|
|
|
@@ -341,6 +364,13 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
worldserver.sendParticles(Particles.FISHING, d0, d1, d2, 0, (double) (-f4), 0.01D, (double) f3, 1.0D);
|
2016-11-17 02:41:03 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
+ // CraftBukkit start
|
2021-11-21 23:00:00 +01:00
|
|
|
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.getPlayerOwner().getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.BITE);
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
|
2016-11-17 02:41:03 +01:00
|
|
|
+ if (playerFishEvent.isCancelled()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2021-06-11 07:00:00 +02:00
|
|
|
this.playSound(SoundEffects.FISHING_BOBBER_SPLASH, 0.25F, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
|
2021-11-21 23:00:00 +01:00
|
|
|
double d3 = this.getY() + 0.5D;
|
2019-04-23 04:00:00 +02:00
|
|
|
|
2024-02-21 10:55:34 +01:00
|
|
|
@@ -373,12 +403,16 @@
|
2023-04-16 02:10:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.timeUntilLured <= 0) {
|
|
|
|
- this.fishAngle = MathHelper.nextFloat(this.random, 0.0F, 360.0F);
|
|
|
|
- this.timeUntilHooked = MathHelper.nextInt(this.random, 20, 80);
|
|
|
|
+ // CraftBukkit start - logic to modify fishing wait time, lure time, and lure angle
|
|
|
|
+ this.fishAngle = MathHelper.nextFloat(this.random, this.minLureAngle, this.maxLureAngle);
|
|
|
|
+ this.timeUntilHooked = MathHelper.nextInt(this.random, this.minLureTime, this.maxLureTime);
|
|
|
|
+ // CraftBukkit end
|
2020-11-06 08:49:15 +01:00
|
|
|
}
|
|
|
|
} else {
|
2021-06-11 07:00:00 +02:00
|
|
|
- this.timeUntilLured = MathHelper.nextInt(this.random, 100, 600);
|
|
|
|
- this.timeUntilLured -= this.lureSpeed * 20 * 5;
|
2020-11-06 08:49:15 +01:00
|
|
|
+ // CraftBukkit start - logic to modify fishing wait time
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.timeUntilLured = MathHelper.nextInt(this.random, this.minWaitTime, this.maxWaitTime);
|
|
|
|
+ this.timeUntilLured -= (this.applyLure) ? this.lureSpeed * 20 * 5 : 0;
|
2020-11-06 08:49:15 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -446,6 +480,14 @@
|
2016-03-15 14:26:45 +01:00
|
|
|
int i = 0;
|
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
if (this.hookedIn != null) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start
|
2021-06-11 07:00:00 +02:00
|
|
|
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), this.hookedIn.getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY);
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
|
|
|
+ if (playerFishEvent.isCancelled()) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
this.pullEntity(this.hookedIn);
|
|
|
|
CriterionTriggers.FISHING_ROD_HOOKED.trigger((EntityPlayer) entityhuman, itemstack, this, Collections.emptyList());
|
2023-06-07 17:30:00 +02:00
|
|
|
this.level().broadcastEntityEvent(this, (byte) 31);
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -461,6 +503,15 @@
|
2016-02-29 22:32:46 +01:00
|
|
|
while (iterator.hasNext()) {
|
2018-07-15 02:00:00 +02:00
|
|
|
ItemStack itemstack1 = (ItemStack) iterator.next();
|
2023-06-07 17:30:00 +02:00
|
|
|
EntityItem entityitem = new EntityItem(this.level(), this.getX(), this.getY(), this.getZ(), itemstack1);
|
2016-02-29 22:32:46 +01:00
|
|
|
+ // CraftBukkit start
|
2020-06-25 02:00:00 +02:00
|
|
|
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), entityitem.getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH);
|
2016-02-29 22:32:46 +01:00
|
|
|
+ playerFishEvent.setExpToDrop(this.random.nextInt(6) + 1);
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ if (playerFishEvent.isCancelled()) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
double d0 = entityhuman.getX() - this.getX();
|
|
|
|
double d1 = entityhuman.getY() - this.getY();
|
|
|
|
double d2 = entityhuman.getZ() - this.getZ();
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -468,7 +519,11 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
entityitem.setDeltaMovement(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
|
2023-06-07 17:30:00 +02:00
|
|
|
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-02-29 22:32:46 +01:00
|
|
|
+ // CraftBukkit start - this.random.nextInt(6) + 1 -> playerFishEvent.getExpToDrop()
|
|
|
|
+ if (playerFishEvent.getExpToDrop() > 0) {
|
2023-06-07 17:30:00 +02:00
|
|
|
+ entityhuman.level().addFreshEntity(new EntityExperienceOrb(entityhuman.level(), entityhuman.getX(), entityhuman.getY() + 0.5D, entityhuman.getZ() + 0.5D, playerFishEvent.getExpToDrop()));
|
2016-02-29 22:32:46 +01:00
|
|
|
+ }
|
2016-11-17 02:41:03 +01:00
|
|
|
+ // CraftBukkit end
|
2022-02-28 16:00:00 +01:00
|
|
|
if (itemstack1.is(TagsItem.FISHES)) {
|
2021-11-21 23:00:00 +01:00
|
|
|
entityhuman.awardStat(StatisticList.FISH_CAUGHT, 1);
|
2018-07-15 02:00:00 +02:00
|
|
|
}
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -478,10 +533,27 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2023-06-07 17:30:00 +02:00
|
|
|
if (this.onGround()) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start
|
2020-06-25 02:00:00 +02:00
|
|
|
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.IN_GROUND);
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
|
|
|
+ if (playerFishEvent.isCancelled()) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2016-02-29 22:32:46 +01:00
|
|
|
i = 2;
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
2016-03-05 05:46:56 +01:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ if (i == 0) {
|
2020-06-25 02:00:00 +02:00
|
|
|
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.REEL_IN);
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
|
2016-03-05 05:46:56 +01:00
|
|
|
+ if (playerFishEvent.isCancelled()) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2024-02-21 10:55:34 +01:00
|
|
|
- this.discard();
|
|
|
|
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
2016-11-17 02:41:03 +01:00
|
|
|
return i;
|
2024-02-21 10:55:34 +01:00
|
|
|
} else {
|
|
|
|
return 0;
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -514,8 +586,15 @@
|
2024-02-21 10:55:34 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remove(Entity.RemovalReason entity_removalreason) {
|
|
|
|
+ // CraftBukkit start - add Bukkit remove cause
|
|
|
|
+ this.remove(entity_removalreason, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void remove(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) {
|
|
|
|
+ // CraftBukkit end
|
|
|
|
this.updateOwnerInfo((EntityFishingHook) null);
|
|
|
|
- super.remove(entity_removalreason);
|
|
|
|
+ super.remove(entity_removalreason, cause); // CraftBukkit - add Bukkit remove cause
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|