Skip to content

Commit a71571b

Browse files
committed
fix: Fix inverted ifs, cleanup
1 parent 3cfe924 commit a71571b

8 files changed

Lines changed: 20 additions & 20 deletions

File tree

common/src/main/java/net/blay09/mods/defaultoptions/DefaultOptionsInitializer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
public class DefaultOptionsInitializer {
1414

15-
private static final Set<String> userModifiedKeys = new HashSet<>();
15+
private static final Set<String> userSeenKeys = new HashSet<>();
1616

1717
static {
1818
DefaultOptionsAPI.__internalMethods = new InternalMethodsImpl();
@@ -54,7 +54,7 @@ public static void postSave() {
5454
}
5555
}
5656

57-
public static void collectUserModifiedKeys(Options options) {
57+
public static void collectSeenKeys(Options options) {
5858
try (final var reader = Files.newReader(options.getFile(), Charsets.UTF_8)) {
5959
reader.lines().forEach((line) -> {
6060
try {
@@ -63,7 +63,7 @@ public static void collectUserModifiedKeys(Options options) {
6363
if (colonIndex != -1) {
6464
final var key = line.substring(0, colonIndex);
6565
final var name = key.substring("key_".length());
66-
userModifiedKeys.add(name);
66+
userSeenKeys.add(name);
6767
}
6868
}
6969
} catch (Exception ignored) {
@@ -73,10 +73,10 @@ public static void collectUserModifiedKeys(Options options) {
7373
}
7474
}
7575

76-
public static void markUserModifiedKeys(Options options) {
76+
public static void markUserSeenKeys(Options options) {
7777
for (final var keyMapping : options.keyMappings) {
78-
if (userModifiedKeys.contains(keyMapping.getName())) {
79-
((DefaultOptionsKeyMapping) keyMapping).defaultoptions$setUserModified(true);
78+
if (userSeenKeys.contains(keyMapping.getName())) {
79+
((DefaultOptionsKeyMapping) keyMapping).defaultoptions$setSeen(true);
8080
}
8181
}
8282
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package net.blay09.mods.defaultoptions;
22

33
public interface DefaultOptionsKeyMapping {
4-
boolean defaultoptions$wasUserModified();
5-
void defaultoptions$setUserModified(boolean modified);
4+
boolean defaultoptions$wasSeen();
5+
void defaultoptions$setSeen(boolean seen);
66
}

common/src/main/java/net/blay09/mods/defaultoptions/keys/DefaultKeyMapping.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public record DefaultKeyMapping(InputConstants.Key input, Set<KeyModifier> modifiers) {
1111
public boolean matches(KeyMapping keyMapping) {
1212
final var keyModifiers = PlatformBindings.INSTANCE.getKeyModifiers(keyMapping);
13-
if (modifiers.equals(keyModifiers)) {
13+
if (!modifiers.equals(keyModifiers)) {
1414
return false;
1515
}
1616

common/src/main/java/net/blay09/mods/defaultoptions/keys/KeyMappingDefaultsHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public boolean shouldLoadDefaults() {
7878

7979
@Override
8080
public void loadDefaults() {
81-
DefaultOptionsInitializer.markUserModifiedKeys(Minecraft.getInstance().options);
81+
DefaultOptionsInitializer.markUserSeenKeys(Minecraft.getInstance().options);
8282

8383
// Clear old values
8484
defaultKeys.clear();
@@ -130,7 +130,7 @@ public void loadDefaults() {
130130
// If the key is still on the original default and has not yet been modified on this run (i.e. through options load),
131131
// we update it to the new default. Essentially options.txt now acts as what was previously knownkeys.txt.
132132
// That way we don't override changes the player themselves may have made already.
133-
if (((DefaultOptionsKeyMapping) keyMapping).defaultoptions$wasUserModified()
133+
if (!((DefaultOptionsKeyMapping) keyMapping).defaultoptions$wasSeen()
134134
&& originalDefaultMapping.matches(keyMapping)
135135
&& !defaultKeyMapping.matches(keyMapping)) {
136136
final var defaultKeyModifiers = PlatformBindings.INSTANCE.getDefaultKeyModifiers(keyMapping);

common/src/main/java/net/blay09/mods/defaultoptions/mixin/KeyMappingMixin.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111
@Mixin(KeyMapping.class)
1212
public class KeyMappingMixin implements DefaultOptionsKeyMapping {
1313

14-
private boolean defaultoptions$userModified = false;
14+
private boolean defaultoptions$seen = false;
1515

1616
@Inject(method = "setKey", at = @At("HEAD"))
1717
void setKey(InputConstants.Key key, CallbackInfo ci) {
1818
// setKey is only called when the key didn't match the default on options load, so it's not reliable.
1919
// We just track it additionally to cover all bases.
20-
defaultoptions$userModified = true;
20+
defaultoptions$seen = true;
2121
}
2222

2323
@Override
24-
public boolean defaultoptions$wasUserModified() {
25-
return defaultoptions$userModified;
24+
public boolean defaultoptions$wasSeen() {
25+
return defaultoptions$seen;
2626
}
2727

2828
@Override
29-
public void defaultoptions$setUserModified(boolean modified) {
30-
defaultoptions$userModified = modified;
29+
public void defaultoptions$setSeen(boolean seen) {
30+
defaultoptions$seen = seen;
3131
}
3232
}

common/src/main/java/net/blay09/mods/defaultoptions/mixin/OptionsMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class OptionsMixin {
1212
@Inject(method = "load()V", at = @At("HEAD"))
1313
private void load(CallbackInfo ci) {
14-
DefaultOptionsInitializer.collectUserModifiedKeys((Options) (Object) this);
14+
DefaultOptionsInitializer.collectSeenKeys((Options) (Object) this);
1515
DefaultOptionsInitializer.preLoad();
1616
}
1717

forge/src/main/java/net/blay09/mods/defaultoptions/forge/mixin/ForgeKeyMappingMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class ForgeKeyMappingMixin {
1616
void setKeyModifierAndCode(KeyModifier keyModifier, InputConstants.Key keyCode, CallbackInfo ci) {
1717
// setKey is only called when the key didn't match the default on options load, so it's not reliable.
1818
// We just track it additionally to cover all bases.
19-
((DefaultOptionsKeyMapping) this).defaultoptions$setUserModified(true);
19+
((DefaultOptionsKeyMapping) this).defaultoptions$setSeen(true);
2020
}
2121

2222
}

neoforge/src/main/java/net/blay09/mods/defaultoptions/neoforge/mixin/NeoForgeKeyMappingMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class NeoForgeKeyMappingMixin {
1616
void setKeyModifierAndCode(KeyModifier keyModifier, InputConstants.Key keyCode, CallbackInfo ci) {
1717
// setKey is only called when the key didn't match the default on options load, so it's not reliable.
1818
// We just track it additionally to cover all bases.
19-
((DefaultOptionsKeyMapping) this).defaultoptions$setUserModified(true);
19+
((DefaultOptionsKeyMapping) this).defaultoptions$setSeen(true);
2020
}
2121

2222
}

0 commit comments

Comments
 (0)