Skip to content

Commit

Permalink
Change tooltip messages
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Jan 7, 2025
1 parent 1882ee8 commit b930270
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
29 changes: 8 additions & 21 deletions src/main/java/cn/zbx1425/projectme/client/ProjectMeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cn.zbx1425.projectme.entity.EntityProjection;
import cn.zbx1425.projectme.entity.EntityProjectionRenderer;
import com.mojang.brigadier.Command;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
Expand All @@ -28,36 +29,22 @@ public ProjectMeClient(IEventBus eventBus) {

public static class ForgeEventBusListener {

private static UUID peTargetUUID;
private static long peFirstInteractTime = -1;

@SubscribeEvent
public static void onPlayerInteractEntity(PlayerInteractEvent.EntityInteractSpecific event) {
if (!event.getEntity().level().isClientSide()) return;
if (event.getTarget() instanceof EntityProjection projection) {
if (System.currentTimeMillis() - peFirstInteractTime > 500) {
peTargetUUID = null;
peFirstInteractTime = -1;
}
if (!projection.getProjectingPlayer().equals(peTargetUUID)) {
peTargetUUID = projection.getProjectingPlayer();
peFirstInteractTime = System.currentTimeMillis();
Minecraft.getInstance().getChatListener().handleSystemMessage(Component.translatable("project_me.projection_entity.goto"), true);
} else {
if (System.currentTimeMillis() - peFirstInteractTime >= 10 &&
System.currentTimeMillis() - peFirstInteractTime <= 500) {
peTargetUUID = null;
peFirstInteractTime = -1;
Objects.requireNonNull(Minecraft.getInstance().getConnection()).sendCommand("go " + projection.getName().getString());
}
}
Minecraft.getInstance().getChatListener().handleSystemMessage(
Component.translatable("project_me.projection_entity.goto", projection.getName())
.withStyle(ChatFormatting.RED).withStyle(ChatFormatting.BOLD), true);
}
}

@SubscribeEvent
public static void onAttackEntity(AttackEntityEvent event) {
if (event.getTarget() instanceof EntityProjection) {
Minecraft.getInstance().getChatListener().handleSystemMessage(Component.translatable("project_me.projection_entity.goto"), true);
if (event.getTarget() instanceof EntityProjection projection) {
Minecraft.getInstance().getChatListener().handleSystemMessage(
Component.translatable("project_me.projection_entity.goto", projection.getName())
.withStyle(ChatFormatting.RED).withStyle(ChatFormatting.BOLD), true);
event.setCanceled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cn.zbx1425.projectme.ClientConfig;
import cn.zbx1425.projectme.ProjectMe;
import cn.zbx1425.projectme.entity.EntityProjection;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import snownee.jade.api.*;
Expand All @@ -17,8 +18,12 @@ public void registerClient(IWailaClientRegistration registration) {
registration.registerEntityComponent(new IComponentProvider<>() {
@Override
public void appendTooltip(ITooltip tooltip, EntityAccessor entity, IPluginConfig iPluginConfig) {
EntityProjection projection = (EntityProjection) entity.getEntity();
if (!ClientConfig.isProjectionEntityEnabled) return;
tooltip.add(Component.translatable("project_me.projection_entity.tooltip"));
tooltip.add(Component.translatable("project_me.projection_entity.tooltip")
.withStyle(ChatFormatting.GOLD).withStyle(ChatFormatting.BOLD));
tooltip.add(Component.translatable("project_me.projection_entity.tooltip_hint_1", projection.getName()));
tooltip.add(Component.translatable("project_me.projection_entity.tooltip_hint_2"));
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/project_me/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"project_me.projection_entity.tooltip": "Player in another sub-server",
"project_me.projection_entity.goto": "Double right-click to go to their sub-server, and you can interact with them.",
"project_me.projection_entity.tooltip_hint_1": "To interact with it, use '/go %s'",
"project_me.projection_entity.tooltip_hint_2": "To hide it, use '/pme'",
"project_me.projection_entity.goto": "To interact with it, go to their server - use '/go %s'",
"project_me.projection.disabled": "Player Projection has been disabled. Execute '/pme' to enable this feature.",
"project_me.projection.enabled": "Player Projection has been enabled."
}
6 changes: 4 additions & 2 deletions src/main/resources/assets/project_me/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"project_me.projection_entity.tooltip": "其他分服务器的玩家",
"project_me.projection_entity.goto": "双击右键前往对方所在的分服务器,以便与其交互",
"project_me.projection_entity.tooltip": "位于其他分服务器的玩家",
"project_me.projection_entity.tooltip_hint_1": "要与它交互,请使用指令: /go %s",
"project_me.projection_entity.tooltip_hint_2": "要不显示它,请使用指令: /pme",
"project_me.projection_entity.goto": "前往对方所在的分服务器才可与其交互——请使用指令: /go %s",
"project_me.projection.disabled": "已不再显示其他分服务器的玩家,运行 /pme 来重新启用",
"project_me.projection.enabled": "已启用显示其他分服务器的玩家"
}

0 comments on commit b930270

Please sign in to comment.