From f6a37e6c40c93adacf5886349ccf0166db5e4753 Mon Sep 17 00:00:00 2001 From: MegumiKasuga <1926195023@qq.com> Date: Tue, 1 Oct 2024 22:11:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=20keyBindingReg=20=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=92=8C=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/kasuga/lib/core/KasugaLibStacks.java | 2 +- .../kasuga/lib/core/events/both/BothSetupEvent.java | 13 +++++++++++++ .../lib/registrations/client/KeyBindingReg.java | 8 -------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/kasuga/lib/core/KasugaLibStacks.java b/src/main/java/kasuga/lib/core/KasugaLibStacks.java index 867502cf..11a8d317 100644 --- a/src/main/java/kasuga/lib/core/KasugaLibStacks.java +++ b/src/main/java/kasuga/lib/core/KasugaLibStacks.java @@ -61,7 +61,7 @@ public KasugaLibStacks(IEventBus bus) { MinecraftForge.EVENT_BUS.addListener(PacketEvent::onServerPayloadHandleEvent); bus.addListener(BothSetupEvent::onFMLCommonSetup); bus.addListener(EntityAttributeEvent::entityAttributeCreation); - bus.addListener(KeyBindingReg::register); + bus.addListener(BothSetupEvent::RegisterKeyEvent); if(Envs.isClient()) { MinecraftForge.EVENT_BUS.addListener(PacketEvent::onClientPayloadHandleEvent); diff --git a/src/main/java/kasuga/lib/core/events/both/BothSetupEvent.java b/src/main/java/kasuga/lib/core/events/both/BothSetupEvent.java index 8e6cfe1d..b4a64618 100644 --- a/src/main/java/kasuga/lib/core/events/both/BothSetupEvent.java +++ b/src/main/java/kasuga/lib/core/events/both/BothSetupEvent.java @@ -1,10 +1,23 @@ package kasuga.lib.core.events.both; import kasuga.lib.KasugaLib; +import net.minecraftforge.client.event.RegisterKeyMappingsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; public class BothSetupEvent { public static void onFMLCommonSetup(FMLCommonSetupEvent event){ } + + @SubscribeEvent + public static void RegisterKeyEvent(RegisterKeyMappingsEvent event) { + KasugaLib.STACKS.getRegistries().forEach( + (name, registry) -> { + registry.key().forEach( + ((s, keyBindingReg) -> event.register(keyBindingReg.getMapping())) + ); + } + ); + } } diff --git a/src/main/java/kasuga/lib/registrations/client/KeyBindingReg.java b/src/main/java/kasuga/lib/registrations/client/KeyBindingReg.java index 3545999c..380124cc 100644 --- a/src/main/java/kasuga/lib/registrations/client/KeyBindingReg.java +++ b/src/main/java/kasuga/lib/registrations/client/KeyBindingReg.java @@ -25,7 +25,6 @@ public class KeyBindingReg extends Reg { public final String translationKey; public final String category; - private int keyCode = -1; private KeyMapping mapping; private Environment env = Environment.ALL; @@ -33,7 +32,6 @@ public class KeyBindingReg extends Reg { private Consumer serverHandler; private KeyModifier modifier = KeyModifier.NONE; private InputConstants.Type type = InputConstants.Type.KEYSYM; - private static final ChannelReg keyChannel; private static final LinkedList registered; @@ -123,7 +121,6 @@ public KeyBindingReg submit(SimpleRegistry registry) { this.mapping = new KeyMapping(registrationKey, env.context, modifier, type, keyCode, category); registry.key().put(this.toString(), this); registered.add(this); - ClientRegistry.registerKeyBinding(this.mapping); return this; } @@ -142,11 +139,6 @@ public static void onClientTick(){ }); } - @Inner - public static void register(RegisterKeyMappingsEvent event) { - reference.forEach(reg -> event.register(reg.mapping)); - } - @Override public String getIdentifier() { return "key_binding";