Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions common/src/main/java/io/github/kurrycat/mpkmod/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import io.github.kurrycat.mpkmod.compatibility.API;
import io.github.kurrycat.mpkmod.compatibility.MCClasses.*;
import io.github.kurrycat.mpkmod.discord.DiscordRPC;
import io.github.kurrycat.mpkmod.events.Event;
import io.github.kurrycat.mpkmod.events.*;
import io.github.kurrycat.mpkmod.events.Event;
import io.github.kurrycat.mpkmod.gui.TickThread;
import io.github.kurrycat.mpkmod.gui.components.Component;
import io.github.kurrycat.mpkmod.gui.components.InputHistory;
Expand All @@ -19,7 +19,10 @@
import io.github.kurrycat.mpkmod.modules.MPKModule;
import io.github.kurrycat.mpkmod.modules.ModuleManager;
import io.github.kurrycat.mpkmod.ticks.TimingStorage;
import io.github.kurrycat.mpkmod.util.*;
import io.github.kurrycat.mpkmod.util.BoundingBox3D;
import io.github.kurrycat.mpkmod.util.ItrUtil;
import io.github.kurrycat.mpkmod.util.MathUtil;
import io.github.kurrycat.mpkmod.util.Vector2D;

import java.awt.*;
import java.util.ArrayList;
Expand Down Expand Up @@ -70,6 +73,8 @@ public void init() {
);

API.registerGUIScreen("options_gui", new OptionsGuiScreen());

