diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java index c15cde5054..76f4929459 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java @@ -1,6 +1,5 @@ package org.bukkit.craftbukkit.block; -import com.google.common.base.Preconditions; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.BlockJukeBox; import net.minecraft.world.level.block.Blocks; @@ -11,8 +10,10 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Jukebox; import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.inventory.CraftInventoryJukebox; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.inventory.JukeboxInventory; public class CraftJukebox extends CraftBlockEntityState implements Jukebox { @@ -20,6 +21,20 @@ public class CraftJukebox extends CraftBlockEntityState imple super(world, tileEntity); } + @Override + public JukeboxInventory getSnapshotInventory() { + return new CraftInventoryJukebox(this.getSnapshot()); + } + + @Override + public JukeboxInventory getInventory() { + if (!this.isPlaced()) { + return this.getSnapshotInventory(); + } + + return new CraftInventoryJukebox(this.getTileEntity()); + } + @Override public boolean update(boolean force, boolean applyPhysics) { boolean result = super.update(force, applyPhysics); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index 581d2fc0bc..93e6a6fcc4 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -17,6 +17,7 @@ import net.minecraft.world.level.block.entity.TileEntityBrewingStand; import net.minecraft.world.level.block.entity.TileEntityDispenser; import net.minecraft.world.level.block.entity.TileEntityDropper; import net.minecraft.world.level.block.entity.TileEntityFurnace; +import net.minecraft.world.level.block.entity.TileEntityJukeBox; import net.minecraft.world.level.block.entity.TileEntityLectern; import net.minecraft.world.level.block.entity.TileEntityShulkerBox; import net.minecraft.world.level.block.entity.TileEntitySmoker; @@ -502,6 +503,8 @@ public class CraftInventory implements Inventory { return InventoryType.STONECUTTER; } else if (inventory instanceof BlockComposter.ContainerEmpty || inventory instanceof BlockComposter.ContainerInput || inventory instanceof BlockComposter.ContainerOutput) { return InventoryType.COMPOSTER; + } else if (inventory instanceof TileEntityJukeBox) { + return InventoryType.JUKEBOX; } else if (this instanceof CraftInventorySmithingNew) { return InventoryType.SMITHING_NEW; } else { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryJukebox.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryJukebox.java new file mode 100644 index 0000000000..a864a17a44 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryJukebox.java @@ -0,0 +1,32 @@ +package org.bukkit.craftbukkit.inventory; + +import net.minecraft.world.IInventory; +import org.bukkit.block.Jukebox; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.JukeboxInventory; + +public class CraftInventoryJukebox extends CraftInventory implements JukeboxInventory { + + public CraftInventoryJukebox(IInventory inventory) { + super(inventory); + } + + @Override + public void setRecord(ItemStack item) { + if (item == null) { + inventory.removeItem(0, 0); // Second parameter is unused in TileEntityJukebox + } else { + setItem(0, item); + } + } + + @Override + public ItemStack getRecord() { + return getItem(0); + } + + @Override + public Jukebox getHolder() { + return (Jukebox) inventory.getOwner(); + } +}