From fe89a8c1bbab24915dacf615ea516043f7678605 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 22 Dec 2018 10:50:57 +1100 Subject: [PATCH] SPIGOT-4503: Add API to insert complete ItemStack into Jukebox --- nms-patches/BlockJukeBox.patch | 17 +++++++++++++ nms-patches/TileEntityJukeBox.patch | 14 ----------- .../craftbukkit/block/CraftJukebox.java | 25 +++++++++++++------ 3 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 nms-patches/BlockJukeBox.patch delete mode 100644 nms-patches/TileEntityJukeBox.patch diff --git a/nms-patches/BlockJukeBox.patch b/nms-patches/BlockJukeBox.patch new file mode 100644 index 0000000000..456b3e9284 --- /dev/null +++ b/nms-patches/BlockJukeBox.patch @@ -0,0 +1,17 @@ +--- a/net/minecraft/server/BlockJukeBox.java ++++ b/net/minecraft/server/BlockJukeBox.java +@@ -24,7 +24,13 @@ + TileEntity tileentity = generatoraccess.getTileEntity(blockposition); + + if (tileentity instanceof TileEntityJukeBox) { +- ((TileEntityJukeBox) tileentity).setRecord(itemstack.cloneItemStack()); ++ // CraftBukkit start - There can only be one ++ itemstack = itemstack.cloneItemStack(); ++ if (!itemstack.isEmpty()) { ++ itemstack.setCount(1); ++ } ++ ((TileEntityJukeBox) tileentity).setRecord(itemstack); ++ // CraftBukkit end + generatoraccess.setTypeAndData(blockposition, (IBlockData) iblockdata.set(BlockJukeBox.HAS_RECORD, true), 2); + } + } diff --git a/nms-patches/TileEntityJukeBox.patch b/nms-patches/TileEntityJukeBox.patch deleted file mode 100644 index 2fb3714509..0000000000 --- a/nms-patches/TileEntityJukeBox.patch +++ /dev/null @@ -1,14 +0,0 @@ ---- a/net/minecraft/server/TileEntityJukeBox.java -+++ b/net/minecraft/server/TileEntityJukeBox.java -@@ -31,6 +31,11 @@ - } - - public void setRecord(ItemStack itemstack) { -+ // CraftBukkit start - There can only be one -+ if (!itemstack.isEmpty()) { -+ itemstack.setCount(1); -+ } -+ // CraftBukkit end - this.a = itemstack; - this.update(); - } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java b/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java index 552bfb45a4..50b0da15d0 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java @@ -12,6 +12,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Jukebox; import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.util.CraftMagicNumbers; public class CraftJukebox extends CraftBlockEntityState implements Jukebox { @@ -36,7 +37,7 @@ public class CraftJukebox extends CraftBlockEntityState imple } else { world.getHandle().setTypeAndData(position, Blocks.JUKEBOX.getBlockData().set(BlockJukeBox.HAS_RECORD, true), 3); } - world.playEffect(this.getLocation(), Effect.RECORD_PLAY, Item.getId(CraftMagicNumbers.getItem((Material) record))); + world.playEffect(this.getLocation(), Effect.RECORD_PLAY, record); } return result; @@ -44,11 +45,7 @@ public class CraftJukebox extends CraftBlockEntityState imple @Override public Material getPlaying() { - ItemStack record = this.getSnapshot().getRecord(); - if (record.isEmpty()) { - return Material.AIR; - } - return CraftMagicNumbers.getMaterial(record.getItem()); + return getRecord().getType(); } @Override @@ -57,8 +54,20 @@ public class CraftJukebox extends CraftBlockEntityState imple record = Material.AIR; } - this.getSnapshot().setRecord(new ItemStack(CraftMagicNumbers.getItem(record), 1)); - if (record == Material.AIR) { + setRecord(new org.bukkit.inventory.ItemStack(record)); + } + + @Override + public org.bukkit.inventory.ItemStack getRecord() { + ItemStack record = this.getSnapshot().getRecord(); + return CraftItemStack.asBukkitCopy(record); + } + + @Override + public void setRecord(org.bukkit.inventory.ItemStack record) { + ItemStack nms = CraftItemStack.asNMSCopy(record); + this.getSnapshot().setRecord(nms); + if (nms.isEmpty()) { getHandle().set(BlockJukeBox.HAS_RECORD, false); } else { getHandle().set(BlockJukeBox.HAS_RECORD, true);