13
0
geforkt von Mirrors/Paper

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>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2023-03-23 20:55:14 +11:00
Ursprung 2a51332a0c
Commit abc47f4655
3 geänderte Dateien mit 51 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -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);

Datei anzeigen

@ -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 {

Datei anzeigen

@ -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();
}
}