3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 12:30:06 +01:00

SPIGOT-4503: Add API to insert complete ItemStack into Jukebox

Dieser Commit ist enthalten in:
md_5 2018-12-22 10:50:57 +11:00
Ursprung fc1024944e
Commit fe89a8c1bb
3 geänderte Dateien mit 34 neuen und 22 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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