Skip to content

Commit

Permalink
Update to 24w13a
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Mar 28, 2024
1 parent 25e5cca commit ecbf95b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 43 deletions.
35 changes: 7 additions & 28 deletions src/main/java/net/wurstclient/mixin/ChatHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.MinecraftClient;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;

import net.minecraft.client.gui.hud.ChatHud;
import net.minecraft.client.gui.hud.ChatHudLine;
import net.minecraft.client.gui.hud.MessageIndicator;
Expand All @@ -33,16 +35,14 @@ public class ChatHudMixin
@Shadow
@Final
private List<ChatHudLine.Visible> visibleMessages;
@Shadow
@Final
private MinecraftClient client;

@Inject(at = @At("HEAD"),
method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V",
cancellable = true)
private void onAddMessage(Text message,
@Nullable MessageSignatureData signature,
@Nullable MessageIndicator indicator, CallbackInfo ci)
@Nullable MessageIndicator indicatorDontUse, CallbackInfo ci,
@Local LocalRef<MessageIndicator> indicator)
{
ChatInputEvent event = new ChatInputEvent(message, visibleMessages);

Expand All @@ -54,28 +54,7 @@ private void onAddMessage(Text message,
}

message = event.getComponent();
indicator = WurstClient.INSTANCE.getOtfs().noChatReportsOtf
.modifyIndicator(message, signature, indicator);

shadow$logChatMessage(message, indicator);
shadow$addMessage(message, signature, client.inGameHud.getTicks(),
indicator, false);

ci.cancel();
}

@Shadow
private void shadow$logChatMessage(Text message,
@Nullable MessageIndicator indicator)
{

}

@Shadow
private void shadow$addMessage(Text message,
@Nullable MessageSignatureData signature, int ticks,
@Nullable MessageIndicator indicator, boolean refresh)
{

indicator.set(WurstClient.INSTANCE.getOtfs().noChatReportsOtf
.modifyIndicator(message, signature, indicator.get()));
}
}
30 changes: 17 additions & 13 deletions src/main/java/net/wurstclient/mixin/ChatScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,36 @@ protected void onInit(CallbackInfo ci)
public void onSendMessage(String message, boolean addToHistory,
CallbackInfo ci)
{
// Ignore empty messages just like vanilla
if((message = normalize(message)).isEmpty())
return;

// Create and fire the chat output event
ChatOutputEvent event = new ChatOutputEvent(message);
EventManager.fire(event);

if(event.isCancelled())
{
ci.cancel();
// If the event hasn't been modified or cancelled,
// let the vanilla method handle the message
boolean cancelled = event.isCancelled();
if(!cancelled && !event.isModified())
return;
}

if(!event.isModified())
return;
// Otherwise, cancel the vanilla method and handle the message here
ci.cancel();

// Add the message to history, even if it was cancelled
// Otherwise the up/down arrows won't work correctly
String newMessage = event.getMessage();
if(addToHistory)
client.inGameHud.getChatHud().addToMessageHistory(newMessage);

if(newMessage.startsWith("/"))
client.player.networkHandler
.sendChatCommand(newMessage.substring(1));
else
client.player.networkHandler.sendChatMessage(newMessage);

ci.cancel();
// If the event isn't cancelled, send the modified message
if(!cancelled)
if(newMessage.startsWith("/"))
client.player.networkHandler
.sendChatCommand(newMessage.substring(1));
else
client.player.networkHandler.sendChatMessage(newMessage);
}

@Shadow
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 @@ -30,8 +30,8 @@

"depends": {
"fabricloader": ">=0.15.7",
"fabric-api": ">=0.96.12",
"minecraft": "~1.20.5-alpha.24.12.a",
"fabric-api": ">=0.96.13",
"minecraft": "~1.20.5-alpha.24.13.a",
"java": ">=17"
},
"suggests": {
Expand Down

0 comments on commit ecbf95b

Please sign in to comment.