Skip to content

Commit

Permalink
fine
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Jan 1, 2024
1 parent 8ef818c commit bc6ffc4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
20 changes: 11 additions & 9 deletions src/main/java/net/krlite/it_follows/ItFollows.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package net.krlite.it_follows;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.client.gui.widget.CyclingButtonWidget;
import net.minecraft.client.gui.widget.PressableWidget;
import net.minecraft.util.ActionResult;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector2d;
import org.joml.Vector2i;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;
import java.util.function.Supplier;

public class ItFollows implements ModInitializer {
public static final String NAME = "It Follows!", ID = "it-follows";
public static final Logger LOGGER = LoggerFactory.getLogger(ID);

@Nullable
private static PressableWidget GUI_SCALE_WIDGET = null;
@Nullable
private static Vector2i BUTTON_POS = null;
private static Supplier<Vector2i> WIDGET_POS_SUPPLIER = null;

@Override
public void onInitialize() {
Expand All @@ -28,13 +28,15 @@ public static void guiScaleWidget(PressableWidget widget) {
GUI_SCALE_WIDGET = widget;
}

public static @Nullable Vector2i buttonPos() {
return BUTTON_POS;
public static @Nullable Vector2i widgetPos() {
if (WIDGET_POS_SUPPLIER != null) {
return WIDGET_POS_SUPPLIER.get();
} else return null;
}

public static void buttonPos(PressableWidget widget, int x, int y) {
public static void widgetPos(PressableWidget widget, Supplier<Vector2i> supplier) {
if (widget.equals(GUI_SCALE_WIDGET)) {
BUTTON_POS = new Vector2i(x, y);
WIDGET_POS_SUPPLIER = supplier;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.gui.widget.CyclingButtonWidget;
import net.minecraft.client.gui.widget.PressableWidget;
import net.minecraft.text.Text;
import org.joml.Vector2i;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -17,6 +18,6 @@ public CyclingButtonWidgetMixin(int i, int j, int k, int l, Text text) {

@Inject(method = "cycle", at = @At("HEAD"))
private void cycleHead(int amount, CallbackInfo ci) {
ItFollows.buttonPos(this, getX(), getY());
ItFollows.widgetPos(this, () -> new Vector2i(getX() + getWidth() / 2, getY() + getHeight() / 2));
}
}
3 changes: 2 additions & 1 deletion src/main/java/net/krlite/it_follows/mixin/MouseMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public abstract class MouseMixin {

@Inject(method = "onResolutionChanged", at = @At("RETURN"))
private void onResolutionChanged(CallbackInfo ci) {
Vector2i pos = ItFollows.buttonPos();
Vector2i pos = ItFollows.widgetPos();
if (pos != null) {
System.out.println(pos);
x = pos.x();
y = pos.y();
InputUtil.setCursorParameters(client.getWindow().getHandle(), 212993, x, y);
Expand Down

0 comments on commit bc6ffc4

Please sign in to comment.