|
| 1 | +package dev.xpple.seedmapper; |
| 2 | + |
| 3 | +import com.mojang.blaze3d.platform.InputConstants; |
| 4 | +import dev.xpple.seedmapper.config.Configs; |
| 5 | +import dev.xpple.seedmapper.render.RenderManager; |
| 6 | +import dev.xpple.seedmapper.seedmap.MapFeature; |
| 7 | +import dev.xpple.seedmapper.seedmap.SeedMapMinimapManager; |
| 8 | +import dev.xpple.seedmapper.seedmap.SeedMapScreen; |
| 9 | +import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper; |
| 10 | +import net.minecraft.client.KeyMapping; |
| 11 | +import net.minecraft.client.Minecraft; |
| 12 | +import net.minecraft.resources.Identifier; |
| 13 | + |
| 14 | +import java.util.Arrays; |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +public final class SeedMapperKeybinds { |
| 18 | + private SeedMapperKeybinds() {} |
| 19 | + |
| 20 | + private static final KeyMapping.Category CATEGORY = KeyMapping.Category.register(Identifier.fromNamespaceAndPath(SeedMapper.MOD_ID, SeedMapper.MOD_ID)); |
| 21 | + private static final int UNBOUND_KEY = InputConstants.UNKNOWN.getValue(); |
| 22 | + |
| 23 | + private static KeyMapping OPEN_SEEDMAP; |
| 24 | + private static KeyMapping TOGGLE_MINIMAP; |
| 25 | + private static KeyMapping TOGGLE_OPTIONS; |
| 26 | + private static KeyMapping OPEN_LOOT_VIEWER; |
| 27 | + private static KeyMapping CLEAR_ESP; |
| 28 | + private static KeyMapping TOGGLE_SELECTED_ESP; |
| 29 | + private static KeyMapping TOGGLE_BLOCK_ESP; |
| 30 | + private static KeyMapping TOGGLE_ORE_VEIN_ESP; |
| 31 | + private static KeyMapping TOGGLE_CANYON_ESP; |
| 32 | + private static KeyMapping TOGGLE_CAVE_ESP; |
| 33 | + private static KeyMapping TOGGLE_TERRAIN_ESP; |
| 34 | + private static KeyMapping TOGGLE_ORE_VEINS; |
| 35 | + private static KeyMapping TOGGLE_CANYON; |
| 36 | + private static KeyMapping TOGGLE_SLIME_CHUNKS; |
| 37 | + private static KeyMapping TOGGLE_WAYPOINTS; |
| 38 | + private static KeyMapping TOGGLE_WORLD_SPAWN; |
| 39 | + private static KeyMapping TOGGLE_PLAYER_ICON; |
| 40 | + private static KeyMapping TOGGLE_DATAPACK_STRUCTURES; |
| 41 | + private static List<KeyMapping> ALL = List.of(); |
| 42 | + |
| 43 | + private static KeyMapping register(String translationKey, int defaultKey) { |
| 44 | + return KeyMappingHelper.registerKeyMapping(new KeyMapping(translationKey, defaultKey, CATEGORY)); |
| 45 | + } |
| 46 | + |
| 47 | + public static void registerAll() { |
| 48 | + if (!ALL.isEmpty()) { |
| 49 | + return; |
| 50 | + } |
| 51 | + OPEN_SEEDMAP = register("key.seedmapper.open_seedmap", InputConstants.KEY_M); |
| 52 | + TOGGLE_MINIMAP = register("key.seedmapper.toggle_minimap", InputConstants.KEY_COMMA); |
| 53 | + TOGGLE_OPTIONS = register("key.seedmapper.toggle_options", InputConstants.KEY_O); |
| 54 | + OPEN_LOOT_VIEWER = register("key.seedmapper.open_loot_viewer", InputConstants.KEY_L); |
| 55 | + CLEAR_ESP = register("key.seedmapper.clear_esp", InputConstants.KEY_SEMICOLON); |
| 56 | + TOGGLE_SELECTED_ESP = register("key.seedmapper.toggle_selected_esp", UNBOUND_KEY); |
| 57 | + TOGGLE_BLOCK_ESP = register("key.seedmapper.toggle_block_esp", UNBOUND_KEY); |
| 58 | + TOGGLE_ORE_VEIN_ESP = register("key.seedmapper.toggle_ore_vein_esp", UNBOUND_KEY); |
| 59 | + TOGGLE_CANYON_ESP = register("key.seedmapper.toggle_canyon_esp", UNBOUND_KEY); |
| 60 | + TOGGLE_CAVE_ESP = register("key.seedmapper.toggle_cave_esp", UNBOUND_KEY); |
| 61 | + TOGGLE_TERRAIN_ESP = register("key.seedmapper.toggle_terrain_esp", UNBOUND_KEY); |
| 62 | + TOGGLE_ORE_VEINS = register("key.seedmapper.toggle_ore_veins", UNBOUND_KEY); |
| 63 | + TOGGLE_CANYON = register("key.seedmapper.toggle_canyon", UNBOUND_KEY); |
| 64 | + TOGGLE_SLIME_CHUNKS = register("key.seedmapper.toggle_slime_chunks", UNBOUND_KEY); |
| 65 | + TOGGLE_WAYPOINTS = register("key.seedmapper.toggle_waypoints", UNBOUND_KEY); |
| 66 | + TOGGLE_WORLD_SPAWN = register("key.seedmapper.toggle_world_spawn", UNBOUND_KEY); |
| 67 | + TOGGLE_PLAYER_ICON = register("key.seedmapper.toggle_player_icon", UNBOUND_KEY); |
| 68 | + TOGGLE_DATAPACK_STRUCTURES = register("key.seedmapper.toggle_datapack_structures", UNBOUND_KEY); |
| 69 | + ALL = List.of( |
| 70 | + OPEN_SEEDMAP, |
| 71 | + TOGGLE_MINIMAP, |
| 72 | + TOGGLE_OPTIONS, |
| 73 | + OPEN_LOOT_VIEWER, |
| 74 | + CLEAR_ESP, |
| 75 | + TOGGLE_SELECTED_ESP, |
| 76 | + TOGGLE_BLOCK_ESP, |
| 77 | + TOGGLE_ORE_VEIN_ESP, |
| 78 | + TOGGLE_CANYON_ESP, |
| 79 | + TOGGLE_CAVE_ESP, |
| 80 | + TOGGLE_TERRAIN_ESP, |
| 81 | + TOGGLE_ORE_VEINS, |
| 82 | + TOGGLE_CANYON, |
| 83 | + TOGGLE_SLIME_CHUNKS, |
| 84 | + TOGGLE_WAYPOINTS, |
| 85 | + TOGGLE_WORLD_SPAWN, |
| 86 | + TOGGLE_PLAYER_ICON, |
| 87 | + TOGGLE_DATAPACK_STRUCTURES |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + public static List<KeyMapping> all() { |
| 92 | + return ALL; |
| 93 | + } |
| 94 | + |
| 95 | + public static void handleClientTick(Minecraft minecraft) { |
| 96 | + while (OPEN_SEEDMAP.consumeClick()) { |
| 97 | + runCommand(minecraft, "sm:seedmap"); |
| 98 | + } |
| 99 | + while (TOGGLE_MINIMAP.consumeClick()) { |
| 100 | + runCommand(minecraft, "sm:minimap"); |
| 101 | + } |
| 102 | + while (TOGGLE_OPTIONS.consumeClick()) { |
| 103 | + if (!SeedMapScreen.toggleOptionsFromKeybind(minecraft)) { |
| 104 | + runCommand(minecraft, "sm:seedmap"); |
| 105 | + } |
| 106 | + } |
| 107 | + while (OPEN_LOOT_VIEWER.consumeClick()) { |
| 108 | + SeedMapScreen.openLootViewerFromKeybind(minecraft); |
| 109 | + } |
| 110 | + while (CLEAR_ESP.consumeClick()) { |
| 111 | + RenderManager.clear(); |
| 112 | + } |
| 113 | + while (TOGGLE_SELECTED_ESP.consumeClick()) { |
| 114 | + SeedMapScreen.toggleSelectedEspFromKeybind(minecraft); |
| 115 | + } |
| 116 | + while (TOGGLE_BLOCK_ESP.consumeClick()) { |
| 117 | + SeedMapScreen.toggleBlockEspFromKeybind(minecraft); |
| 118 | + } |
| 119 | + while (TOGGLE_ORE_VEIN_ESP.consumeClick()) { |
| 120 | + SeedMapScreen.toggleOreVeinEspFromKeybind(minecraft); |
| 121 | + } |
| 122 | + while (TOGGLE_CANYON_ESP.consumeClick()) { |
| 123 | + SeedMapScreen.toggleCanyonEspFromKeybind(minecraft); |
| 124 | + } |
| 125 | + while (TOGGLE_CAVE_ESP.consumeClick()) { |
| 126 | + SeedMapScreen.toggleCaveEspFromKeybind(minecraft); |
| 127 | + } |
| 128 | + while (TOGGLE_TERRAIN_ESP.consumeClick()) { |
| 129 | + SeedMapScreen.toggleTerrainEspFromKeybind(minecraft); |
| 130 | + } |
| 131 | + while (TOGGLE_ORE_VEINS.consumeClick()) { |
| 132 | + toggleFeatures(MapFeature.COPPER_ORE_VEIN, MapFeature.IRON_ORE_VEIN); |
| 133 | + } |
| 134 | + while (TOGGLE_CANYON.consumeClick()) { |
| 135 | + toggleFeatures(MapFeature.CANYON); |
| 136 | + } |
| 137 | + while (TOGGLE_SLIME_CHUNKS.consumeClick()) { |
| 138 | + toggleFeatures(MapFeature.SLIME_CHUNK); |
| 139 | + } |
| 140 | + while (TOGGLE_WAYPOINTS.consumeClick()) { |
| 141 | + toggleFeatures(MapFeature.WAYPOINT); |
| 142 | + } |
| 143 | + while (TOGGLE_WORLD_SPAWN.consumeClick()) { |
| 144 | + toggleFeatures(MapFeature.WORLD_SPAWN); |
| 145 | + } |
| 146 | + while (TOGGLE_PLAYER_ICON.consumeClick()) { |
| 147 | + toggleFeatures(MapFeature.PLAYER_ICON); |
| 148 | + } |
| 149 | + while (TOGGLE_DATAPACK_STRUCTURES.consumeClick()) { |
| 150 | + Configs.ShowDatapackStructures = !Configs.ShowDatapackStructures; |
| 151 | + Configs.save(); |
| 152 | + SeedMapMinimapManager.refreshIfOpen(); |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + private static void runCommand(Minecraft minecraft, String command) { |
| 157 | + if (minecraft.player == null || minecraft.player.connection == null) { |
| 158 | + return; |
| 159 | + } |
| 160 | + minecraft.player.connection.sendCommand(command); |
| 161 | + } |
| 162 | + |
| 163 | + private static void toggleFeatures(MapFeature... features) { |
| 164 | + boolean enable = Arrays.stream(features).anyMatch(feature -> !Configs.ToggledFeatures.contains(feature)); |
| 165 | + for (MapFeature feature : features) { |
| 166 | + if (enable) { |
| 167 | + Configs.ToggledFeatures.add(feature); |
| 168 | + } else { |
| 169 | + Configs.ToggledFeatures.remove(feature); |
| 170 | + } |
| 171 | + } |
| 172 | + Configs.save(); |
| 173 | + SeedMapMinimapManager.refreshIfOpen(); |
| 174 | + } |
| 175 | +} |
0 commit comments