fix gamemode handling

This commit is contained in:
Bixilon 2021-11-13 16:55:48 +01:00
parent f1c932a68a
commit 4db63f37f5
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 11 additions and 16 deletions

View File

@ -231,7 +231,7 @@ class WorldRenderer(
} }
private fun updateSectionSync(chunkPosition: Vec2i, sectionHeight: Int, chunk: Chunk, meshes: SynchronizedMap<Int, ChunkSectionMeshes>) { private fun updateSectionSync(chunkPosition: Vec2i, sectionHeight: Int, chunk: Chunk, meshes: SynchronizedMap<Int, ChunkSectionMeshes>) {
if (!chunk.isFullyLoaded || incomplete.contains(chunkPosition)) { if (!chunk.isFullyLoaded || chunkPosition in incomplete) {
// chunk not loaded and/or neighbours also not fully loaded // chunk not loaded and/or neighbours also not fully loaded
return return
} }
@ -339,7 +339,7 @@ class WorldRenderer(
for ((chunkPosition, sectionHeights) in this.queue.toSynchronizedMap()) { for ((chunkPosition, sectionHeights) in this.queue.toSynchronizedMap()) {
val chunk = world[chunkPosition] val chunk = world[chunkPosition]
if (chunk == null) { if (chunk == null || !chunk.isFullyLoaded || chunkPosition in incomplete) {
this.queue.remove(chunkPosition) this.queue.remove(chunkPosition)
continue continue
} }

View File

@ -17,10 +17,9 @@ import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.key.KeyAction import de.bixilon.minosoft.config.key.KeyAction
import de.bixilon.minosoft.config.key.KeyBinding import de.bixilon.minosoft.config.key.KeyBinding
import de.bixilon.minosoft.config.key.KeyCodes import de.bixilon.minosoft.config.key.KeyCodes
import de.bixilon.minosoft.data.abilities.Gamemodes
import de.bixilon.minosoft.data.direction.Directions import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.registries.ResourceLocation import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.other.game.event.handlers.gamemode.GamemodeChangeGameEventHandler import de.bixilon.minosoft.data.registries.other.game.event.handlers.gamemode.GamemodeChangeEvent
import de.bixilon.minosoft.data.text.BaseComponent import de.bixilon.minosoft.data.text.BaseComponent
import de.bixilon.minosoft.data.text.ChatColors import de.bixilon.minosoft.data.text.ChatColors
import de.bixilon.minosoft.data.text.TextComponent import de.bixilon.minosoft.data.text.TextComponent
@ -41,7 +40,6 @@ import de.bixilon.minosoft.gui.rendering.modding.events.ResizeWindowEvent
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
import de.bixilon.minosoft.modding.event.events.DifficultyChangeEvent import de.bixilon.minosoft.modding.event.events.DifficultyChangeEvent
import de.bixilon.minosoft.modding.event.events.GameEventChangeEvent
import de.bixilon.minosoft.modding.event.events.TimeChangeEvent import de.bixilon.minosoft.modding.event.events.TimeChangeEvent
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
import de.bixilon.minosoft.modding.loading.ModLoader import de.bixilon.minosoft.modding.loading.ModLoader
@ -152,12 +150,8 @@ class DebugHUDElement(hudRenderer: HUDRenderer) : LayoutedHUDElement<GridLayout>
layout += LineSpacerElement(hudRenderer) layout += LineSpacerElement(hudRenderer)
layout += TextElement(hudRenderer, BaseComponent("Gamemode ", connection.player.gamemode)).apply { layout += TextElement(hudRenderer, BaseComponent("Gamemode ", connection.player.gamemode)).apply {
connection.registerEvent(CallbackEventInvoker.of<GameEventChangeEvent> { connection.registerEvent(CallbackEventInvoker.of<GamemodeChangeEvent> {
if (it.event.resourceLocation != GamemodeChangeGameEventHandler.RESOURCE_LOCATION) { text = BaseComponent("Gamemode ", it.gamemode)
return@of
}
// ToDo: Improve game mode change event
text = BaseComponent("Gamemode ", Gamemodes[it.data.toInt()])
}) })
} }

View File

@ -147,6 +147,7 @@ class JoinGameS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun handle(connection: PlayConnection) { override fun handle(connection: PlayConnection) {
val gamemode = Gamemodes.SPECTATOR
val playerEntity = connection.player val playerEntity = connection.player
val previousGamemode = playerEntity.tabListItem.gamemode val previousGamemode = playerEntity.tabListItem.gamemode

View File

@ -169,13 +169,13 @@ class TabListDataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
entity.tabListItem.specialMerge(data) entity.tabListItem.specialMerge(data)
} else { } else {
tabListItem.merge(data) tabListItem.merge(data)
} if (entity == null || entity !is PlayerEntity) {
continue
if (entity == null || entity !is PlayerEntity) { }
continue
entity.tabListItem = tabListItem
} }
entity.tabListItem = tabListItem
} }
connection.fireEvent(TabListEntryChangeEvent(connection, this)) connection.fireEvent(TabListEntryChangeEvent(connection, this))
} }