Skip to content

Commit

Permalink
修复游戏内计算器相关问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Nov 10, 2024
1 parent a8a36b4 commit 9743dff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import dev.dubhe.gugle.carpet.tools.TriConsumer;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.network.protocol.game.ServerboundChatPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.FilteredText;
Expand All @@ -26,7 +25,7 @@ abstract class ServerGamePacketListenerImplMixin {

@Inject(method = "method_45064", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;)V", shift = At.Shift.AFTER))
private void handleChat(PlayerChatMessage playerChatMessage, Component component, FilteredText filteredText, CallbackInfo ci) {
this.gca$handleChat(GcaSetting.simpleInGameCalculator, "==", component, SimpleInGameCalculator::handleChat);
this.gca$handleChat(GcaSetting.simpleInGameCalculator, "==", component, (server, player, msg) -> SimpleInGameCalculator.handleChat(server, msg));
this.gca$handleChat(GcaSetting.fastPingFriend, "@ ", component, FastPingFriend::handleChat);
this.gca$handleChat(GcaSetting.fastPingFriend, "@@ ", component, FastPingFriend::handleChatUrgent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import org.jetbrains.annotations.NotNull;
import org.nfunk.jep.JEP;

public class SimpleInGameCalculator {
public static void handleChat(@NotNull MinecraftServer server, @NotNull ServerPlayer player, @NotNull String msg) {
public static void handleChat(@NotNull MinecraftServer server, @NotNull String msg) {
if (msg.startsWith("=")) return;
server.getPlayerList().broadcastSystemMessage(SimpleInGameCalculator.calculate(msg), false);
}

Expand All @@ -21,12 +21,12 @@ public static void handleChat(@NotNull MinecraftServer server, @NotNull ServerPl
jep.addStandardConstants();
// 添加虚数
jep.addComplex();
jep.parseExpression(expression);
if (!jep.hasError()) {
jep.parseExpression(expression);
double result = jep.getValue();
return Component.literal("=%f".formatted(result)).withStyle(ChatFormatting.DARK_GRAY);
} else {
return Component.literal("Illegal expression");
return Component.literal("Illegal expression: %s".formatted(jep.getErrorInfo()));
}
}
}

0 comments on commit 9743dff

Please sign in to comment.