Skip to content

Commit

Permalink
对 keyBindingReg 进行合并和适配
Browse files Browse the repository at this point in the history
  • Loading branch information
MegumiKasuga committed Oct 1, 2024
1 parent e526542 commit f6a37e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/kasuga/lib/core/KasugaLibStacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/kasuga/lib/core/events/both/BothSetupEvent.java
Original file line number Diff line number Diff line change
@@ -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()))
);
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
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;
private Consumer<LocalPlayer> clientHandler;
private Consumer<ServerPlayer> serverHandler;
private KeyModifier modifier = KeyModifier.NONE;
private InputConstants.Type type = InputConstants.Type.KEYSYM;

private static final ChannelReg keyChannel;
private static final LinkedList<KeyBindingReg> registered;

Expand Down Expand Up @@ -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;
}

Expand All @@ -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";
Expand Down

0 comments on commit f6a37e6

Please sign in to comment.