From 28c4b7531fd0da8228d4bd281989c5c5974f216d Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 15 Mar 2023 18:14:15 +1100 Subject: [PATCH] Fix crash with juke boxes By: md_5 --- .../block/entity/TileEntityJukeBox.patch | 68 +++++++++++++++++++ .../block/entity/TileEntityLectern.patch | 13 ++-- 2 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityJukeBox.patch diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityJukeBox.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityJukeBox.patch new file mode 100644 index 0000000000..d626e46353 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityJukeBox.patch @@ -0,0 +1,68 @@ +--- a/net/minecraft/world/level/block/entity/TileEntityJukeBox.java ++++ b/net/minecraft/world/level/block/entity/TileEntityJukeBox.java +@@ -24,6 +24,13 @@ + import net.minecraft.world.phys.Vec3D; + import net.minecraft.world.ticks.ContainerSingleItem; + ++// CraftBukkit start ++import java.util.List; ++import org.bukkit.Location; ++import org.bukkit.craftbukkit.entity.CraftHumanEntity; ++import org.bukkit.entity.HumanEntity; ++// CraftBukkit end ++ + public class TileEntityJukeBox extends TileEntity implements Clearable, ContainerSingleItem { + + private static final int SONG_END_PADDING = 20; +@@ -32,6 +39,42 @@ + private long tickCount; + private long recordStartedTick; + private boolean isPlaying; ++ // CraftBukkit start - add fields and methods ++ public List transaction = new java.util.ArrayList(); ++ private int maxStack = MAX_STACK; ++ public boolean opened; ++ ++ @Override ++ public List getContents() { ++ return this.items; ++ } ++ ++ @Override ++ public void onOpen(CraftHumanEntity who) { ++ transaction.add(who); ++ } ++ ++ @Override ++ public void onClose(CraftHumanEntity who) { ++ transaction.remove(who); ++ } ++ ++ @Override ++ public List getViewers() { ++ return transaction; ++ } ++ ++ @Override ++ public void setMaxStackSize(int size) { ++ maxStack = size; ++ } ++ ++ @Override ++ public Location getLocation() { ++ if (level == null) return null; ++ return new org.bukkit.Location(level.getWorld(), worldPosition.getX(), worldPosition.getY(), worldPosition.getZ()); ++ } ++ // CraftBukkit end + + public TileEntityJukeBox(BlockPosition blockposition, IBlockData iblockdata) { + super(TileEntityTypes.JUKEBOX, blockposition, iblockdata); +@@ -150,7 +193,7 @@ + + @Override + public int getMaxStackSize() { +- return 1; ++ return maxStack; // CraftBukkit + } + + @Override diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityLectern.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityLectern.patch index abe72eb95b..cc5146602b 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityLectern.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityLectern.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityLectern.java +++ b/net/minecraft/world/level/block/entity/TileEntityLectern.java -@@ -25,13 +25,71 @@ +@@ -25,13 +25,72 @@ import net.minecraft.world.phys.Vec2F; import net.minecraft.world.phys.Vec3D; @@ -58,6 +58,7 @@ + + @Override + public Location getLocation() { ++ if (level == null) return null; + return new Location(level.getWorld(), worldPosition.getX(), worldPosition.getY(), worldPosition.getZ()); + } + @@ -74,7 +75,7 @@ @Override public int getContainerSize() { return 1; -@@ -76,11 +134,20 @@ +@@ -76,11 +135,20 @@ } @Override @@ -97,7 +98,7 @@ } @Override -@@ -160,7 +227,7 @@ +@@ -160,7 +228,7 @@ if (j != this.page) { this.page = j; this.setChanged(); @@ -106,7 +107,7 @@ } } -@@ -183,6 +250,32 @@ +@@ -183,6 +251,32 @@ return itemstack; } @@ -139,7 +140,7 @@ private CommandListenerWrapper createCommandSourceStack(@Nullable EntityHuman entityhuman) { String s; Object object; -@@ -197,7 +290,8 @@ +@@ -197,7 +291,8 @@ Vec3D vec3d = Vec3D.atCenterOf(this.worldPosition); @@ -149,7 +150,7 @@ } @Override -@@ -235,7 +329,7 @@ +@@ -235,7 +330,7 @@ @Override public Container createMenu(int i, PlayerInventory playerinventory, EntityHuman entityhuman) {