Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
[skip ci] Merge pull request #43 from mysticdrew/chat-mixin-fix
Browse files Browse the repository at this point in the history
fix mod conflicts with chat mixins
  • Loading branch information
DarkKronicle authored Apr 24, 2022
2 parents bd083a3 + 4c7ccd1 commit 6e38281
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
/*
* Copyright (C) 2021 DarkKronicle
* Copyright (C) 2021-2022 DarkKronicle
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package io.github.darkkronicle.advancedchatcore.mixin;

import fi.dy.masa.malilib.gui.GuiBase;
import io.github.darkkronicle.advancedchatcore.chat.AdvancedChatScreen;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import org.spongepowered.asm.mixin.Final;
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;
Expand All @@ -24,15 +20,6 @@
@Mixin(ChatScreen.class)
public class MixinChatScreen {

@Final @Shadow private String originalChatText;

@Inject(method = "init", at = @At("HEAD"), cancellable = true)
public void chatInit(CallbackInfo ci) {
// Open the AdvancedChatScreen instead
GuiBase.openGui(new AdvancedChatScreen(this.originalChatText));
ci.cancel();
}

@Inject(method = "addScreenNarrations", at = @At("HEAD"), cancellable = true)
public void screenNarrations(NarrationMessageBuilder builder, CallbackInfo ci) {
// Don't cause random narrations to happen/crashes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
/*
* Copyright (C) 2021 DarkKronicle
* Copyright (C) 2021-2022 DarkKronicle
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package io.github.darkkronicle.advancedchatcore.mixin;

import io.github.darkkronicle.advancedchatcore.chat.AdvancedChatScreen;
import io.github.darkkronicle.advancedchatcore.chat.AdvancedSleepingChatScreen;
import io.github.darkkronicle.advancedchatcore.chat.ChatHistory;
import io.github.darkkronicle.advancedchatcore.config.ConfigStorage;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import org.jetbrains.annotations.Nullable;
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Environment(EnvType.CLIENT)
@Mixin(MinecraftClient.class)
Expand All @@ -29,4 +35,18 @@ public void onDisconnect(Screen screen, CallbackInfo ci) {
ChatHistory.getInstance().clearAll();
}
}

@ModifyArgs(method = "openChatScreen(Ljava/lang/String;)V",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V", ordinal = 0))
public void openChatScreen(Args args, String text) {
args.set(0, new AdvancedChatScreen(text));
}

@ModifyArg(method = "tick()V",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V", ordinal = 1))
public Screen openSleepingChatScreen(@Nullable Screen screen) {
return new AdvancedSleepingChatScreen();
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
/*
* Copyright (C) 2021 DarkKronicle
* Copyright (C) 2021-2022 DarkKronicle
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package io.github.darkkronicle.advancedchatcore.mixin;

import fi.dy.masa.malilib.gui.GuiBase;
import io.github.darkkronicle.advancedchatcore.chat.AdvancedSleepingChatScreen;
import io.github.darkkronicle.advancedchatcore.chat.AdvancedChatScreen;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.SleepingChatScreen;
import org.jetbrains.annotations.Nullable;
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;
import org.spongepowered.asm.mixin.injection.ModifyArg;

@Environment(EnvType.CLIENT)
@Mixin(SleepingChatScreen.class)
public class MixinSleepingChatScreen {
public class MixinSleepingChatScreen extends ChatScreen {

@Inject(method = "init", at = @At("HEAD"), cancellable = true)
public void sleepInit(CallbackInfo ci) {
// Open the Advanced sleeping screen
GuiBase.openGui(new AdvancedSleepingChatScreen());
ci.cancel();
public MixinSleepingChatScreen() {
super("");
}

@ModifyArg(method = "closeChatIfEmpty",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V", ordinal = 1))
public Screen openSleepingChatScreen(@Nullable Screen screen) {

return new AdvancedChatScreen(this.chatField.getText());
}
}

0 comments on commit 6e38281

Please sign in to comment.