Skip to content

Commit

Permalink
0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtnt committed Jan 5, 2025
1 parent 5494b39 commit c95c92b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 12 deletions.
36 changes: 32 additions & 4 deletions src/main/java/cn/zbx1425/projectme/client/ProjectMeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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;
})
)
));
}
}
}
21 changes: 16 additions & 5 deletions src/main/java/cn/zbx1425/projectme/entity/EntityProjection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -60,36 +62,45 @@ 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<ItemStack> 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;
}

private static final EntityDataAccessor<UUID> PROJECTING_PLAYER = SynchedEntityData.defineId(EntityProjection.class,
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Optional;

public class EntityProjectionRenderer extends LivingEntityRenderer<EntityProjection, PlayerModel<EntityProjection>> {
public static boolean enabled = true;

private final PlayerModel<EntityProjection> slimModel;
private final PlayerModel<EntityProjection> wideModel;
Expand All @@ -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<GameProfile> result = entity.gameProfile.getNow(Optional.empty());
if (result.isPresent()) {
SkinManager skinManager = Minecraft.getInstance().getSkinManager();
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/assets/project_me/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -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."
}
7 changes: 5 additions & 2 deletions src/main/resources/assets/project_me/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -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": "已启用渲染其他分服务器的玩家"
}

0 comments on commit c95c92b

Please sign in to comment.