-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed movement in screen with MixinExtras
- Loading branch information
1 parent
5b88335
commit fd96777
Showing
8 changed files
with
51 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/me/roundaround/armorstands/ArmorStandsPreLaunch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/me/roundaround/armorstands/mixin/HandledScreenMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
src/main/java/me/roundaround/armorstands/mixin/KeyboardMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters