SPIGOT-7309: Add API for jukebox inventories

Also fixes a crash when inserting music discs into jukeboxes with a Dropper

By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
CraftBukkit/Spigot
2023-03-23 20:55:14 +11:00
parent 2a51332a0c
commit abc47f4655
3 changed files with 51 additions and 1 deletions

View File

@@ -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<TileEntityJukeBox> implements Jukebox {
@@ -20,6 +21,20 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> 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);