1
0
forked from Clones/Controlify

🐛 Fix vanilla overrides triggering more than once

This commit is contained in:
isXander
2023-07-11 08:11:28 +01:00
parent 1ab42afdbb
commit f9c93c8ab1
4 changed files with 9 additions and 43 deletions

View File

@ -410,10 +410,11 @@ public class ControllerBindings<T extends ControllerState> {
registerModdedKeybinds();
// key events are executed in Minecraft#execute, which run at runTick.runAllTasks()
// which this event runs directly after. A normal tick could run multiple
// times per frame, so you could get double clicks if lagging.
InputHandledEvent.EVENT.register(this::imitateVanillaClick);
ControlifyEvents.CONTROLLER_STATE_UPDATE.register(ctrl -> {
if (ctrl == this.controller) {
this.imitateVanillaClick();
}
});
ControlifyEvents.INPUT_MODE_CHANGED.register(mode -> KeyMapping.releaseAll());
}
@ -540,8 +541,9 @@ public class ControllerBindings<T extends ControllerState> {
accessor.setIsDown(!accessor.getIsDown());
}
}
if (binding.justPressed())
if (binding.justPressed()) {
KeyMapping.click(vanillaKeyCode);
}
}
}

View File

@ -1,14 +0,0 @@
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();
}
});
}

View File

@ -1,19 +0,0 @@
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();
}
}