mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-10 03:52:45 +01:00
eed041d629
By: md_5 <git@md-5.net>
218 lines
10 KiB
Diff
218 lines
10 KiB
Diff
--- a/net/minecraft/world/entity/projectile/EntityFishingHook.java
|
|
+++ b/net/minecraft/world/entity/projectile/EntityFishingHook.java
|
|
@@ -47,6 +47,13 @@
|
|
import net.minecraft.world.phys.Vec3D;
|
|
import org.slf4j.Logger;
|
|
|
|
+// CraftBukkit start
|
|
+import org.bukkit.entity.Player;
|
|
+import org.bukkit.entity.FishHook;
|
|
+import org.bukkit.event.entity.EntityRemoveEvent;
|
|
+import org.bukkit.event.player.PlayerFishEvent;
|
|
+// CraftBukkit end
|
|
+
|
|
public class EntityFishingHook extends IProjectile {
|
|
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
@@ -68,6 +75,18 @@
|
|
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 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 EntityFishingHook(EntityTypes<? extends EntityFishingHook> entitytypes, World world, int i, int j) {
|
|
super(entitytypes, world);
|
|
this.syncronizedRandom = RandomSource.create();
|
|
@@ -148,12 +167,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 {
|
|
@@ -254,7 +273,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;
|
|
}
|
|
}
|
|
@@ -262,7 +281,7 @@
|
|
private void checkCollision() {
|
|
MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity);
|
|
|
|
- this.hitTargetOrDeflectSelf(movingobjectposition);
|
|
+ this.preHitTargetOrDeflectSelf(movingobjectposition); // CraftBukkit - projectile hit event
|
|
}
|
|
|
|
@Override
|
|
@@ -295,11 +314,11 @@
|
|
int i = 1;
|
|
BlockPosition blockposition1 = blockposition.above();
|
|
|
|
- if (this.random.nextFloat() < 0.25F && this.level().isRainingAt(blockposition1)) {
|
|
+ if (this.rainInfluenced && this.random.nextFloat() < 0.25F && this.level().isRainingAt(blockposition1)) { // CraftBukkit
|
|
++i;
|
|
}
|
|
|
|
- if (this.random.nextFloat() < 0.5F && !this.level().canSeeSky(blockposition1)) {
|
|
+ if (this.skyInfluenced && this.random.nextFloat() < 0.5F && !this.level().canSeeSky(blockposition1)) { // CraftBukkit
|
|
--i;
|
|
}
|
|
|
|
@@ -309,6 +328,10 @@
|
|
this.timeUntilLured = 0;
|
|
this.timeUntilHooked = 0;
|
|
this.getEntityData().set(EntityFishingHook.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;
|
|
@@ -342,6 +365,13 @@
|
|
worldserver.sendParticles(Particles.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(SoundEffects.FISHING_BOBBER_SPLASH, 0.25F, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
|
|
double d3 = this.getY() + 0.5D;
|
|
|
|
@@ -374,12 +404,16 @@
|
|
}
|
|
|
|
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
|
|
}
|
|
} else {
|
|
- this.timeUntilLured = MathHelper.nextInt(this.random, 100, 600);
|
|
- this.timeUntilLured -= this.lureSpeed;
|
|
+ // CraftBukkit start - logic to modify fishing wait time
|
|
+ this.timeUntilLured = MathHelper.nextInt(this.random, this.minWaitTime, this.maxWaitTime);
|
|
+ this.timeUntilLured -= (this.applyLure) ? this.lureSpeed : 0;
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
|
|
@@ -447,6 +481,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);
|
|
CriterionTriggers.FISHING_ROD_HOOKED.trigger((EntityPlayer) entityhuman, itemstack, this, Collections.emptyList());
|
|
this.level().broadcastEntityEvent(this, (byte) 31);
|
|
@@ -462,6 +504,15 @@
|
|
while (iterator.hasNext()) {
|
|
ItemStack itemstack1 = (ItemStack) iterator.next();
|
|
EntityItem entityitem = new EntityItem(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();
|
|
@@ -469,7 +520,11 @@
|
|
|
|
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));
|
|
+ // CraftBukkit start - this.random.nextInt(6) + 1 -> playerFishEvent.getExpToDrop()
|
|
+ if (playerFishEvent.getExpToDrop() > 0) {
|
|
+ entityhuman.level().addFreshEntity(new EntityExperienceOrb(entityhuman.level(), entityhuman.getX(), entityhuman.getY() + 0.5D, entityhuman.getZ() + 0.5D, playerFishEvent.getExpToDrop()));
|
|
+ }
|
|
+ // CraftBukkit end
|
|
if (itemstack1.is(TagsItem.FISHES)) {
|
|
entityhuman.awardStat(StatisticList.FISH_CAUGHT, 1);
|
|
}
|
|
@@ -479,10 +534,27 @@
|
|
}
|
|
|
|
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();
|
|
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
|
return i;
|
|
} else {
|
|
return 0;
|
|
@@ -515,8 +587,15 @@
|
|
|
|
@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
|