Fix conflicting keybindings not having the correct click count set. #9360

This commit is contained in:
Random832 authored and LexManos committed 2023-07-15 09:28:47 -07:00
1 parent 4385eb2155
commit 150e8281ae
4 files changed
+76

No files matched your search

@@ -12,6 +12,15 @@
private static final Set<String> f_90811_ = Sets.newHashSet();
public static final String f_167805_ = "key.categories.movement";
public static final String f_167806_ = "key.categories.misc";
@@ -41,7 +_,7 @@
private int f_90818_;
public static void m_90835_(InputConstants.Key p_90836_) {
- KeyMapping keymapping = f_90810_.get(p_90836_);
+ for (KeyMapping keymapping : f_90810_.getAll(p_90836_))
if (keymapping != null) {
++keymapping.f_90818_;
}
@@ -49,7 +_,7 @@
}
@@ -27,6 +27,8 @@ public class KeyMappingLookup
}
}
/** Replaced by {@link #getAll(InputConstants.Key) getAll} */
@Deprecated(forRemoval = true, since = "1.20.1")
@Nullable
public KeyMapping get(InputConstants.Key keyCode)
{
@@ -43,6 +45,7 @@ public class KeyMappingLookup
}
@Nullable
@Deprecated(forRemoval = true, since = "1.20.1")
private KeyMapping get(InputConstants.Key keyCode, KeyModifier keyModifier)
{
Collection<KeyMapping> bindings = map.get(keyModifier).get(keyCode);
@@ -59,6 +62,13 @@ public class KeyMappingLookup
return null;
}
/**
* Returns all active keys associated with the given key code and the active
* modifiers and conflict context.
*
* @param keyCode the key being pressed
* @return the list of key mappings
*/
public List<KeyMapping> getAll(InputConstants.Key keyCode)
{
List<KeyMapping> matchingBindings = new ArrayList<KeyMapping>();
@@ -0,0 +1,55 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.debug;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Items;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLConstructModEvent;
@Mod("keymapping_test")
public class KeyMappingTest
{
@Mod.EventBusSubscriber(modid = "keymapping_test", value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public static class ClientStuff {
// these are two separate keys to stand in for keys added by different
// mods that each do something similar with a held item from the
// respective mod, so the user wants them on the same physical key.
static KeyMapping stickKey = new KeyMapping("stick_key", InputConstants.KEY_BACKSLASH, KeyMapping.CATEGORY_MISC);
static KeyMapping rockKey = new KeyMapping("rock_key", InputConstants.KEY_BACKSLASH, KeyMapping.CATEGORY_MISC);
@SubscribeEvent
public static void init(FMLConstructModEvent event) {
MinecraftForge.EVENT_BUS.addListener(ClientStuff::tick);
}
@SubscribeEvent
public static void initKeys(RegisterKeyMappingsEvent event) {
event.register(stickKey);
event.register(rockKey);
}
public static void tick(TickEvent.ClientTickEvent event) {
if(event.phase != TickEvent.Phase.START) return;
if(stickKey.consumeClick()) {
Player player = Minecraft.getInstance().player;
if(player != null && player.getMainHandItem().is(Items.STICK))
player.sendSystemMessage(Component.literal("stick found!"));
}
if(rockKey.consumeClick()) {
Player player = Minecraft.getInstance().player;
if(player != null && player.getMainHandItem().is(Items.COBBLESTONE))
player.sendSystemMessage(Component.literal("rock found!"));
}
}
}
}
+2
View File
@@ -297,5 +297,7 @@ modId="chunk_event_load_new_chunk_test"
modId="custom_fluid_container_test"
[[mods]]
modId="alter_ground_event_test"
[[mods]]
modId="keymapping_test"
# ADD ABOVE THIS LINE