Skip to content
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.legacyfabric:yarn:${project.minecraft_version}+build.mcp"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.13.3'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

// task for downloading KillTheRng
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ public static Object fireEvent(Class<? extends EventListenerRegistry.EventBase>
// Iterate through all methods
for (Method method : methodsInListener) {

// Check if the current method has the same name as the method we are looking
// for
// Check if the current method has the same name as the method we are looking for
if (!checkName(method, methodToFind.getName())) {
continue;
}
Expand All @@ -252,7 +251,9 @@ public static Object fireEvent(Class<? extends EventListenerRegistry.EventBase>
toThrow = null; // Reset toThrow as the correct method was found
method.setAccessible(true);
try {
returnValue = method.invoke(eventListener, eventParams); // Call the method
Object newReturnValue = method.invoke(eventListener, eventParams); // Call the method
if (newReturnValue != null)
returnValue = newReturnValue;
} catch (IllegalAccessException | InvocationTargetException e) {
throw new EventException(eventClass, e);
} catch (IllegalArgumentException e) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/minecrafttas/tasmod/TASmodClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ private void registerEventListeners() {
EventListenerRegistry.register(TASmodAPIRegistry.PLAYBACK_FILE_COMMAND);
EventListenerRegistry.register(new LoggerMarkers());
EventListenerRegistry.register(savestateHandlerClient);

EventListenerRegistry.register(virtual.interpolationHandler);
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/minecrafttas/tasmod/events/EventClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.minecrafttas.mctcommon.events.EventListenerRegistry.EventBase;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;

/**
* TASmod specific events fired on the client side
Expand All @@ -22,6 +23,17 @@ public static interface EventDrawHotbar extends EventBase {
public void onDrawHotbar();
}

/**
* Fired when a screen in a gui is drawn
*/
@FunctionalInterface
public static interface EventDrawScreen extends EventBase {
/**
* Fired when a screen in a gui is drawn
*/
public void onDrawScreen(GuiScreen screen, int xCoordinate, int yCoordinate);
}

/**
* Fired when drawing something on screen. Ignores F1
*/
Expand Down
66 changes: 40 additions & 26 deletions src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
import com.minecrafttas.tasmod.TASmod;
import com.minecrafttas.tasmod.TASmodClient;
import com.minecrafttas.tasmod.events.EventClient.EventDrawHotbar;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
import com.minecrafttas.tasmod.playback.filecommands.builtin.DesyncMonitorFileCommandExtension;
import com.minecrafttas.tasmod.virtual.VirtualInput;
import com.minecrafttas.tasmod.virtual.VirtualInterpolationHandler.MouseInterpolation;
import com.mojang.realmsclient.gui.ChatFormatting;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextFormatting;

/**
* The info hud is a hud that is always being rendered ontop of the screen, it can show some stuff such as coordinates, etc.,
Expand Down Expand Up @@ -378,13 +382,25 @@ public boolean checkInit() {
}
}));

// title = "cursor";
// y += 14;
// if (configuration.getProperty(title + "_x", "err").equals("err")) setDefaults(title, y);
// lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> {
// if (Minecraft.getMinecraft().currentScreen == this) return "Mouse Position";
// return String.format("Mouse Cursor: " + TASmodClient.virtual.getNextMouse().getPath().get(0).cursorX + " " + TASmodClient.virtual.getNextMouse().getPath().get(0).cursorY);
// })); TODO Remove?
title = "cursor";
y += 14;
if (configuration.getProperty(title + "_x", "err").equals("err"))
setDefaults(title, y);
lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title
+ "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> {
if (Minecraft.getMinecraft().currentScreen == this)
return "Mouse Position";

MouseInterpolation mouseInterpolation = TASmodClient.virtual.interpolationHandler.getInterpolatedMouseCursor(0, false);
Integer xCursor = mouseInterpolation.getX();
Integer yCursor = mouseInterpolation.getY();

if (Minecraft.getMinecraft().currentScreen != null)
return String.format("Mouse Cursor: %s %s", xCursor == null ? "null" : xCursor, yCursor == null ? "null" : yCursor);
else
return "Mouse Cursor: 0 0";

}));

// title = "trajectories";
// y += 14;
Expand Down Expand Up @@ -537,29 +553,27 @@ private void drawRectWithText(String text, int x, int y, boolean rect) {
}

private String keystrokes() {
boolean isPlayingBack = TASmodClient.controller.isPlayingback();
VirtualInput virtual = TASmodClient.virtual;
PlaybackControllerClient controller = TASmodClient.controller;

String out1 = "" + ChatFormatting.WHITE;
for (String mouse : TASmodClient.virtual.getCurrentMousePresses()) {
out1 = out1.concat(mouse + " ");
}
if (Display.isActive() || TASmodClient.controller.isPlayingback()) {
out1 = out1.concat("" + ChatFormatting.GREEN);
for (String mouse : TASmodClient.virtual.getNextMousePresses()) {
out1 = out1.concat(mouse + " ");
}
}
String currentMousePresses = String.join(" ", virtual.getCurrentMousePresses());

String out2 = "" + ChatFormatting.WHITE;
for (String key : TASmodClient.virtual.getCurrentKeyboardPresses()) {
out2 = out2.concat(key + " ");
String nextMousePresses = "";
if (Display.isActive() || isPlayingBack) {
List<String> mousePresses = isPlayingBack ? controller.getNextMousePresses() : virtual.getNextMousePresses();
nextMousePresses = String.join(" ", mousePresses);
}
if (Display.isActive() || TASmodClient.controller.isPlayingback()) {
out2 = out2.concat("" + ChatFormatting.GREEN);
for (String key : TASmodClient.virtual.getNextKeyboardPresses()) {
out2 = out2.concat(key + " ");
}

String currentKeyboardPresses = String.join(" ", TASmodClient.virtual.getCurrentKeyboardPresses());

String nextKeyboardPresses = "";
if (Display.isActive() || isPlayingBack) {
List<String> keyboardPresses = isPlayingBack ? controller.getNextKeyboardPresses() : virtual.getNextKeyboardPresses();
nextKeyboardPresses = String.join(" ", keyboardPresses);
}
return out1 + out2;

return String.format("%s%s %s%s %s%s %s%s", TextFormatting.WHITE, currentMousePresses, TextFormatting.GREEN, nextMousePresses, TextFormatting.WHITE, currentKeyboardPresses, TextFormatting.GREEN, nextKeyboardPresses);
}

private Pair<Integer, Integer> getScreenOffset(int x, int y, InfoLabel label) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.minecrafttas.tasmod.mixin.playbackhooks;

import org.apache.commons.lang3.tuple.Triple;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -11,11 +10,14 @@

import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef;
import com.llamalad7.mixinextras.sugar.ref.LocalIntRef;
import com.minecrafttas.mctcommon.events.EventListenerRegistry;
import com.minecrafttas.tasmod.TASmodClient;
import com.minecrafttas.tasmod.events.EventClient.EventDrawHotbarAlways;
import com.minecrafttas.tasmod.util.Ducks.SubtickDuck;
import com.minecrafttas.tasmod.virtual.VirtualInput;
import com.minecrafttas.tasmod.virtual.VirtualInterpolationHandler.CameraInterpolation;
import com.minecrafttas.tasmod.virtual.VirtualInterpolationHandler.MouseInterpolation;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
Expand Down Expand Up @@ -193,21 +195,31 @@ public void playback_updateOverlay(CallbackInfo ci) {
EventListenerRegistry.fireEvent(EventDrawHotbarAlways.class);
}

@Redirect(method = "updateCameraAndRender", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getX()I", remap = false))
public int redirect_updateCameraAndRendererX(@Share(value = "interpolatedY") LocalIntRef shared) {
MouseInterpolation interpolated = TASmodClient.virtual.interpolationHandler.getInterpolatedMouseCursor(Minecraft.getMinecraft().timer.renderPartialTicks, TASmodClient.controller.isPlayingback());
shared.set(interpolated.getY());
return interpolated.getX();
}

@Redirect(method = "updateCameraAndRender", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getY()I", remap = false))
public int redirect_updateCameraAndRendererY(@Share(value = "interpolatedY") LocalIntRef shared) {
return shared.get();
}

/**
* Turns the camera via GLStateManager
* @param pitch The pi
* @param pitch The pitch
* @param yaw The yaw
* @see com.minecrafttas.tasmod.virtual.VirtualInput.VirtualCameraAngleInput#getInterpolatedState(float, float, float, boolean)
* @see com.minecrafttas.tasmod.virtual.VirtualInterpolationHandler#getInterpolatedState(float, float, float, boolean)
* @return The redirected yaw
*/
private float redirectCam(float pitch, float yaw) {
Triple<Float, Float, Float> interpolated = TASmodClient.virtual.CAMERA_ANGLE.getInterpolatedState(Minecraft.getMinecraft().timer.renderPartialTicks, pitch, yaw, TASmodClient.controller.isPlayingback());
float pitch2 = interpolated.getLeft();
float yaw2 = interpolated.getMiddle();
CameraInterpolation interpolated = TASmodClient.virtual.interpolationHandler.getInterpolatedState(Minecraft.getMinecraft().timer.renderPartialTicks, pitch, yaw, TASmodClient.controller.isPlayingback());
float pitch2 = interpolated.getPitch();
float yaw2 = interpolated.getYaw();
// Update pitch
GlStateManager.rotate(pitch2, 1.0f, 0.0f, 0.0f);
// Update roll
GlStateManager.rotate(interpolated.getRight(), 0.0f, 0.0f, 1.0f);
// Update yaw
return yaw2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.minecrafttas.mctcommon.events.EventListenerRegistry;
import com.minecrafttas.tasmod.TASmodClient;
import com.minecrafttas.tasmod.events.EventClient.EventDrawScreen;
import com.minecrafttas.tasmod.util.Ducks.GuiScreenDuck;
import com.minecrafttas.tasmod.virtual.VirtualInput;
import com.minecrafttas.tasmod.virtual.event.VirtualKeyboardEvent;
Expand Down Expand Up @@ -103,6 +107,11 @@ private static boolean redirectIsAltKeyDown(int i) {

// =====================================================================================================================================

@Inject(method = "drawScreen", at = @At("HEAD"))
private void injectDrawScreen(int i, int j, float f, CallbackInfo ci) {
EventListenerRegistry.fireEvent(EventDrawScreen.class, (GuiScreen) (Object) this, i, j);
}

@Shadow
private int width;

Expand Down
Loading