Skip to content

Commit

Permalink
Fixed movement in screen with MixinExtras
Browse files Browse the repository at this point in the history
  • Loading branch information
Roundaround committed May 31, 2023
1 parent 5b88335 commit fd96777
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Roundaround's Armor Stands

<img src="https://img.shields.io/badge/Loader-Fabric-%23313e51?style=for-the-badge"/>
<img src="https://img.shields.io/badge/MC-1.19--1.19.4-%23313e51?style=for-the-badge"/>
<img src="https://img.shields.io/badge/MC-1.20%20|%201.19--1.19.4-%23313e51?style=for-the-badge"/>
<img src="https://img.shields.io/badge/Side-Client+Server-%23313e51?style=for-the-badge"/>

Place, pose, and dress armor stands with an easy-to-use UI.
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ repositories {
dependencies {
implementation("com.github.LlamaLad7:MixinExtras:0.1.1")
annotationProcessor("com.github.LlamaLad7:MixinExtras:0.1.1")
include("com.github.LlamaLad7:MixinExtras:0.1.1")
}
10 changes: 10 additions & 0 deletions src/main/java/me/roundaround/armorstands/ArmorStandsPreLaunch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package me.roundaround.armorstands;

import com.llamalad7.mixinextras.MixinExtrasBootstrap;
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint;

public class ArmorStandsPreLaunch implements PreLaunchEntrypoint {
public void onPreLaunch() {
MixinExtrasBootstrap.init();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,14 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
lockCursor();
return true;
case GLFW.GLFW_KEY_LEFT:
if (this.client.options.leftKey.matchesKey(keyCode, scanCode) && !Screen.hasControlDown()) {
if (!Screen.hasControlDown()) {
break;
}
playClickSound();
goToPreviousScreen();
return true;
case GLFW.GLFW_KEY_RIGHT:
if (this.client.options.rightKey.matchesKey(keyCode, scanCode) &&
!Screen.hasControlDown()) {
if (!Screen.hasControlDown()) {
break;
}
playClickSound();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package me.roundaround.armorstands.mixin;

import me.roundaround.armorstands.client.gui.screen.PassesEventsThrough;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
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.CallbackInfoReturnable;

@Mixin(HandledScreen.class)
public abstract class HandledScreenMixin extends Screen {
protected HandledScreenMixin() {
super(null);
}

@Inject(method = "keyPressed", at = @At(value = "HEAD"), cancellable = true)
public void keyPressed(
int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> info) {
if (this instanceof PassesEventsThrough passesEventsThrough &&
passesEventsThrough.shouldPassEvents()) {
info.setReturnValue(super.keyPressed(keyCode, scanCode, modifiers));
}
}
}
32 changes: 7 additions & 25 deletions src/main/java/me/roundaround/armorstands/mixin/KeyboardMixin.java
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
package me.roundaround.armorstands.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import me.roundaround.armorstands.ArmorStandsMod;
import me.roundaround.armorstands.client.gui.screen.AbstractArmorStandScreen;
import me.roundaround.armorstands.client.gui.screen.PassesEventsThrough;
import net.minecraft.client.Keyboard;
import net.minecraft.client.gui.screen.Screen;
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(Keyboard.class)
public class KeyboardMixin {
@ModifyExpressionValue(
method = "onKey",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
ordinal = 2
)
method = "onKey", at = @At(
value = "FIELD",
target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
ordinal = 2
)
)
private Screen modifyCurrentScreen(Screen screen) {
if (screen instanceof AbstractArmorStandScreen) {
ArmorStandsMod.LOGGER.info("We're in the armor stand screen!");
}
if (screen instanceof PassesEventsThrough && ((PassesEventsThrough) screen).shouldPassEvents()) {
ArmorStandsMod.LOGGER.info("We're in a screen that passes events through!");
}
return
screen instanceof PassesEventsThrough && ((PassesEventsThrough) screen).shouldPassEvents()
? null
: screen;
}

@Inject(method = "onKey", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/InputUtil;fromKeyCode(II)Lnet/minecraft/client/util/InputUtil$Key;", shift = At.Shift.AFTER))
private void afterScreenCheck(long window, int key, int scancode, int action, int modifiers, CallbackInfo info) {
ArmorStandsMod.LOGGER.info("We've made it!");
return screen instanceof PassesEventsThrough passesEventsThrough &&
passesEventsThrough.shouldPassEvents() ? null : screen;
}
}
1 change: 1 addition & 0 deletions src/main/resources/armorstands.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
"client": [
"ArmorStandEntityClientMixin",
"HandledScreenMixin",
"InGameHudAccessor",
"InGameHudMixin",
"KeyBindingAccessor",
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "armorstands",
"version": "${version}",
"name": "Armor Stands",
"description": "Place, pose, and dress armor stands with an easy-to-use UI.",
"description": "Place, pose, and dress armor stands with an easy-to-use UI.\n${library}",
"authors": [
"Roundaround"
],
Expand All @@ -16,6 +16,9 @@
"icon": "assets/armorstands/icon.png",
"environment": "*",
"entrypoints": {
"preLaunch": [
"me.roundaround.armorstands.ArmorStandsPreLaunch"
],
"client": [
"me.roundaround.armorstands.client.ArmorStandsClientMod"
],
Expand Down

0 comments on commit fd96777

Please sign in to comment.