Extend fishing API (#10634)
Adds a missing fishing state when the fish is lured and fires an event for it. Also adds a way to control the fish swimming time towards the bobber.
Dieser Commit ist enthalten in:
Ursprung
efd91e52a6
Commit
27d2ed84f4
@ -4,6 +4,7 @@ Date: Wed, 26 May 2021 19:34:43 -0400
|
||||
Subject: [PATCH] More Projectile API
|
||||
|
||||
Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
|
||||
Co-authored-by: SoSeDiK <mrsosedik@gmail.com>
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/entity/AbstractArrow.java b/src/main/java/org/bukkit/entity/AbstractArrow.java
|
||||
index 839e5b7df49f42b5fec7729997bef3370ba36d80..b36298679d6d52d09fe4bb8e52e19e18f6df742a 100644
|
||||
@ -183,10 +184,10 @@ index 0d31aa0b22cf1e849572294e2cfe38b48c9210af..217d348ad0bbef720b25d3b507a55ca8
|
||||
+ // Paper end
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/entity/FishHook.java b/src/main/java/org/bukkit/entity/FishHook.java
|
||||
index 94e1a30ea1bc26821065a6d89c1f5669bd1d08ae..6ed83d3e4d23e0dc0e1b156a1ee221aaba5c7210 100644
|
||||
index 94e1a30ea1bc26821065a6d89c1f5669bd1d08ae..fe32fa569afd62300f7fdc29eefaba291f265674 100644
|
||||
--- a/src/main/java/org/bukkit/entity/FishHook.java
|
||||
+++ b/src/main/java/org/bukkit/entity/FishHook.java
|
||||
@@ -322,4 +322,20 @@ public interface FishHook extends Projectile {
|
||||
@@ -322,4 +322,50 @@ public interface FishHook extends Projectile {
|
||||
*/
|
||||
BOBBING;
|
||||
}
|
||||
@ -205,6 +206,36 @@ index 94e1a30ea1bc26821065a6d89c1f5669bd1d08ae..6ed83d3e4d23e0dc0e1b156a1ee221aa
|
||||
+ * @param ticks Number of ticks
|
||||
+ */
|
||||
+ void setWaitTime(int ticks);
|
||||
+
|
||||
+ /**
|
||||
+ * Get the number of ticks the fish has to swim until biting the hook.
|
||||
+ * The {@link #getWaitTime()} has to be zero or below for the fish to start the time until bite timer.
|
||||
+ *
|
||||
+ * @return number of ticks.
|
||||
+ * A value of one indicates that the fish bites the very next time the fish hook is ticked
|
||||
+ * while a value of zero represents a fish that has already bitten the hook.
|
||||
+ * @see #getWaitTime()
|
||||
+ */
|
||||
+ @org.jetbrains.annotations.Range(from = 0, to = Integer.MAX_VALUE)
|
||||
+ int getTimeUntilBite();
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the number of ticks the fish has to swim until biting the hook.
|
||||
+ *
|
||||
+ * @param ticks number of ticks.
|
||||
+ * One is the minimum that can be passed to this method and instructs the fish to bite the very next tick.
|
||||
+ * @throws IllegalArgumentException if the passed tick value is less than one.
|
||||
+ */
|
||||
+ void setTimeUntilBite(@org.jetbrains.annotations.Range(from = 1, to = Integer.MAX_VALUE) int ticks) throws IllegalArgumentException;
|
||||
+
|
||||
+ /**
|
||||
+ * Completely resets this fishing hook's fishing state, re-randomizing the time needed until a fish is lured and
|
||||
+ * bites the hook.
|
||||
+ * <p>
|
||||
+ * This method takes all properties of the fishing hook into account when resetting said values, such as a lure
|
||||
+ * enchantment.
|
||||
+ */
|
||||
+ void resetFishingState();
|
||||
+ // Paper end
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/entity/Projectile.java b/src/main/java/org/bukkit/entity/Projectile.java
|
||||
|
24
patches/api/0482-Add-missing-fishing-event-state.patch
Normale Datei
24
patches/api/0482-Add-missing-fishing-event-state.patch
Normale Datei
@ -0,0 +1,24 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: SoSeDiK <mrsosedik@gmail.com>
|
||||
Date: Wed, 1 May 2024 07:44:50 +0300
|
||||
Subject: [PATCH] Add missing fishing event state
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/event/player/PlayerFishEvent.java b/src/main/java/org/bukkit/event/player/PlayerFishEvent.java
|
||||
index d4001f64a7ee9d5173e9bafd9c45860cbda1fc85..8b4ad421700f859396291508b178af9b51f23b0a 100644
|
||||
--- a/src/main/java/org/bukkit/event/player/PlayerFishEvent.java
|
||||
+++ b/src/main/java/org/bukkit/event/player/PlayerFishEvent.java
|
||||
@@ -165,5 +165,13 @@ public class PlayerFishEvent extends PlayerEvent implements Cancellable {
|
||||
* in.
|
||||
*/
|
||||
BITE
|
||||
+ // Paper start - Add missing fishing event state
|
||||
+ ,
|
||||
+ /**
|
||||
+ * Called when a bobber was lured, and is now waiting to be hooked
|
||||
+ * (when a "fish" starts to swim toward the bobber to bite it).
|
||||
+ */
|
||||
+ LURED,
|
||||
+ // Paper end - Add missing fishing event state
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ Subject: [PATCH] More Projectile API
|
||||
|
||||
== AT ==
|
||||
public net.minecraft.world.entity.projectile.FishingHook timeUntilLured
|
||||
public net.minecraft.world.entity.projectile.FishingHook fishAngle
|
||||
public net.minecraft.world.entity.projectile.ShulkerBullet targetDeltaX
|
||||
public net.minecraft.world.entity.projectile.ShulkerBullet targetDeltaY
|
||||
public net.minecraft.world.entity.projectile.ShulkerBullet targetDeltaZ
|
||||
@ -19,7 +20,33 @@ public net.minecraft.world.entity.projectile.Projectile canHitEntity(Lnet/minecr
|
||||
public net.minecraft.world.entity.projectile.FireworkRocketEntity getDefaultItem()Lnet/minecraft/world/item/ItemStack;
|
||||
|
||||
Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
|
||||
Co-authored-by: SoSeDiK <mrsosedik@gmail.com>
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
index 7d557c7ec6fb1763395f4920a170bd4e4ba6747f..e603307871b623ce437f4b1b68ab306fbdd9919d 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
@@ -413,13 +413,18 @@ public class FishingHook extends Projectile {
|
||||
}
|
||||
} else {
|
||||
// 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 >= this.maxWaitTime ? this.timeUntilLured - 1 : this.lureSpeed * 20 * 5) : 0; // Paper - Fix Lure infinite loop
|
||||
+ resetTimeUntilLured(); // Paper - more projectile api - extract time until lured reset logic
|
||||
// CraftBukkit end
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+ // Paper start - more projectile api - extract time until lured reset logic
|
||||
+ public void resetTimeUntilLured() {
|
||||
+ this.timeUntilLured = Mth.nextInt(this.random, this.minWaitTime, this.maxWaitTime);
|
||||
+ this.timeUntilLured -= (this.applyLure) ? (this.lureSpeed * 20 * 5 >= this.maxWaitTime ? this.timeUntilLured - 1 : this.lureSpeed * 20 * 5) : 0; // Paper - Fix Lure infinite loop
|
||||
+ }
|
||||
+ // Paper end - more projectile api - extract time until lured reset logic
|
||||
|
||||
public boolean calculateOpenWater(BlockPos pos) {
|
||||
FishingHook.OpenWaterType entityfishinghook_waterposition = FishingHook.OpenWaterType.INVALID;
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
|
||||
index 40348e45b02be9a0b397a883940a476fb6738ef4..ccb7aa341e3087255bce1f6fb953d33584147fd3 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
|
||||
@ -351,10 +378,10 @@ index c9e15a9d82dee935293b2e7e233f5b9b2d822448..3c31ff72f3e77ee0d9231fec5f15267c
|
||||
+ // Paper end - Expose firework item directly + manually setting flight
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java
|
||||
index 6e2f91423371ead9890095cf4b1e2299c4dcba28..ad1aeea80877f2cdb9e8ad9c5b46f95dd76b3335 100644
|
||||
index 6e2f91423371ead9890095cf4b1e2299c4dcba28..9d8f4b7176e60180565e3134a14ecf19060f2621 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java
|
||||
@@ -196,4 +196,15 @@ public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
@@ -196,4 +196,42 @@ public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
public HookState getState() {
|
||||
return HookState.values()[this.getHandle().currentState.ordinal()];
|
||||
}
|
||||
@ -368,6 +395,33 @@ index 6e2f91423371ead9890095cf4b1e2299c4dcba28..ad1aeea80877f2cdb9e8ad9c5b46f95d
|
||||
+ public void setWaitTime(int ticks) {
|
||||
+ this.getHandle().timeUntilLured = ticks;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int getTimeUntilBite() {
|
||||
+ return this.getHandle().timeUntilHooked;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setTimeUntilBite(final int ticks) {
|
||||
+ com.google.common.base.Preconditions.checkArgument(ticks >= 1, "Cannot set time until bite to less than 1 (%s<1)", ticks);
|
||||
+ final FishingHook hook = this.getHandle();
|
||||
+
|
||||
+ // Reset the fish angle hook only when this call "enters" the fish into the lure stage.
|
||||
+ final boolean alreadyInLuringPhase = hook.timeUntilHooked > 0 && hook.timeUntilLured <= 0;
|
||||
+ if (!alreadyInLuringPhase) {
|
||||
+ hook.fishAngle = net.minecraft.util.Mth.nextFloat(hook.random, hook.minLureAngle, hook.maxLureAngle);
|
||||
+ hook.timeUntilLured = 0;
|
||||
+ }
|
||||
+
|
||||
+ hook.timeUntilHooked = ticks;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void resetFishingState() {
|
||||
+ final FishingHook hook = this.getHandle();
|
||||
+ hook.resetTimeUntilLured();
|
||||
+ hook.timeUntilHooked = 0; // Reset time until hooked, will be repopulated once lured time is ticked down.
|
||||
+ }
|
||||
+ // Paper end
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
||||
|
@ -13,7 +13,7 @@ public net.minecraft.world.entity.projectile.FishingHook calculateOpenWater(Lnet
|
||||
public net.minecraft.world.entity.projectile.FishingHook outOfWaterTime
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java
|
||||
index ad1aeea80877f2cdb9e8ad9c5b46f95dd76b3335..116f23a3ee9fa409d7bc34c3769b94ed2bb07183 100644
|
||||
index 9d8f4b7176e60180565e3134a14ecf19060f2621..e0d65df2e5b4c14abeb89a5f72cc2d9fa034dcf5 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java
|
||||
@@ -164,7 +164,7 @@ public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
|
@ -5,10 +5,10 @@ Subject: [PATCH] Add hand to fish event for all player interactions
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
index a9ea83ea03ab23abc1eb463dadcdd742bfa20036..35299affb699d745804a3b60cb78b9323f3e068e 100644
|
||||
index e603307871b623ce437f4b1b68ab306fbdd9919d..9962d50ea342cd47428a814519b2d54f547753a4 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
@@ -476,7 +476,15 @@ public class FishingHook extends Projectile {
|
||||
@@ -481,7 +481,15 @@ public class FishingHook extends Projectile {
|
||||
@Override
|
||||
public void readAdditionalSaveData(CompoundTag nbt) {}
|
||||
|
||||
@ -24,7 +24,7 @@ index a9ea83ea03ab23abc1eb463dadcdd742bfa20036..35299affb699d745804a3b60cb78b932
|
||||
net.minecraft.world.entity.player.Player entityhuman = this.getPlayerOwner();
|
||||
|
||||
if (!this.level().isClientSide && entityhuman != null && !this.shouldStopFishing(entityhuman)) {
|
||||
@@ -484,7 +492,7 @@ public class FishingHook extends Projectile {
|
||||
@@ -489,7 +497,7 @@ public class FishingHook extends Projectile {
|
||||
|
||||
if (this.hookedIn != null) {
|
||||
// CraftBukkit start
|
||||
@ -33,7 +33,7 @@ index a9ea83ea03ab23abc1eb463dadcdd742bfa20036..35299affb699d745804a3b60cb78b932
|
||||
this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
|
||||
|
||||
if (playerFishEvent.isCancelled()) {
|
||||
@@ -513,7 +521,7 @@ public class FishingHook extends Projectile {
|
||||
@@ -518,7 +526,7 @@ public class FishingHook extends Projectile {
|
||||
}
|
||||
// Paper end
|
||||
// CraftBukkit start
|
||||
@ -42,7 +42,7 @@ index a9ea83ea03ab23abc1eb463dadcdd742bfa20036..35299affb699d745804a3b60cb78b932
|
||||
playerFishEvent.setExpToDrop(this.random.nextInt(6) + 1);
|
||||
this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
|
||||
|
||||
@@ -547,7 +555,7 @@ public class FishingHook extends Projectile {
|
||||
@@ -552,7 +560,7 @@ public class FishingHook extends Projectile {
|
||||
|
||||
if (this.onGround()) {
|
||||
// CraftBukkit start
|
||||
@ -51,7 +51,7 @@ index a9ea83ea03ab23abc1eb463dadcdd742bfa20036..35299affb699d745804a3b60cb78b932
|
||||
this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
|
||||
|
||||
if (playerFishEvent.isCancelled()) {
|
||||
@@ -558,7 +566,7 @@ public class FishingHook extends Projectile {
|
||||
@@ -563,7 +571,7 @@ public class FishingHook extends Projectile {
|
||||
}
|
||||
// CraftBukkit start
|
||||
if (i == 0) {
|
||||
|
@ -5,10 +5,10 @@ Subject: [PATCH] Prevent NPE if hooked entity was cleared
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
index 35299affb699d745804a3b60cb78b9323f3e068e..882de08963c72614a3d26cd917916e42b7136042 100644
|
||||
index 9962d50ea342cd47428a814519b2d54f547753a4..6ea34a76707d9f60076b7423ac0bb1de200308ae 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
@@ -498,11 +498,13 @@ public class FishingHook extends Projectile {
|
||||
@@ -503,11 +503,13 @@ public class FishingHook extends Projectile {
|
||||
if (playerFishEvent.isCancelled()) {
|
||||
return 0;
|
||||
}
|
||||
|
26
patches/server/1050-Add-missing-fishing-event-state.patch
Normale Datei
26
patches/server/1050-Add-missing-fishing-event-state.patch
Normale Datei
@ -0,0 +1,26 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: SoSeDiK <mrsosedik@gmail.com>
|
||||
Date: Wed, 1 May 2024 07:44:50 +0300
|
||||
Subject: [PATCH] Add missing fishing event state
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
index 6ea34a76707d9f60076b7423ac0bb1de200308ae..7dd5e0b935d98d552c916f8412569ff4aa0e9b04 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
@@ -410,6 +410,15 @@ public class FishingHook extends Projectile {
|
||||
this.fishAngle = Mth.nextFloat(this.random, this.minLureAngle, this.maxLureAngle);
|
||||
this.timeUntilHooked = Mth.nextInt(this.random, this.minLureTime, this.maxLureTime);
|
||||
// CraftBukkit end
|
||||
+ // Paper start - Add missing fishing event state
|
||||
+ if (this.getPlayerOwner() != null) {
|
||||
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.getPlayerOwner().getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.LURED);
|
||||
+ if (!playerFishEvent.callEvent()) {
|
||||
+ this.timeUntilHooked = 0;
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+ // Paper end - Add missing fishing event state
|
||||
}
|
||||
} else {
|
||||
// CraftBukkit start - logic to modify fishing wait time
|
In neuem Issue referenzieren
Einen Benutzer sperren