diff --git a/gradle.properties b/gradle.properties index ba88eff..fcf69ff 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G loom.platform = neoforge # Mod properties -mod_version = 0.1.6 +mod_version = 0.1.7 maven_group = cn.zbx1425 archives_name = project_me diff --git a/src/main/java/cn/zbx1425/projectme/ClientConfig.java b/src/main/java/cn/zbx1425/projectme/ClientConfig.java new file mode 100644 index 0000000..8b7977e --- /dev/null +++ b/src/main/java/cn/zbx1425/projectme/ClientConfig.java @@ -0,0 +1,6 @@ +package cn.zbx1425.projectme; + +public class ClientConfig { + + public static boolean isProjectionEntityEnabled = true; +} diff --git a/src/main/java/cn/zbx1425/projectme/client/ProjectMeClient.java b/src/main/java/cn/zbx1425/projectme/client/ProjectMeClient.java index 81f0d52..3bcea6e 100644 --- a/src/main/java/cn/zbx1425/projectme/client/ProjectMeClient.java +++ b/src/main/java/cn/zbx1425/projectme/client/ProjectMeClient.java @@ -1,5 +1,6 @@ package cn.zbx1425.projectme.client; +import cn.zbx1425.projectme.ClientConfig; import cn.zbx1425.projectme.ProjectMe; import cn.zbx1425.projectme.entity.EntityProjection; import cn.zbx1425.projectme.entity.EntityProjectionRenderer; @@ -25,11 +26,11 @@ public ProjectMeClient(IEventBus eventBus) { eventBus.register(ModEventBusListener.class); } - private static UUID peTargetUUID; - private static long peFirstInteractTime = -1; - 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; @@ -63,30 +64,30 @@ public static void onAttackEntity(AttackEntityEvent event) { @SubscribeEvent public static void registerCommands(RegisterClientCommandsEvent event) { - event.getDispatcher().register(Commands.literal("projectme").then( - Commands.literal("render").then( - Commands.literal("switch").executes(c -> { - EntityProjectionRenderer.enabled = !EntityProjectionRenderer.enabled; - - c.getSource().sendSuccess(() -> Component.translatable("project_me.renderer.switch"), true); - return Command.SINGLE_SUCCESS; - }) - ).then( + event.getDispatcher().register(Commands.literal("pme").then( + Commands.literal("projection").then( Commands.literal("enable").executes(c -> { - EntityProjectionRenderer.enabled = true; + ClientConfig.isProjectionEntityEnabled = true; - c.getSource().sendSuccess(() -> Component.translatable("project_me.renderer.enabled"), true); + c.getSource().sendSuccess(() -> Component.translatable("project_me.projection.enabled"), true); return Command.SINGLE_SUCCESS; }) ).then( Commands.literal("disable").executes(c -> { - EntityProjectionRenderer.enabled = false; + ClientConfig.isProjectionEntityEnabled = false; - c.getSource().sendSuccess(() -> Component.translatable("project_me.renderer.disabled"), true); + c.getSource().sendSuccess(() -> Component.translatable("project_me.projection.disabled"), true); return Command.SINGLE_SUCCESS; }) ) - )); + ).executes(c -> { + ClientConfig.isProjectionEntityEnabled = !ClientConfig.isProjectionEntityEnabled; + + c.getSource().sendSuccess(() -> ClientConfig.isProjectionEntityEnabled + ? Component.translatable("project_me.projection.enabled") + : Component.translatable("project_me.projection.disabled"), true); + return Command.SINGLE_SUCCESS; + })); } } diff --git a/src/main/java/cn/zbx1425/projectme/client/ProjectMeJadePlugin.java b/src/main/java/cn/zbx1425/projectme/client/ProjectMeJadePlugin.java index 04461eb..4523b4d 100644 --- a/src/main/java/cn/zbx1425/projectme/client/ProjectMeJadePlugin.java +++ b/src/main/java/cn/zbx1425/projectme/client/ProjectMeJadePlugin.java @@ -1,5 +1,6 @@ package cn.zbx1425.projectme.client; +import cn.zbx1425.projectme.ClientConfig; import cn.zbx1425.projectme.ProjectMe; import cn.zbx1425.projectme.entity.EntityProjection; import net.minecraft.network.chat.Component; @@ -16,6 +17,7 @@ public void registerClient(IWailaClientRegistration registration) { registration.registerEntityComponent(new IComponentProvider<>() { @Override public void appendTooltip(ITooltip tooltip, EntityAccessor entity, IPluginConfig iPluginConfig) { + if (!ClientConfig.isProjectionEntityEnabled) return; tooltip.add(Component.translatable("project_me.projection_entity.tooltip")); } diff --git a/src/main/java/cn/zbx1425/projectme/entity/EntityProjection.java b/src/main/java/cn/zbx1425/projectme/entity/EntityProjection.java index d0f5d93..80f86f4 100644 --- a/src/main/java/cn/zbx1425/projectme/entity/EntityProjection.java +++ b/src/main/java/cn/zbx1425/projectme/entity/EntityProjection.java @@ -1,5 +1,6 @@ package cn.zbx1425.projectme.entity; +import cn.zbx1425.projectme.ClientConfig; import cn.zbx1425.projectme.ProjectMe; import com.mojang.authlib.GameProfile; import net.minecraft.Util; @@ -77,6 +78,11 @@ public boolean isInvulnerableTo(DamageSource arg) { return true; } + @Override + public boolean isPickable() { + return ClientConfig.isProjectionEntityEnabled && super.isPickable(); + } + @Override public Iterable getArmorSlots() { return List.of(); diff --git a/src/main/java/cn/zbx1425/projectme/entity/EntityProjectionRenderer.java b/src/main/java/cn/zbx1425/projectme/entity/EntityProjectionRenderer.java index acc3a4b..7c1d108 100644 --- a/src/main/java/cn/zbx1425/projectme/entity/EntityProjectionRenderer.java +++ b/src/main/java/cn/zbx1425/projectme/entity/EntityProjectionRenderer.java @@ -1,5 +1,6 @@ package cn.zbx1425.projectme.entity; +import cn.zbx1425.projectme.ClientConfig; import com.mojang.authlib.GameProfile; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; @@ -17,7 +18,6 @@ import java.util.Optional; public class EntityProjectionRenderer extends LivingEntityRenderer> { - public static boolean enabled = true; private final PlayerModel slimModel; private final PlayerModel wideModel; @@ -40,7 +40,7 @@ public ResourceLocation getTextureLocation(EntityProjection entity) { @Override public void render(EntityProjection entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) { - if (!enabled) { + if (!ClientConfig.isProjectionEntityEnabled) { return; } diff --git a/src/main/resources/assets/project_me/lang/en_us.json b/src/main/resources/assets/project_me/lang/en_us.json index 9e2fa53..72f20d3 100644 --- a/src/main/resources/assets/project_me/lang/en_us.json +++ b/src/main/resources/assets/project_me/lang/en_us.json @@ -1,7 +1,6 @@ { "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.renderer.switch": "Projection Renderer has been disabled. Execute this command again to re-enable this feature.", - "project_me.renderer.disabled": "Projection Renderer has been disabled. Execute '/projectme renderer enable' to enable this feature.", - "project_me.renderer.enabled": "Projection Renderer has been enabled." + "project_me.projection.disabled": "Player Projection has been disabled. Execute '/pme' to enable this feature.", + "project_me.projection.enabled": "Player Projection has been enabled." } \ No newline at end of file diff --git a/src/main/resources/assets/project_me/lang/zh_cn.json b/src/main/resources/assets/project_me/lang/zh_cn.json index f02639b..e8755b8 100644 --- a/src/main/resources/assets/project_me/lang/zh_cn.json +++ b/src/main/resources/assets/project_me/lang/zh_cn.json @@ -1,7 +1,6 @@ { "project_me.projection_entity.tooltip": "其他分服务器的玩家", "project_me.projection_entity.goto": "双击右键前往对方所在的分服务器,以便与其交互", - "project_me.renderer.switch": "已不再渲染其他分服务器的玩家,再运行一次本命令以启用。", - "project_me.renderer.disabled": "已不再渲染其他分服务器的玩家,运行 /projectme renderer enable 来重新启用", - "project_me.renderer.enabled": "已启用渲染其他分服务器的玩家" + "project_me.projection.disabled": "已不再显示其他分服务器的玩家,运行 /pme 来重新启用", + "project_me.projection.enabled": "已启用显示其他分服务器的玩家" } \ No newline at end of file