diff options
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament')
4 files changed, 33 insertions, 14 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/apis/ingame/HypixelModAPI.kt b/src/main/kotlin/moe/nea/firmament/apis/ingame/HypixelModAPI.kt index 460df91..00e6aa9 100644 --- a/src/main/kotlin/moe/nea/firmament/apis/ingame/HypixelModAPI.kt +++ b/src/main/kotlin/moe/nea/firmament/apis/ingame/HypixelModAPI.kt @@ -6,6 +6,7 @@ package moe.nea.firmament.apis.ingame +import net.hypixel.modapi.fabric.event.HypixelModAPICallback import net.minecraft.network.packet.c2s.common.CustomPayloadC2SPacket import net.minecraft.text.Text import moe.nea.firmament.annotations.Subscribe @@ -30,6 +31,9 @@ object HypixelModAPI : SubscriptionOwner { InGameCodecWrapper.createStealthyCodec( PartyInfoResponse.intoType() ) + HypixelModAPICallback.EVENT.register(HypixelModAPICallback { + MC.sendChat(Text.literal("Official API: $it")) + }) } @JvmStatic diff --git a/src/main/kotlin/moe/nea/firmament/apis/ingame/InGameCodecWrapper.kt b/src/main/kotlin/moe/nea/firmament/apis/ingame/InGameCodecWrapper.kt index 0720dbf..447b902 100644 --- a/src/main/kotlin/moe/nea/firmament/apis/ingame/InGameCodecWrapper.kt +++ b/src/main/kotlin/moe/nea/firmament/apis/ingame/InGameCodecWrapper.kt @@ -35,6 +35,7 @@ class InGameCodecWrapper( override fun decode(buf: PacketByteBuf): CustomPayload { val duplicateBuffer = PacketByteBuf(buf.slice()) val original = wrapped.decode(buf) + buf.skipBytes(buf.readableBytes()) val duplicate = direction.customCodec.decode(duplicateBuffer) if (duplicate is FirmamentCustomPayload.Unhandled) return original diff --git a/src/main/kotlin/moe/nea/firmament/events/FirmamentEventBus.kt b/src/main/kotlin/moe/nea/firmament/events/FirmamentEventBus.kt index 8a7b387..f0a0ed3 100644 --- a/src/main/kotlin/moe/nea/firmament/events/FirmamentEventBus.kt +++ b/src/main/kotlin/moe/nea/firmament/events/FirmamentEventBus.kt @@ -1,5 +1,6 @@ /* * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> * * SPDX-License-Identifier: GPL-3.0-or-later */ @@ -8,6 +9,7 @@ package moe.nea.firmament.events import java.util.concurrent.CopyOnWriteArrayList import moe.nea.firmament.Firmament +import moe.nea.firmament.util.MC /** * A pubsub event bus. @@ -47,4 +49,9 @@ open class FirmamentEventBus<T : FirmamentEvent> { return event } + fun publishSync(event: T) { + MC.onMainThread { + publish(event) + } + } } diff --git a/src/main/kotlin/moe/nea/firmament/util/MC.kt b/src/main/kotlin/moe/nea/firmament/util/MC.kt index 830934f..4a4f7d3 100644 --- a/src/main/kotlin/moe/nea/firmament/util/MC.kt +++ b/src/main/kotlin/moe/nea/firmament/util/MC.kt @@ -56,23 +56,30 @@ object MC { player?.networkHandler?.sendCommand(command) } - inline val resourceManager get() = (MinecraftClient.getInstance().resourceManager as ReloadableResourceManagerImpl) + fun onMainThread(block: () -> Unit) { + if (instance.isOnThread) + block() + else + instance.send(block) + } + + inline val resourceManager get() = (instance.resourceManager as ReloadableResourceManagerImpl) inline val networkHandler get() = player?.networkHandler inline val instance get() = MinecraftClient.getInstance() - inline val keyboard get() = MinecraftClient.getInstance().keyboard - inline val textureManager get() = MinecraftClient.getInstance().textureManager - inline val inGameHud get() = MinecraftClient.getInstance().inGameHud - inline val font get() = MinecraftClient.getInstance().textRenderer - inline val soundManager get() = MinecraftClient.getInstance().soundManager - inline val player get() = MinecraftClient.getInstance().player - inline val camera get() = MinecraftClient.getInstance().cameraEntity - inline val guiAtlasManager get() = MinecraftClient.getInstance().guiAtlasManager - inline val world get() = MinecraftClient.getInstance().world + inline val keyboard get() = instance.keyboard + inline val textureManager get() = instance.textureManager + inline val inGameHud get() = instance.inGameHud + inline val font get() = instance.textRenderer + inline val soundManager get() = instance.soundManager + inline val player get() = instance.player + inline val camera get() = instance.cameraEntity + inline val guiAtlasManager get() = instance.guiAtlasManager + inline val world get() = instance.world inline var screen - get() = MinecraftClient.getInstance().currentScreen - set(value) = MinecraftClient.getInstance().setScreen(value) - inline val handledScreen: HandledScreen<*>? get() = MinecraftClient.getInstance().currentScreen as? HandledScreen<*> - inline val window get() = MinecraftClient.getInstance().window + get() = instance.currentScreen + set(value) = instance.setScreen(value) + inline val handledScreen: HandledScreen<*>? get() = instance.currentScreen as? HandledScreen<*> + inline val window get() = instance.window inline val currentRegistries: RegistryWrapper.WrapperLookup? get() = world?.registryManager val defaultRegistries: RegistryWrapper.WrapperLookup = BuiltinRegistries.createWrapperLookup() val defaultItems = defaultRegistries.getWrapperOrThrow(RegistryKeys.ITEM) |