API.registerKeyBinding("togglesprint", Minecraft::toggleSprint);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Minecraft {
public static String version;
public static WorldState worldState = WorldState.MENU;
public static PlayState playState = PlayState.ACTIVE;
public static boolean sprintToggled = false;

@InfoString.Getter
public static String getIp() {
Expand Down Expand Up @@ -109,13 +110,22 @@ public static boolean isF3Enabled() {
return Interface.get().map(Interface::isF3Enabled).orElse(false);
}

@InfoString.Getter
public static boolean isSprintToggled() {
return sprintToggled;
}

public static void toggleSprint() {
sprintToggled = !sprintToggled;
}


public enum WorldState {
MENU,
SINGLE_PLAYER,
MULTI_PLAYER;
}


public enum PlayState {
ACTIVE,
AFK;
Expand Down
6 changes: 0 additions & 6 deletions common/src/main/resources/assets/mpkmod/lang/en_US.lang

This file was deleted.

8 changes: 0 additions & 8 deletions common/src/main/resources/assets/mpkmod/lang/en_us.json

This file was deleted.

6 changes: 0 additions & 6 deletions common/src/main/resources/assets/mpkmod/lang/pl_pl.json

This file was deleted.

4 changes: 0 additions & 4 deletions common/src/main/resources/assets/mpkmod/lang/pl_pl.lang

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,32 @@
import io.github.kurrycat.mpkmod.util.Vector3D;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.Options;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.input.KeyEvent;
import net.minecraft.client.input.MouseButtonInfo;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.util.Util;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

import java.util.Map;

public class EventHandler {
private static final ButtonMSList timeQueue = new ButtonMSList();

/**
* @param keyInput The Minecraft {@link KeyEvent} object.
* @param input The Minecraft {@link KeyEvent} object.
* @param action The action, where 0 = unpressed, 1 = pressed, 2 = held.
*/
public void onKey(KeyEvent keyInput, int action) {
public void onKey(KeyEvent input, int action) {
Options options = Minecraft.getInstance().options;
long eventNanos = Util.getNanos();

InputConstants.Key inputKey = InputConstants.getKey(new KeyEvent(keyInput.key(), keyInput.scancode(), keyInput.modifiers()));
InputConstants.Key inputKey = InputConstants.getKey(new KeyEvent(input.key(), input.scancode(), input.modifiers()));

int[] keys = {
((KeyMappingAccessor) options.keyUp).getKey().getValue(),
Expand All @@ -45,7 +49,7 @@ public void onKey(KeyEvent keyInput, int action) {
};

for (int i = 0; i < keys.length; i++) {
if (keyInput.key() == keys[i]) {
if (input.key() == keys[i]) {
timeQueue.add(ButtonMS.of(ButtonMS.Button.values()[i], eventNanos, action == 1));
}
}
Expand All @@ -56,13 +60,56 @@ public void onKey(KeyEvent keyInput, int action) {
FunctionCompatibility.pressedButtons.remove(inputKey.getValue());
}

API.Events.onKeyInput(keyInput.key(), inputKey.getDisplayName().getString(), action == 1);
API.Events.onKeyInput(input.key(), inputKey.getDisplayName().getString(), action == 1);

if (action != 0) {
checkKeyBinding(input.key());
}
}

MPKMod.keyBindingMap.forEach((id, keyBinding) -> {
if (keyBinding.isDown()) {
API.Events.onKeybind(id);
public void onMouseMove(double x, double y, double dx, double dy) {
API.Events.onMouseInput(
io.github.kurrycat.mpkmod.util.Mouse.Button.NONE,
io.github.kurrycat.mpkmod.util.Mouse.State.NONE,
(int) x, (int) y, (int) dx, (int) dy,
0, System.nanoTime()
);
}

public void onMouseScroll(double vertical, double x, double y) {
API.Events.onMouseInput(
io.github.kurrycat.mpkmod.util.Mouse.Button.NONE,
io.github.kurrycat.mpkmod.util.Mouse.State.NONE,
(int) x, (int) y, 0, 0,
(int) vertical, System.nanoTime()
);
}

public void onMouseButton(MouseButtonInfo input, int action, double x, double y) {
API.Events.onMouseInput(
io.github.kurrycat.mpkmod.util.Mouse.Button.fromInt(input.button()),
input.button() == -1 ? io.github.kurrycat.mpkmod.util.Mouse.State.NONE :
(action == 1 ? io.github.kurrycat.mpkmod.util.Mouse.State.DOWN : io.github.kurrycat.mpkmod.util.Mouse.State.UP),
(int) x, (int) y, 0, 0,
0, System.nanoTime()
);

if (action == 1)
checkKeyBinding(input.button());
}

private void checkKeyBinding(int keyCode) {
if (Minecraft.getInstance().screen != null) return;

for (Map.Entry<String, KeyMapping> keyBindingEntry : MPKMod.keyBindingMap.entrySet()) {
InputConstants.Key boundKey = ((KeyMappingAccessor) keyBindingEntry.getValue()).getKey();
String keyBindId = keyBindingEntry.getKey();

if (boundKey.getValue() == keyCode) {
API.Events.onKeybind(keyBindId);
return;
}
});
}
}

public void onInGameOverlayRender(GuiGraphics drawContext, DeltaTracker renderTickCounter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.client.renderer.ShapeRenderer;
import net.minecraft.client.renderer.rendertype.RenderTypes;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.core.BlockPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
@Mixin(KeyboardHandler.class)
public class KeyboardHandlerMixin {
@Inject(method = "keyPress", at = @At(value = "RETURN"))
private void onKey(long window, int action, KeyEvent keyInput, CallbackInfo ci) {
if (keyInput.key() != -1) {
MPKMod.INSTANCE.eventHandler.onKey(keyInput, action);
private void onKey(long window, int action, KeyEvent input, CallbackInfo ci) {
if (input.key() != -1) {
MPKMod.INSTANCE.eventHandler.onKey(input, action);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.mixin;

import io.github.kurrycat.mpkmod.compatibility.API;
import io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.MPKMod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.MouseHandler;
import net.minecraft.client.input.MouseButtonInfo;
Expand All @@ -24,33 +25,19 @@ public class MouseHandlerMixin {
@Inject(method = "onMove", at = @At(value = "TAIL"))
private void onCursorPos(long window, double x, double y, CallbackInfo ci) {
if (window == Minecraft.getInstance().getWindow().handle()) {
API.Events.onMouseInput(
io.github.kurrycat.mpkmod.util.Mouse.Button.NONE,
io.github.kurrycat.mpkmod.util.Mouse.State.NONE,
(int) x, (int) y, (int) accumulatedDX, (int) -accumulatedDY,
0, System.nanoTime()
);
MPKMod.INSTANCE.eventHandler.onMouseMove(x, y, accumulatedDX, -accumulatedDY);
}
}

@Inject(method = "onScroll", at = @At(value = "TAIL"))
private void onMouseScroll(long window, double horizontal, double vertical, CallbackInfo ci) {
API.Events.onMouseInput(
io.github.kurrycat.mpkmod.util.Mouse.Button.NONE,
io.github.kurrycat.mpkmod.util.Mouse.State.NONE,
(int) xpos, (int) ypos, 0, 0,
(int) vertical, System.nanoTime()
);
MPKMod.INSTANCE.eventHandler.onMouseScroll(vertical, xpos, ypos);
}

@Inject(method = "onButton", at = @At(value = "TAIL"))
private void onMouseButton(long window, MouseButtonInfo input, int action, CallbackInfo ci) {
API.Events.onMouseInput(
io.github.kurrycat.mpkmod.util.Mouse.Button.fromInt(input.button()),
input.button() == -1 ? io.github.kurrycat.mpkmod.util.Mouse.State.NONE :
(action == 1 ? io.github.kurrycat.mpkmod.util.Mouse.State.DOWN : io.github.kurrycat.mpkmod.util.Mouse.State.UP),
(int) xpos, (int) ypos, 0, 0,
0, System.nanoTime()
);
if (input.button() != -1) {
MPKMod.INSTANCE.eventHandler.onMouseButton(input, action, xpos, ypos);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.kurrycat.mpkmod.compatibility.fabric_1_21_11.mixin;

import io.github.kurrycat.mpkmod.compatibility.MCClasses.Minecraft;
import net.minecraft.client.KeyMapping;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(KeyMapping.class)
public class ToggleSprintKeyMixin {
@Inject(method = "isDown", at = @At("HEAD"), cancellable = true)
private void sprintOverride(CallbackInfoReturnable<Boolean> cir) {
KeyMapping self = (KeyMapping) (Object) this;
KeyMapping sprintKey = net.minecraft.client.Minecraft.getInstance().options.keySprint;

if (self == sprintKey && Minecraft.isSprintToggled())
cir.setReturnValue(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"mpkmod.key.lb_gui.desc": "Open Landing Block GUI",
"mpkmod.key.lb_set.desc": "Set Landing Block",
"mpkmod.key.options_gui.desc": "Open Options GUI",
"mpkmod.key.togglesprint.desc": "Toggle Sprint",
"mpkmod.main_gui.title": "MPK Mod GUI",
"mpkmod.lb_gui.title": "Landing Block GUI"
}
3 changes: 2 additions & 1 deletion fabric-1.21.11/src/main/resources/mpkmod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"KeyMappingAccessor",
"KeyboardHandlerMixin",
"MinecraftMixin",
"MouseHandlerMixin"
"MouseHandlerMixin",
"ToggleSprintKeyMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
Expand All @@ -24,6 +25,8 @@
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;

import java.util.Map;

@SuppressWarnings("unused")
public class EventListener {
private static final ButtonMSList timeQueue = new ButtonMSList();
Expand All @@ -35,6 +38,12 @@ public void onEvent(InputEvent.KeyInputEvent event) {
String key = Keyboard.getKeyName(keyCode);
boolean pressed = Keyboard.getEventKeyState();

if (keyCode == 0) {
char c = Keyboard.getEventCharacter();
keyCode = 256 + c;
key = String.valueOf(c);
}

GameSettings gameSettings = Minecraft.getMinecraft().gameSettings;

int[] keys = {
Expand All @@ -54,11 +63,9 @@ public void onEvent(InputEvent.KeyInputEvent event) {

API.Events.onKeyInput(InputConstants.convert(keyCode), key, pressed);

MPKMod.keyBindingMap.forEach((id, keyBinding) -> {
if (keyBinding.isPressed()) {
API.Events.onKeybind(id);
}
});
if (pressed) {
checkKeyBinding(keyCode);
}
}

@SideOnly(Side.CLIENT)
Expand All @@ -70,6 +77,23 @@ public void onMouseEvent(MouseEvent event) {
event.getX(), event.getY(), event.getDx(), event.getDy(),
event.getDwheel(), event.getNanoseconds()
);

if (event.isButtonstate())
checkKeyBinding(event.getButton() - 100);
}

private void checkKeyBinding(int keyCode) {
if (Minecraft.getMinecraft().currentScreen != null) return;

for (Map.Entry<String, KeyBinding> keyBindingEntry : MPKMod.keyBindingMap.entrySet()) {
KeyBinding keyBinding = keyBindingEntry.getValue();
String keyBindingId = keyBindingEntry.getKey();

if (keyBinding.getKeyCode() == keyCode) {
API.Events.onKeybind(keyBindingId);
return;
}
}
}


Expand Down
Loading