fix: smart instrument block entity serialization
This commit is contained in:
parent
b574d8a3d4
commit
fd7766b38c
@ -153,6 +153,8 @@ class SmartInstrumentBlockEntity(pos: BlockPos, state: BlockState) :
|
|||||||
const val TAG_MUSIC = "Music"
|
const val TAG_MUSIC = "Music"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// delay MusicPlayer initialization until level is available
|
||||||
|
var playerData: CompoundTag? = null
|
||||||
var player: MusicPlayer? = null
|
var player: MusicPlayer? = null
|
||||||
|
|
||||||
override fun getUpdateTag(): CompoundTag = saveWithoutMetadata()
|
override fun getUpdateTag(): CompoundTag = saveWithoutMetadata()
|
||||||
@ -162,7 +164,11 @@ class SmartInstrumentBlockEntity(pos: BlockPos, state: BlockState) :
|
|||||||
override fun load(tag: CompoundTag) {
|
override fun load(tag: CompoundTag) {
|
||||||
super.load(tag)
|
super.load(tag)
|
||||||
if (TAG_MUSIC in tag) {
|
if (TAG_MUSIC in tag) {
|
||||||
player = MusicPlayer(tag.getCompound(TAG_MUSIC), level!!, blockPos)
|
if (level == null) {
|
||||||
|
playerData = tag.getCompound(TAG_MUSIC)
|
||||||
|
} else {
|
||||||
|
player = MusicPlayer(tag.getCompound(TAG_MUSIC), level!!, blockPos)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,22 +205,27 @@ class SmartInstrumentBlockEntity(pos: BlockPos, state: BlockState) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun tick() {
|
fun tick() {
|
||||||
if (checkProjections()) {
|
if (playerData != null) {
|
||||||
player?.tick()
|
player = MusicPlayer(playerData!!, level!!, blockPos)
|
||||||
if (!level!!.isClientSide) {
|
}
|
||||||
if (player?.isEnd == true) {
|
if (player != null) {
|
||||||
player = null
|
if (checkProjections()) {
|
||||||
setChanged()
|
player!!.tick()
|
||||||
sendBlockUpdated()
|
if (!level!!.isClientSide) {
|
||||||
if (CausalityAnchor.checkEffect(level!!, blockPos) || level!!.random.nextInt(7) != 0) {
|
if (player!!.isEnd == true) {
|
||||||
startMusic()
|
player = null
|
||||||
|
setChanged()
|
||||||
|
sendBlockUpdated()
|
||||||
|
if (CausalityAnchor.checkEffect(level!!, blockPos) || level!!.random.nextInt(7) != 0) {
|
||||||
|
startMusic()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
player = null
|
||||||
|
setChanged()
|
||||||
|
sendBlockUpdated()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
player = null
|
|
||||||
setChanged()
|
|
||||||
sendBlockUpdated()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user