forked from Clones/Controlify
🐛 Fix vanilla overrides getting stuck sometimes
This commit is contained in:
@ -410,16 +410,21 @@ public class ControllerBindings<T extends ControllerState> {
|
|||||||
|
|
||||||
registerModdedKeybinds();
|
registerModdedKeybinds();
|
||||||
|
|
||||||
// key events are executed in Minecraft#execute, aka runTick.runAllTasks()
|
// key events are executed in Minecraft#execute, which run at runTick.runAllTasks()
|
||||||
// which is called before ticking (the event below). so we can safely imitate clicks
|
// which this event runs directly after. A normal tick could run multiple
|
||||||
// before key mappings are handled in tick()
|
// times per frame, so you could get double clicks if lagging.
|
||||||
ClientTickEvents.START_CLIENT_TICK.register(this::onTick);
|
InputHandledEvent.EVENT.register(this::imitateVanillaClick);
|
||||||
|
|
||||||
ControlifyEvents.INPUT_MODE_CHANGED.register(mode -> KeyMapping.releaseAll());
|
ControlifyEvents.INPUT_MODE_CHANGED.register(mode -> KeyMapping.releaseAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControllerBinding register(ControllerBinding binding) {
|
public ControllerBinding register(ControllerBinding binding) {
|
||||||
registry.put(binding.id(), binding);
|
registry.put(binding.id(), binding);
|
||||||
|
|
||||||
|
if (binding.override() != null) {
|
||||||
|
((KeyMappingOverrideHolder) binding.override().keyMapping()).controlify$addOverride(binding);
|
||||||
|
}
|
||||||
|
|
||||||
return binding;
|
return binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,10 +486,6 @@ public class ControllerBindings<T extends ControllerState> {
|
|||||||
return clean;
|
return clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTick(Minecraft minecraft) {
|
|
||||||
imitateVanillaClick();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerModdedKeybinds() {
|
private void registerModdedKeybinds() {
|
||||||
for (KeyMapping keyMapping : KeyBindingRegistryImplAccessor.getCustomKeys()) {
|
for (KeyMapping keyMapping : KeyBindingRegistryImplAccessor.getCustomKeys()) {
|
||||||
if (EXCLUDED_VANILLA_BINDS.contains(keyMapping))
|
if (EXCLUDED_VANILLA_BINDS.contains(keyMapping))
|
||||||
@ -538,8 +539,6 @@ public class ControllerBindings<T extends ControllerState> {
|
|||||||
// must set field directly to avoid ToggleKeyMapping breaking things
|
// must set field directly to avoid ToggleKeyMapping breaking things
|
||||||
accessor.setIsDown(!accessor.getIsDown());
|
accessor.setIsDown(!accessor.getIsDown());
|
||||||
}
|
}
|
||||||
} else if (!override.keyMapping().isDown()) {
|
|
||||||
KeyMapping.set(vanillaKeyCode, binding.held());
|
|
||||||
}
|
}
|
||||||
if (binding.justPressed())
|
if (binding.justPressed())
|
||||||
KeyMapping.click(vanillaKeyCode);
|
KeyMapping.click(vanillaKeyCode);
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package dev.isxander.controlify.bindings;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.event.Event;
|
||||||
|
import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
|
|
||||||
|
public interface InputHandledEvent {
|
||||||
|
void onInputHandled();
|
||||||
|
|
||||||
|
Event<InputHandledEvent> EVENT = EventFactory.createArrayBacked(InputHandledEvent.class, (listeners) -> () -> {
|
||||||
|
for (InputHandledEvent listener : listeners) {
|
||||||
|
listener.onInputHandled();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package dev.isxander.controlify.bindings;
|
||||||
|
|
||||||
|
import dev.isxander.controlify.api.bind.ControllerBinding;
|
||||||
|
|
||||||
|
public interface KeyMappingOverrideHolder {
|
||||||
|
void controlify$addOverride(ControllerBinding binding);
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package dev.isxander.controlify.mixins.feature.bind;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
||||||
|
import dev.isxander.controlify.api.bind.ControllerBinding;
|
||||||
|
import dev.isxander.controlify.bindings.KeyMappingOverrideHolder;
|
||||||
|
import net.minecraft.client.KeyMapping;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mixin(KeyMapping.class)
|
||||||
|
public class KeyMappingMixin implements KeyMappingOverrideHolder {
|
||||||
|
@Unique private final List<ControllerBinding> overrides = new ArrayList<>();
|
||||||
|
|
||||||
|
@ModifyReturnValue(method = "isDown", at = @At("RETURN"))
|
||||||
|
private boolean injectOverrideState(boolean keyMappingState) {
|
||||||
|
return keyMappingState || overrides.stream().anyMatch(override -> override.override() != null && override.override().toggleable().getAsBoolean() && override.held());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void controlify$addOverride(ControllerBinding binding) {
|
||||||
|
this.overrides.add(binding);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package dev.isxander.controlify.mixins.feature.bind;
|
||||||
|
|
||||||
|
import dev.isxander.controlify.bindings.InputHandledEvent;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(Minecraft.class)
|
||||||
|
public class MinecraftMixin {
|
||||||
|
// KeyboardHandler and MouseHandler run input events through Minecraft#execute,
|
||||||
|
// which is polled by the injection point below. Cannot be done in normal tick event
|
||||||
|
// as that could run up to 10 times per frame depending on framerate.
|
||||||
|
@Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;runAllTasks()V", shift = At.Shift.AFTER))
|
||||||
|
private void onTasksExecuted(boolean tick, CallbackInfo ci) {
|
||||||
|
InputHandledEvent.EVENT.invoker().onInputHandled();
|
||||||
|
}
|
||||||
|
}
|
@ -36,6 +36,8 @@
|
|||||||
"feature.accessibility.LocalPlayerMixin",
|
"feature.accessibility.LocalPlayerMixin",
|
||||||
"feature.autoswitch.ToastComponentAccessor",
|
"feature.autoswitch.ToastComponentAccessor",
|
||||||
"feature.bind.KeyMappingAccessor",
|
"feature.bind.KeyMappingAccessor",
|
||||||
|
"feature.bind.KeyMappingMixin",
|
||||||
|
"feature.bind.MinecraftMixin",
|
||||||
"feature.bind.ToggleKeyMappingAccessor",
|
"feature.bind.ToggleKeyMappingAccessor",
|
||||||
"feature.chatkbheight.ChatComponentMixin",
|
"feature.chatkbheight.ChatComponentMixin",
|
||||||
"feature.chatkbheight.ChatScreenMixin",
|
"feature.chatkbheight.ChatScreenMixin",
|
||||||
|
Reference in New Issue
Block a user