Skip to content

Commit

Permalink
Map name of injected key mapping field
Browse files Browse the repository at this point in the history
Fixes #1043
  • Loading branch information
Su5eD committed Apr 27, 2024
1 parent 8ebc197 commit 612e1a2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ versionForgeAutoRenamingTool=1.0.11
versionFabricLoader=2.7.2+0.15.3+1.20.1
versionAccessWidener=2.1.0
versionFabricApi=0.92.0+1.11.5+1.20.1
versionMixin=0.12.10+mixin.0.8.5
versionMixinTransmog=0.4.5+1.20.1
versionMixin=0.12.11+mixin.0.8.5
versionMixinTransmog=0.4.6+1.20.1

# Publishing
curseForgeId=890127
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public class KeyMappingMixin {
@Shadow
private static KeyMappingLookup MAP;

@Shadow(remap = false, aliases = "f_90810_")
@Shadow(remap = false, aliases = { "f_90810_", "MAP" })
private static final Map<InputConstants.Key, KeyMapping> vanillaKeyMapping;

private static final ThreadLocal<KeyMapping> KEY_MAPPING_LOCAL = new ThreadLocal<>();

@Inject(method = "set", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/KeyMapping;setDown(Z)V"))
private static void onSetKeyMapping(InputConstants.Key pKey, boolean pHeld, CallbackInfo ci, @Local KeyMapping keyMapping) {
KEY_MAPPING_LOCAL.set(keyMapping);
Expand All @@ -50,7 +50,7 @@ private static void connector_onSetKeyMapping(InputConstants.Key pKey, boolean p
// if they use the field in their code or otherwise reflect (see voxelmap)
// The field is added back through a coremod, and here it is semi-delegated
final EnumMap<KeyModifier, Map<InputConstants.Key, Collection<KeyMapping>>> actualMap = ObfuscationReflectionHelper
.getPrivateValue(KeyMappingLookup.class, MAP, "map");
.getPrivateValue(KeyMappingLookup.class, MAP, "map");
final var delegate = actualMap.get(KeyModifier.NONE);
vanillaKeyMapping = new Map<>() {
@Override
Expand Down Expand Up @@ -99,7 +99,7 @@ public KeyMapping remove(Object key) {
public boolean remove(Object key, Object value) {
Object curValue = get(key);
if (!Objects.equals(curValue, value) ||
(curValue == null && !containsKey(key))) {
(curValue == null && !containsKey(key))) {
return false;
}
MAP.remove((KeyMapping) value);
Expand All @@ -126,20 +126,20 @@ public Set<InputConstants.Key> keySet() {
@Override
public Collection<KeyMapping> values() {
return delegate.values()
.stream().flatMap(Collection::stream)
.toList();
.stream().flatMap(Collection::stream)
.toList();
}

@NotNull
@Override
public Set<Entry<InputConstants.Key, KeyMapping>> entrySet() {
return delegate.entrySet().stream()
.filter(e -> !e.getValue().isEmpty())
.collect(Collectors.toMap(
Entry::getKey,
e -> ((ArrayList<KeyMapping>) e.getValue()).get(0)
))
.entrySet();
.filter(e -> !e.getValue().isEmpty())
.collect(Collectors.toMap(
Entry::getKey,
e -> ((ArrayList<KeyMapping>) e.getValue()).get(0)
))
.entrySet();
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/mod/resources/META-INF/asm/fixFieldSignatureChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function initializeCoreMod() {

// Add the field before the f_90812_ (KeyMapping#CATEGORY_SORT_ORDER) which is the 3rd map
// See https://github.com/Sinytra/Connector/issues/723
node.fields.add(i, new FieldNode(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, 'f_90810_', 'Ljava/util/Map;', null, null));
node.fields.add(i, new FieldNode(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, ASMAPI.mapField('f_90810_'), 'Ljava/util/Map;', null, null));

ASMAPI.log('DEBUG', 'Added field for KeyMapping#MAP (f_90810_) at index ' + (i + 1));
return node;
Expand Down

0 comments on commit 612e1a2

Please sign in to comment.