Skip to content

Commit

Permalink
feat: Add forceVirtual to prevent a mapping from registering as a van…
Browse files Browse the repository at this point in the history
…illa key mapping
  • Loading branch information
BlayTheNinth committed Jun 1, 2024
1 parent d9e457f commit a5ca536
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.blay09.mods.kuma;

import net.blay09.mods.kuma.api.*;
import net.minecraft.client.KeyMapping;
import net.minecraft.resources.ResourceLocation;

import java.util.ArrayList;
Expand All @@ -15,6 +14,7 @@ public abstract class AbstractManagedKeyMappingBuilder implements ManagedKeyMapp
protected KeyConflictContext context;
protected InputBinding defaultBinding = InputBinding.none();
protected List<InputBinding> fallbackBindings = new ArrayList<>();
protected boolean forceVirtual;
protected WorldInputEventHandler worldInputHandler;
protected ScreenInputEventHandler screenInputHandler;

Expand Down Expand Up @@ -53,6 +53,12 @@ public ManagedKeyMapping.Builder handleWorldInput(WorldInputEventHandler handler
return this;
}

@Override
public ManagedKeyMapping.Builder forceVirtual() {
this.forceVirtual = true;
return this;
}

@Override
public ManagedKeyMapping.Builder handleScreenInput(ScreenInputEventHandler handler) {
this.screenInputHandler = handler;
Expand Down Expand Up @@ -88,7 +94,12 @@ public ManagedKeyMapping build() {
context = determineContext();
}
var effectiveBinding = determineBinding();
var managedKeyMapping = effectiveBinding.map(it -> (ManagedKeyMapping) createVanillaKeyMapping(name, it))
var managedKeyMapping = effectiveBinding.map(it -> {
if (forceVirtual) {
return null;
}
return (ManagedKeyMapping) createVanillaKeyMapping(name, it);
})
.orElseGet(() -> new VirtualManagedKeyMapping(context, screenInputHandler, worldInputHandler, defaultBinding));
ManagedKeyMappingRegistry.register(managedKeyMapping);
return managedKeyMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ interface Builder {

Builder handleWorldInput(WorldInputEventHandler handler);

Builder forceVirtual();

Builder handleScreenInput(ScreenInputEventHandler handler);

ManagedKeyMapping build();
Expand Down

0 comments on commit a5ca536

Please sign in to comment.