SPIGOT-7313: More accurately edit data on Jukeboxes
This commit is contained in:
parent
f92c945173
commit
eff1743b9c
@ -1,6 +1,6 @@
|
|||||||
--- a/net/minecraft/world/level/block/entity/TileEntityJukeBox.java
|
--- a/net/minecraft/world/level/block/entity/TileEntityJukeBox.java
|
||||||
+++ b/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.phys.Vec3D;
|
||||||
import net.minecraft.world.ticks.ContainerSingleItem;
|
import net.minecraft.world.ticks.ContainerSingleItem;
|
||||||
|
|
||||||
@ -14,10 +14,14 @@
|
|||||||
public class TileEntityJukeBox extends TileEntity implements Clearable, ContainerSingleItem {
|
public class TileEntityJukeBox extends TileEntity implements Clearable, ContainerSingleItem {
|
||||||
|
|
||||||
private static final int SONG_END_PADDING = 20;
|
private static final int SONG_END_PADDING = 20;
|
||||||
@@ -32,6 +39,42 @@
|
private final NonNullList<ItemStack> items;
|
||||||
private long tickCount;
|
private int ticksSinceLastEvent;
|
||||||
private long recordStartedTick;
|
- private long tickCount;
|
||||||
private boolean isPlaying;
|
- private long recordStartedTick;
|
||||||
|
- private boolean isPlaying;
|
||||||
|
+ public long tickCount;
|
||||||
|
+ public long recordStartedTick;
|
||||||
|
+ public boolean isPlaying;
|
||||||
+ // CraftBukkit start - add fields and methods
|
+ // CraftBukkit start - add fields and methods
|
||||||
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
||||||
+ private int maxStack = MAX_STACK;
|
+ private int maxStack = MAX_STACK;
|
||||||
|
@ -2,7 +2,6 @@ package org.bukkit.craftbukkit.block;
|
|||||||
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.block.BlockJukeBox;
|
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.TileEntity;
|
||||||
import net.minecraft.world.level.block.entity.TileEntityJukeBox;
|
import net.minecraft.world.level.block.entity.TileEntityJukeBox;
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
@ -40,15 +39,20 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
|
|||||||
boolean result = super.update(force, applyPhysics);
|
boolean result = super.update(force, applyPhysics);
|
||||||
|
|
||||||
if (result && this.isPlaced() && this.getType() == Material.JUKEBOX) {
|
if (result && this.isPlaced() && this.getType() == Material.JUKEBOX) {
|
||||||
CraftWorld world = (CraftWorld) this.getWorld();
|
|
||||||
Material record = this.getPlaying();
|
Material record = this.getPlaying();
|
||||||
if (record == Material.AIR) {
|
getWorldHandle().setBlock(this.getPosition(), data, 3);
|
||||||
getWorldHandle().setBlock(this.getPosition(), Blocks.JUKEBOX.defaultBlockState().setValue(BlockJukeBox.HAS_RECORD, false), 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 {
|
} else {
|
||||||
getWorldHandle().setBlock(this.getPosition(), Blocks.JUKEBOX.defaultBlockState().setValue(BlockJukeBox.HAS_RECORD, true), 3);
|
|
||||||
}
|
|
||||||
world.playEffect(this.getLocation(), Effect.RECORD_PLAY, record);
|
world.playEffect(this.getLocation(), Effect.RECORD_PLAY, record);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -67,6 +71,11 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
|
|||||||
setRecord(new org.bukkit.inventory.ItemStack(record));
|
setRecord(new org.bukkit.inventory.ItemStack(record));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasRecord() {
|
||||||
|
return getHandle().getValue(BlockJukeBox.HAS_RECORD) && !getPlaying().isAir();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public org.bukkit.inventory.ItemStack getRecord() {
|
public org.bukkit.inventory.ItemStack getRecord() {
|
||||||
ItemStack record = this.getSnapshot().getFirstItem();
|
ItemStack record = this.getSnapshot().getFirstItem();
|
||||||
@ -76,22 +85,54 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
|
|||||||
@Override
|
@Override
|
||||||
public void setRecord(org.bukkit.inventory.ItemStack record) {
|
public void setRecord(org.bukkit.inventory.ItemStack record) {
|
||||||
ItemStack nms = CraftItemStack.asNMSCopy(record);
|
ItemStack nms = CraftItemStack.asNMSCopy(record);
|
||||||
this.getSnapshot().setRecordWithoutPlaying(nms);
|
|
||||||
if (nms.isEmpty()) {
|
TileEntityJukeBox snapshot = this.getSnapshot();
|
||||||
this.data = this.data.setValue(BlockJukeBox.HAS_RECORD, false);
|
snapshot.setRecordWithoutPlaying(nms);
|
||||||
} else {
|
snapshot.recordStartedTick = snapshot.tickCount;
|
||||||
this.data = this.data.setValue(BlockJukeBox.HAS_RECORD, true);
|
snapshot.isPlaying = !nms.isEmpty();
|
||||||
}
|
|
||||||
|
this.data = this.data.setValue(BlockJukeBox.HAS_RECORD, !nms.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPlaying() {
|
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
|
@Override
|
||||||
public void stopPlaying() {
|
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
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user