Skip to content

Commit

Permalink
Add isPickable
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Jan 7, 2025
1 parent b39920b commit 250d929
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/cn/zbx1425/projectme/ClientConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cn.zbx1425.projectme;

public class ClientConfig {

public static boolean isProjectionEntityEnabled = true;
}
35 changes: 18 additions & 17 deletions src/main/java/cn/zbx1425/projectme/client/ProjectMeClient.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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"));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -77,6 +78,11 @@ public boolean isInvulnerableTo(DamageSource arg) {
return true;
}

@Override
public boolean isPickable() {
return ClientConfig.isProjectionEntityEnabled && super.isPickable();
}

@Override
public Iterable<ItemStack> getArmorSlots() {
return List.of();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,7 +18,6 @@
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 @@ -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;
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/resources/assets/project_me/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -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."
}
5 changes: 2 additions & 3 deletions src/main/resources/assets/project_me/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -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": "已启用显示其他分服务器的玩家"
}

0 comments on commit 250d929

Please sign in to comment.