mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 15:30:19 +01:00
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.
This commit is contained in:
parent
a888e73efa
commit
2786ee1e8f
4 changed files with 135 additions and 0 deletions
24
patches/api/Add-missing-fishing-event-state.patch
Normal file
24
patches/api/Add-missing-fishing-event-state.patch
Normal file
|
@ -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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/event/player/PlayerFishEvent.java
|
||||
+++ b/src/main/java/org/bukkit/event/player/PlayerFishEvent.java
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
}
|
||||
}
|
|
@ -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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
|
@ -205,6 +206,36 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ * @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
|
||||
|
|
26
patches/server/Add-missing-fishing-event-state.patch
Normal file
26
patches/server/Add-missing-fishing-event-state.patch
Normal file
|
@ -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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
@@ -0,0 +0,0 @@ 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
|
|
@ -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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
|
||||
|
@ -368,6 +395,33 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ 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
|
||||
|
|
Loading…
Reference in a new issue