• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CyclopsMC / CyclopsCore / #479033785

24 Mar 2025 03:08PM UTC coverage: 22.15% (-0.003%) from 22.153%
#479033785

push

github

rubensworks
Bump mod version

2297 of 10370 relevant lines covered (22.15%)

0.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/org/cyclops/cyclopscore/client/key/KeyRegistry.java
1
package org.cyclops.cyclopscore.client.key;
2

3
import com.google.common.collect.HashMultimap;
4
import com.google.common.collect.Multimap;
5
import net.minecraft.client.KeyMapping;
6
import net.minecraftforge.event.TickEvent;
7
import net.minecraftforge.eventbus.api.EventPriority;
8
import net.minecraftforge.eventbus.api.SubscribeEvent;
9
import org.cyclops.cyclopscore.helper.L10NHelpers;
10
import org.cyclops.cyclopscore.init.ModBase;
11

12
/**
13
 * Enum that contains all custom hotkeys that
14
 * are added. Every key also has a
15
 * {@link KeyMapping} for that specific key.
16
 *
17
 * @author immortaleeb
18
 *
19
 */
20
public class KeyRegistry implements IKeyRegistry {
×
21

22
    private final Multimap<KeyMapping, IKeyHandler> keyHandlerMap = HashMultimap.create();
×
23

24
    /**
25
     * Create a new keybinding.
26
     * @param mod The mod.
27
     * @param name The unique name.
28
     * @param defaultKey The keycode.
29
     * @return A new keybinding.
30
     */
31
    public static KeyMapping newKeyMapping(ModBase mod, String name, int defaultKey) {
32
        String id = L10NHelpers.localize("key." + mod.getModId() + "." + name);
×
33
        String category = L10NHelpers.localize("key.categories." + mod.getModId());
×
34
        return new KeyMapping(id, defaultKey, category);
×
35
    }
36

37
    @Override
38
    @SubscribeEvent(priority = EventPriority.NORMAL)
39
    public void onPlayerKeyInput(TickEvent.ClientTickEvent event) {
40
        if (event.phase == TickEvent.Phase.END) {
×
41
            for (KeyMapping kb : keyHandlerMap.keySet()) {
×
42
                while (kb.consumeClick()) {
×
43
                    fireKeyPressed(kb);
×
44
                }
45
            }
×
46
        }
47
    }
×
48

49
    private void fireKeyPressed(KeyMapping kb) {
50
        for (IKeyHandler h : keyHandlerMap.get(kb)) {
×
51
            h.onKeyPressed(kb);
×
52
        }
×
53
    }
×
54

55
    @Override
56
    public void addKeyHandler(KeyMapping kb, IKeyHandler handler) {
57
        keyHandlerMap.put(kb, handler);
×
58
    }
×
59

60
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc