From c95c92bc519b4b1368c870d5136c4c0deea9f699 Mon Sep 17 00:00:00 2001 From: burningtnt Date: Sun, 5 Jan 2025 15:25:24 +0800 Subject: [PATCH] 0.1.4 --- .../projectme/client/ProjectMeClient.java | 36 ++++++++++++++++--- .../projectme/entity/EntityProjection.java | 21 ++++++++--- .../entity/EntityProjectionRenderer.java | 5 +++ .../assets/project_me/lang/en_us.json | 5 ++- .../assets/project_me/lang/zh_cn.json | 7 ++-- 5 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/main/java/cn/zbx1425/projectme/client/ProjectMeClient.java b/src/main/java/cn/zbx1425/projectme/client/ProjectMeClient.java index 86e264e..eebf03b 100644 --- a/src/main/java/cn/zbx1425/projectme/client/ProjectMeClient.java +++ b/src/main/java/cn/zbx1425/projectme/client/ProjectMeClient.java @@ -3,20 +3,19 @@ import cn.zbx1425.projectme.ProjectMe; import cn.zbx1425.projectme.entity.EntityProjection; import cn.zbx1425.projectme.entity.EntityProjectionRenderer; -import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.Command; import net.minecraft.client.Minecraft; +import net.minecraft.commands.Commands; import net.minecraft.network.chat.Component; -import net.minecraft.world.phys.EntityHitResult; -import net.minecraft.world.phys.HitResult; import net.neoforged.bus.api.IEventBus; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.neoforge.client.event.EntityRenderersEvent; +import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.event.entity.player.AttackEntityEvent; import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; import java.util.Objects; -import java.util.Optional; import java.util.UUID; public class ProjectMeClient { @@ -57,6 +56,7 @@ public static void onPlayerInteractEntity(PlayerInteractEvent.EntityInteractSpec @SubscribeEvent public static void onAttackEntity(AttackEntityEvent event) { if (event.getTarget() instanceof EntityProjection) { + Minecraft.getInstance().getChatListener().handleSystemMessage(Component.translatable("project_me.projection_entity.goto"), true); event.setCanceled(true); } } @@ -68,5 +68,33 @@ public static class ModEventBusListener { public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) { event.registerEntityRenderer(ProjectMe.ENTITY_PROJECTION.get(), EntityProjectionRenderer::new); } + + @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( + Commands.literal("enable").executes(c -> { + EntityProjectionRenderer.enabled = true; + + c.getSource().sendSuccess(() -> Component.translatable("project_me.renderer.enabled"), true); + return Command.SINGLE_SUCCESS; + }) + ).then( + Commands.literal("disable").executes(c -> { + EntityProjectionRenderer.enabled = false; + + c.getSource().sendSuccess(() -> Component.translatable("project_me.renderer.disabled"), true); + return Command.SINGLE_SUCCESS; + }) + ) + )); + } } } diff --git a/src/main/java/cn/zbx1425/projectme/entity/EntityProjection.java b/src/main/java/cn/zbx1425/projectme/entity/EntityProjection.java index 756538b..d0f5d93 100644 --- a/src/main/java/cn/zbx1425/projectme/entity/EntityProjection.java +++ b/src/main/java/cn/zbx1425/projectme/entity/EntityProjection.java @@ -6,6 +6,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.HumanoidArm; @@ -17,6 +18,7 @@ import net.minecraft.world.level.block.entity.SkullBlockEntity; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Optional; @@ -60,28 +62,37 @@ public boolean shouldBeSaved() { return false; } + @Override + public boolean canAttackType(EntityType arg) { + return super.canAttackType(arg); + } + @Override public boolean isInvulnerable() { return true; } + @Override + public boolean isInvulnerableTo(DamageSource arg) { + return true; + } + @Override public Iterable getArmorSlots() { return List.of(); } @Override - public ItemStack getItemBySlot(EquipmentSlot arg) { + public @NotNull ItemStack getItemBySlot(@NotNull EquipmentSlot arg) { return ItemStack.EMPTY; } @Override - public void setItemSlot(EquipmentSlot arg, ItemStack arg2) { - + public void setItemSlot(@NotNull EquipmentSlot arg, @NotNull ItemStack arg2) { } @Override - public HumanoidArm getMainArm() { + public @NotNull HumanoidArm getMainArm() { return HumanoidArm.RIGHT; } @@ -89,7 +100,7 @@ public HumanoidArm getMainArm() { ProjectMe.UUID_ENTITY_DATA_SERIALIZER.get()); @Override - protected void defineSynchedData(SynchedEntityData.Builder builder) { + protected void defineSynchedData(SynchedEntityData.@NotNull Builder builder) { super.defineSynchedData(builder); builder.define(PROJECTING_PLAYER, Util.NIL_UUID); } diff --git a/src/main/java/cn/zbx1425/projectme/entity/EntityProjectionRenderer.java b/src/main/java/cn/zbx1425/projectme/entity/EntityProjectionRenderer.java index f1e04c2..acc3a4b 100644 --- a/src/main/java/cn/zbx1425/projectme/entity/EntityProjectionRenderer.java +++ b/src/main/java/cn/zbx1425/projectme/entity/EntityProjectionRenderer.java @@ -17,6 +17,7 @@ import java.util.Optional; public class EntityProjectionRenderer extends LivingEntityRenderer> { + public static boolean enabled = true; private final PlayerModel slimModel; private final PlayerModel wideModel; @@ -39,6 +40,10 @@ public ResourceLocation getTextureLocation(EntityProjection entity) { @Override public void render(EntityProjection entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) { + if (!enabled) { + return; + } + Optional result = entity.gameProfile.getNow(Optional.empty()); if (result.isPresent()) { SkinManager skinManager = Minecraft.getInstance().getSkinManager(); 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 a97af7a..9e2fa53 100644 --- a/src/main/resources/assets/project_me/lang/en_us.json +++ b/src/main/resources/assets/project_me/lang/en_us.json @@ -1,4 +1,7 @@ { "project_me.projection_entity.tooltip": "Player in another sub-server", - "project_me.projection_entity.goto": "Double right-click to go to their server, so that you can interact with him" + "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." } \ 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 32f9bdd..f02639b 100644 --- a/src/main/resources/assets/project_me/lang/zh_cn.json +++ b/src/main/resources/assets/project_me/lang/zh_cn.json @@ -1,4 +1,7 @@ { - "project_me.projection_entity.tooltip": "位于另一个分服务器的玩家", - "project_me.projection_entity.goto": "双击右键前往他所在的服务器,以便与他交互" + "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": "已启用渲染其他分服务器的玩家" } \ No newline at end of file