SPIGOT-7313: More accurately edit data on Jukeboxes

This commit is contained in:
Parker Hawke 2023-03-29 19:23:41 +11:00 committed by md_5
parent f92c945173
commit eff1743b9c
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 65 additions and 20 deletions

View File

@ -1,6 +1,6 @@
--- a/net/minecraft/world/level/block/entity/TileEntityJukeBox.java
+++ b/net/minecraft/world/level/block/entity/TileEntityJukeBox.java
@@ -24,6 +24,13 @@
@@ -24,14 +24,57 @@
import net.minecraft.world.phys.Vec3D;
import net.minecraft.world.ticks.ContainerSingleItem;
@ -14,10 +14,14 @@
public class TileEntityJukeBox extends TileEntity implements Clearable, ContainerSingleItem {
private static final int SONG_END_PADDING = 20;
@@ -32,6 +39,42 @@
private long tickCount;
private long recordStartedTick;
private boolean isPlaying;
private final NonNullList<ItemStack> items;
private int ticksSinceLastEvent;
- private long tickCount;
- private long recordStartedTick;
- private boolean isPlaying;
+ public long tickCount;
+ public long recordStartedTick;
+ public boolean isPlaying;
+ // CraftBukkit start - add fields and methods
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = MAX_STACK;

View File

@ -2,7 +2,6 @@ package org.bukkit.craftbukkit.block;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.BlockJukeBox;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.TileEntity;
import net.minecraft.world.level.block.entity.TileEntityJukeBox;
import org.bukkit.Effect;
@ -40,14 +39,19 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
boolean result = super.update(force, applyPhysics);
if (result && this.isPlaced() && this.getType() == Material.JUKEBOX) {
CraftWorld world = (CraftWorld) this.getWorld();
Material record = this.getPlaying();
if (record == Material.AIR) {
getWorldHandle().setBlock(this.getPosition(), Blocks.JUKEBOX.defaultBlockState().setValue(BlockJukeBox.HAS_RECORD, false), 3);
} else {
getWorldHandle().setBlock(this.getPosition(), Blocks.JUKEBOX.defaultBlockState().setValue(BlockJukeBox.HAS_RECORD, true), 3);
getWorldHandle().setBlock(this.getPosition(), data, 3);
TileEntity tileEntity = this.getTileEntityFromWorld();
if (tileEntity instanceof TileEntityJukeBox jukebox) {
CraftWorld world = (CraftWorld) this.getWorld();
if (record.isAir()) {
jukebox.setRecordWithoutPlaying(ItemStack.EMPTY);
world.playEffect(this.getLocation(), Effect.IRON_DOOR_CLOSE, 0); // TODO: Fix this enum constant. This stops jukeboxes
} else {
world.playEffect(this.getLocation(), Effect.RECORD_PLAY, record);
}
}
world.playEffect(this.getLocation(), Effect.RECORD_PLAY, record);
}
return result;
@ -67,6 +71,11 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
setRecord(new org.bukkit.inventory.ItemStack(record));
}
@Override
public boolean hasRecord() {
return getHandle().getValue(BlockJukeBox.HAS_RECORD) && !getPlaying().isAir();
}
@Override
public org.bukkit.inventory.ItemStack getRecord() {
ItemStack record = this.getSnapshot().getFirstItem();
@ -76,22 +85,54 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
@Override
public void setRecord(org.bukkit.inventory.ItemStack record) {
ItemStack nms = CraftItemStack.asNMSCopy(record);
this.getSnapshot().setRecordWithoutPlaying(nms);
if (nms.isEmpty()) {
this.data = this.data.setValue(BlockJukeBox.HAS_RECORD, false);
} else {
this.data = this.data.setValue(BlockJukeBox.HAS_RECORD, true);
}
TileEntityJukeBox snapshot = this.getSnapshot();
snapshot.setRecordWithoutPlaying(nms);
snapshot.recordStartedTick = snapshot.tickCount;
snapshot.isPlaying = !nms.isEmpty();
this.data = this.data.setValue(BlockJukeBox.HAS_RECORD, !nms.isEmpty());
}
@Override
public boolean isPlaying() {
return getHandle().getValue(BlockJukeBox.HAS_RECORD);
requirePlaced();
TileEntity tileEntity = this.getTileEntityFromWorld();
return tileEntity instanceof TileEntityJukeBox jukebox && jukebox.isRecordPlaying();
}
@Override
public boolean startPlaying() {
requirePlaced();
TileEntity tileEntity = this.getTileEntityFromWorld();
if (!(tileEntity instanceof TileEntityJukeBox jukebox)) {
return false;
}
ItemStack record = jukebox.getFirstItem();
if (record.isEmpty() || isPlaying()) {
return false;
}
jukebox.isPlaying = true;
jukebox.recordStartedTick = jukebox.tickCount;
getWorld().playEffect(getLocation(), Effect.RECORD_PLAY, CraftMagicNumbers.getMaterial(record.getItem()));
return true;
}
@Override
public void stopPlaying() {
getWorld().playEffect(getLocation(), Effect.RECORD_PLAY, Material.AIR);
requirePlaced();
TileEntity tileEntity = this.getTileEntityFromWorld();
if (!(tileEntity instanceof TileEntityJukeBox jukebox)) {
return;
}
jukebox.isPlaying = false;
getWorld().playEffect(getLocation(), Effect.IRON_DOOR_CLOSE, 0); // TODO: Fix this enum constant. This stops jukeboxes
}
@Override