Skip to content

Commit

Permalink
Update to 1.20-pre6
Browse files Browse the repository at this point in the history
  • Loading branch information
Roundaround committed May 28, 2023
1 parent 191ac4e commit 5b88335
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 17 deletions.
9 changes: 9 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
plugins {
id("roundalib") version "0.3.6"
}

repositories {
maven("https://jitpack.io")
}

dependencies {
implementation("com.github.LlamaLad7:MixinExtras:0.1.1")
annotationProcessor("com.github.LlamaLad7:MixinExtras:0.1.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.util.Optional;

public abstract class AbstractArmorStandScreen extends HandledScreen<ArmorStandScreenHandler>
implements HasArmorStand, HasMessageRenderer {
implements HasArmorStand, HasMessageRenderer, PassesEventsThrough {
protected static final int SCREEN_EDGE_PAD = 4;
protected static final int BETWEEN_PAD = 2;
protected static final int NAV_BUTTON_BOTTOM_PADDING = 1;
Expand All @@ -55,6 +55,7 @@ public abstract class AbstractArmorStandScreen extends HandledScreen<ArmorStandS
protected NavigationButtonWidget activeButton;
protected boolean supportsUndoRedo = false;
protected boolean utilizesInventory = false;
protected boolean passEvents = true;
protected long currentSyncDelay = 0;

private boolean cursorLocked = false;
Expand All @@ -65,9 +66,6 @@ protected AbstractArmorStandScreen(ArmorStandScreenHandler handler, Text title)
this.armorStand = handler.getArmorStand();

this.messageRenderer = new MessageRenderer(this);

// TODO: Find an alternative to this
this.passEvents = true;
}

public abstract ScreenType getScreenType();
Expand All @@ -87,6 +85,11 @@ public MessageRenderer getMessageRenderer() {
return this.messageRenderer;
}

@Override
public boolean shouldPassEvents() {
return this.passEvents;
}

@Override
public boolean shouldPause() {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package me.roundaround.armorstands.client.gui.screen;

public interface PassesEventsThrough {
boolean shouldPassEvents();
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package me.roundaround.armorstands.mixin;

import me.roundaround.armorstands.client.gui.screen.AbstractArmorStandScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
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.CallbackInfo;

import me.roundaround.armorstands.client.gui.screen.AbstractArmorStandScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.util.math.MatrixStack;

@Mixin(InGameHud.class)
public abstract class InGameHudMixin {
@Shadow
private MinecraftClient client;

@Inject(method = "render", at = @At(value = "HEAD"), cancellable = true)
private void render(MatrixStack matrixStack, float delta, CallbackInfo info) {
private void render(DrawContext drawContext, float delta, CallbackInfo info) {
if (client.currentScreen instanceof AbstractArmorStandScreen) {
info.cancel();
}
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/me/roundaround/armorstands/mixin/KeyboardMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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
)
)
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!");
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package me.roundaround.armorstands.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import me.roundaround.armorstands.client.gui.screen.PassesEventsThrough;
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.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import me.roundaround.armorstands.client.gui.screen.AbstractArmorStandScreen;
Expand All @@ -24,4 +27,30 @@ private void hasOutline(Entity entity, CallbackInfoReturnable<Boolean> info) {

info.setReturnValue(((AbstractArmorStandScreen) currentScreen).shouldHighlight(entity));
}

// @formatter:off
@ModifyExpressionValue(
method = "tick",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;"
),
slice = @Slice(
from = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/hud/InGameHud;resetDebugHudChunk()V"
),
to = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/MinecraftClient;handleInputEvents()V"
)
)
)
// @formatter:on
private Screen modifyCurrentScreen(Screen screen) {
return
screen instanceof PassesEventsThrough && ((PassesEventsThrough) screen).shouldPassEvents()
? null
: screen;
}
}
25 changes: 21 additions & 4 deletions src/main/java/me/roundaround/armorstands/mixin/MouseMixin.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package me.roundaround.armorstands.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import me.roundaround.armorstands.client.gui.screen.AbstractArmorStandScreen;
import me.roundaround.armorstands.client.gui.screen.PassesEventsThrough;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.Mouse;
import net.minecraft.client.gui.screen.Screen;
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;

import me.roundaround.armorstands.client.gui.screen.AbstractArmorStandScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.Mouse;

@Mixin(Mouse.class)
public abstract class MouseMixin {
@Shadow
Expand All @@ -21,4 +23,19 @@ public void isCursorLocked(CallbackInfoReturnable<Boolean> info) {
info.setReturnValue(((AbstractArmorStandScreen) client.currentScreen).isCursorLocked());
}
}

@ModifyExpressionValue(
method = "onMouseButton",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
ordinal = 3
)
)
private Screen modifyCurrentScreen(Screen screen) {
return
screen instanceof PassesEventsThrough && ((PassesEventsThrough) screen).shouldPassEvents()
? null
: screen;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract class SliderWidgetMixin {
@ModifyArg(
method = "renderButton", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/widget/SliderWidget;drawNineSlicedTexture(Lnet/minecraft/client/util/math/MatrixStack;IIIIIIIIII)V",
target = "Lnet/minecraft/client/gui/DrawContext;drawNineSlicedTexture(Lnet/minecraft/util/Identifier;IIIIIIIIII)V",
ordinal = 1
), index = 4
)
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/armorstands.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"InGameHudAccessor",
"InGameHudMixin",
"KeyBindingAccessor",
"KeyboardMixin",
"LivingEntityMixin",
"MinecraftClientMixin",
"MouseAccessor",
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
],
"depends": {
"fabricloader": ">=0.13.3",
"fabric": "*",
"minecraft": "1.19.x",
"fabric-api": "*",
"minecraft": ">=1.20-beta.1 <1.21",
"java": ">=17"
}
}

0 comments on commit 5b88335

Please sign in to comment.