fix: dirty-data for block entities

This commit is contained in:
xtex 2023-07-29 16:20:35 +08:00
parent 7fcd199b9f
commit 249d060075
Signed by: xtex
GPG Key ID: B918086ED8045B91
4 changed files with 11 additions and 7 deletions

View File

@ -19,7 +19,7 @@ object SimpleProjectionUpdate {
NetworkManager.registerReceiver(NetworkManager.Side.C2S, id, ::handle)
}
private fun handle(buf: FriendlyByteBuf, ctx: PacketContext) {
private fun handle(buf: FriendlyByteBuf, ctx: PacketContext) = runCatching {
val player = ctx.player!! as ServerPlayer
val level = player.level()
@ -31,7 +31,7 @@ object SimpleProjectionUpdate {
if (player.blockPosition().distSqr(pos) > 50 * 50) {
player.connection.disconnect(Component.literal("[Quaedam] wth r u doing? why not waiting for server?"))
}
return
return@runCatching
}
level.server!!.execute {
@ -47,10 +47,13 @@ object SimpleProjectionUpdate {
player.connection.disconnect(Component.literal("[Quaedam] ? wait what did you send to the server?"))
return@execute
}
entity.setChanged()
blockEntity.sendBlockUpdated()
ProjectionBlock.sendUpdateToProjectors(level, pos)
}
}
.onFailure { Quaedam.logger.error("Error handling simple projection update packet", it) }
.getOrThrow()
fun send(pos: BlockPos, data: CompoundTag) {
val buf = FriendlyByteBuf(Unpooled.buffer())

View File

@ -101,7 +101,7 @@ object NoiseProjectionBlock : EntityProjectionBlock<NoiseProjectionEffect>(creat
}
data class NoiseProjectionEffect(var rate: Int = 120, var amount: Int = 3) : ProjectionEffect(),
data class NoiseProjectionEffect(var rate: Int = 250, var amount: Int = 3) : ProjectionEffect(),
ProjectionEffectShell.Provider {
companion object {

View File

@ -106,6 +106,7 @@ class ProjectorBlockEntity(pos: BlockPos, state: BlockState) :
if (!level.isClientSide && notify) {
sendBlockUpdated()
}
setChanged()
val addedEffects = effects.filterKeys { it !in oldEffects }
val removedEffects = oldEffects.filterKeys { it !in effects }
val updatedEffects = effects.filter { (k, v) -> oldEffects[k] != null && oldEffects[k] != v }

View File

@ -34,10 +34,6 @@ class ProjectionShellScreen(val level: Level, val pos: BlockPos, val shell: Proj
run { // Buttons
rows.addChild(StringWidget(Component.empty(), font))
rows.addChild(Button.builder(Component.translatable("quaedam.screen.projection_shell.save")) {
val block = level.getBlockState(pos).block
if (block is ProjectionShellBlock) {
block.applyFromShell(level, pos, shell)
}
GameInstance.getClient().setScreen(null)
}.build().apply(::setInitialFocus))
}
@ -78,6 +74,10 @@ class ProjectionShellScreen(val level: Level, val pos: BlockPos, val shell: Proj
override fun removed() {
super.removed()
val block = level.getBlockState(pos).block
if (block is ProjectionShellBlock) {
block.applyFromShell(level, pos, shell)
}
ProjectionShell.channel.sendToServer(ServerboundPSHLockReleasePacket(pos))
}