Paper/patches/server/0428-Avoid-error-bubbling-up-when-item-stack-is-empty-in-.patch

47 lines
3.5 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Toon Schoenmakers <nighteyes1993@gmail.com>
Date: Fri, 23 Oct 2020 15:01:44 +0200
Subject: [PATCH] Avoid error bubbling up when item stack is empty in fishing
loot
This can realistically only happen if there's custom loot active on fishing
which can return 0 items. This would disconnect the player who's fishing.
diff --git a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
2024-06-13 22:57:13 +02:00
index 0b4c67b9de6893601f032a8fae103e8a98f2c767..5b7734020b496ade3740d92908ad2d399bfd55e6 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
2024-06-13 22:57:13 +02:00
@@ -506,9 +506,15 @@ public class FishingHook extends Projectile {
2021-06-11 14:02:28 +02:00
while (iterator.hasNext()) {
ItemStack itemstack1 = (ItemStack) iterator.next();
2023-06-08 01:44:11 +02:00
- ItemEntity entityitem = new ItemEntity(this.level(), this.getX(), this.getY(), this.getZ(), itemstack1);
2024-02-01 10:15:57 +01:00
+ // Paper start - new ItemEntity would throw if for whatever reason (mostly shitty datapacks) the itemstack1 turns out to be empty
2021-06-11 14:02:28 +02:00
+ // if the item stack is empty we instead just have our entityitem as null
+ ItemEntity entityitem = null;
+ if (!itemstack1.isEmpty()) {
2023-06-08 01:44:11 +02:00
+ entityitem = new ItemEntity(this.level(), this.getX(), this.getY(), this.getZ(), itemstack1);
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
// CraftBukkit start
- PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), entityitem.getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH);
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), entityitem != null ? entityitem.getBukkitEntity() : null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH); // Paper - entityitem may be null
playerFishEvent.setExpToDrop(this.random.nextInt(6) + 1);
2023-06-08 01:44:11 +02:00
this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
2021-06-11 14:02:28 +02:00
2024-06-13 22:57:13 +02:00
@@ -521,8 +527,12 @@ public class FishingHook extends Projectile {
2021-06-11 14:02:28 +02:00
double d2 = entityhuman.getZ() - this.getZ();
double d3 = 0.1D;
- 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-08 01:44:11 +02:00
- this.level().addFreshEntity(entityitem);
2024-02-01 10:15:57 +01:00
+ // Paper start - entity item can be null, so we need to check against this
2021-06-11 14:02:28 +02:00
+ if (entityitem != null) {
+ 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-08 01:44:11 +02:00
+ this.level().addFreshEntity(entityitem);
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
// CraftBukkit start - this.random.nextInt(6) + 1 -> playerFishEvent.getExpToDrop()
if (playerFishEvent.getExpToDrop() > 0) {
2023-06-08 01:44:11 +02:00
entityhuman.level().addFreshEntity(new ExperienceOrb(entityhuman.level(), entityhuman.getX(), entityhuman.getY() + 0.5D, entityhuman.getZ() + 0.5D, playerFishEvent.getExpToDrop(), org.bukkit.entity.ExperienceOrb.SpawnReason.FISHING, this.getPlayerOwner(), this)); // Paper