From f7c63e174d05f25b6bac771460a462ce9e442108 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Thu, 25 Apr 2024 22:21:18 +0100 Subject: [PATCH] Fix an init order problem with client-side armor registration Can't count on client tick events not coming in before FMLClientSetupEvent has been fired --- .../java/me/desht/pneumaticcraft/client/ClientSetup.java | 7 ++----- .../client/pneumatic_armor/ClientArmorRegistry.java | 9 +++++++++ .../common/pneumatic_armor/CommonArmorHandler.java | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/desht/pneumaticcraft/client/ClientSetup.java b/src/main/java/me/desht/pneumaticcraft/client/ClientSetup.java index 7b66fae30..ad824e77b 100644 --- a/src/main/java/me/desht/pneumaticcraft/client/ClientSetup.java +++ b/src/main/java/me/desht/pneumaticcraft/client/ClientSetup.java @@ -8,11 +8,7 @@ import me.desht.pneumaticcraft.client.gui.semiblock.LogisticsProviderScreen; import me.desht.pneumaticcraft.client.gui.semiblock.LogisticsRequesterScreen; import me.desht.pneumaticcraft.client.gui.semiblock.LogisticsStorageScreen; -import me.desht.pneumaticcraft.client.gui.tubemodule.AirGrateModuleScreen; -import me.desht.pneumaticcraft.client.gui.tubemodule.LogisticsModuleScreen; -import me.desht.pneumaticcraft.client.gui.tubemodule.PressureGaugeModuleScreen; -import me.desht.pneumaticcraft.client.gui.tubemodule.RedstoneModuleScreen; -import me.desht.pneumaticcraft.client.gui.tubemodule.ThermostatModuleScreen; +import me.desht.pneumaticcraft.client.gui.tubemodule.*; import me.desht.pneumaticcraft.client.gui.upgrademanager.*; import me.desht.pneumaticcraft.client.model.ModelMinigun; import me.desht.pneumaticcraft.client.model.PNCModelLayers; @@ -133,6 +129,7 @@ public static void initLate() { BlockTrackHandler.getInstance().freeze(); ClientArmorRegistry.getInstance().registerSubKeyBinds(); ClientArmorRegistry.getInstance().registerKeybindsWithMinecraft(); + ClientArmorRegistry.getInstance().freeze(); registerProgWidgetExtraRenderers(); } diff --git a/src/main/java/me/desht/pneumaticcraft/client/pneumatic_armor/ClientArmorRegistry.java b/src/main/java/me/desht/pneumaticcraft/client/pneumatic_armor/ClientArmorRegistry.java index c71391ff3..917734194 100644 --- a/src/main/java/me/desht/pneumaticcraft/client/pneumatic_armor/ClientArmorRegistry.java +++ b/src/main/java/me/desht/pneumaticcraft/client/pneumatic_armor/ClientArmorRegistry.java @@ -69,6 +69,8 @@ public enum ClientArmorRegistry implements IClientArmorRegistry { private final Map id2KeyBindMap = new ConcurrentHashMap<>(); // map keymapping name to upgrade handler that it triggers (e.g. hacking, kick, item launcher...) private final Map> triggerKeyBindMap = new ConcurrentHashMap<>(); + // frozen when everything set up + private boolean frozen; public static ClientArmorRegistry getInstance() { return INSTANCE; @@ -244,4 +246,11 @@ public void refreshConfig() { } } + public void freeze() { + frozen = true; + } + + public boolean isFrozen() { + return frozen; + } } diff --git a/src/main/java/me/desht/pneumaticcraft/common/pneumatic_armor/CommonArmorHandler.java b/src/main/java/me/desht/pneumaticcraft/common/pneumatic_armor/CommonArmorHandler.java index 3e3a7184f..665a91624 100644 --- a/src/main/java/me/desht/pneumaticcraft/common/pneumatic_armor/CommonArmorHandler.java +++ b/src/main/java/me/desht/pneumaticcraft/common/pneumatic_armor/CommonArmorHandler.java @@ -152,7 +152,7 @@ public static void onClientDisconnect(ClientPlayerNetworkEvent.LoggingOut event) @SubscribeEvent public static void tickEnd(TickEvent.ClientTickEvent event) { if (event.phase == TickEvent.Phase.END) { - if (ClientUtils.getOptionalClientPlayer().isEmpty() && ArmorUpgradeRegistry.getInstance().isFrozen()) { + if (ClientUtils.getOptionalClientPlayer().isEmpty() && ArmorUpgradeRegistry.getInstance().isFrozen() && ClientArmorRegistry.getInstance().isFrozen()) { for (EquipmentSlot slot : ArmorUpgradeRegistry.ARMOR_SLOTS) { ClientArmorRegistry.getInstance().getHandlersForSlot(slot).forEach(IArmorUpgradeClientHandler::reset); }