From 677378bdae481840c180131b843e4ab74489eddc Mon Sep 17 00:00:00 2001 From: I-No-oNe <145749961+I-No-oNe@users.noreply.github.com> Date: Wed, 24 Apr 2024 18:17:01 +0300 Subject: [PATCH] [Glowing entities 3.0] - Change Glowing logic, updated to Minecraft version 1.20.5, I will update Read.md soon. --- .../GlowingEntitiesClient.java | 40 +++++++++++++------ .../mixin/client/EntityRendererMixin.java | 18 +++++---- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/client/java/net/i_no_am/glowing_entities/GlowingEntitiesClient.java b/src/client/java/net/i_no_am/glowing_entities/GlowingEntitiesClient.java index 6819226..2f31833 100644 --- a/src/client/java/net/i_no_am/glowing_entities/GlowingEntitiesClient.java +++ b/src/client/java/net/i_no_am/glowing_entities/GlowingEntitiesClient.java @@ -3,6 +3,8 @@ import com.mojang.brigadier.arguments.IntegerArgumentType; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; +import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.text.Text; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; @@ -11,17 +13,31 @@ public class GlowingEntitiesClient implements ClientModInitializer { @Override public void onInitializeClient() { - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(literal("glowing_effect") - .then(argument("glowing", IntegerArgumentType.integer()) - .executes(context -> { - int value = IntegerArgumentType.getInteger(context, "glowing"); - IEntityDataSaver playerData = (IEntityDataSaver) context.getSource().getPlayer(); - playerData.glowing_entities$getPersistentData().putInt("glow",value); - if (value > 15) - value = 15; - String glow = value < 0 ? "Normal" : String.valueOf(value); - context.getSource().sendFeedback(Text.literal("§l§6Glowing Entities: §bThe Entity Glowing set to: " + glow)); - return value; - })))); + ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register( + literal("glowing_effect") + .then(argument("glowing", IntegerArgumentType.integer(-1, 15)) + .executes(context -> { + int value = IntegerArgumentType.getInteger(context, "glowing"); + ClientPlayerEntity player = context.getSource().getPlayer(); + IEntityDataSaver playerData = (IEntityDataSaver) player; + if (value == -1 || value == 0) { + playerData.glowing_entities$getPersistentData().putInt("glow", 0); // Set glow level to 0 + context.getSource().sendFeedback(Text.literal("§l§6Glowing Entities: §cThe mod is turned off")); + return 0; + } else { + playerData.glowing_entities$getPersistentData().putInt("glow", value); + context.getSource().sendFeedback(Text.literal("§l§6Glowing Entities: §bThe Entity Glowing set to: " + value)); + return value; + } + }) + ) + )); + ClientLifecycleEvents.CLIENT_STARTED.register(client -> { + ClientPlayerEntity player = client.player; + if (player != null) { + IEntityDataSaver playerData = (IEntityDataSaver) player; + playerData.glowing_entities$getPersistentData().putInt("glow", 15); + } + }); } } \ No newline at end of file diff --git a/src/client/java/net/i_no_am/glowing_entities/mixin/client/EntityRendererMixin.java b/src/client/java/net/i_no_am/glowing_entities/mixin/client/EntityRendererMixin.java index 2e5b074..0694cb4 100644 --- a/src/client/java/net/i_no_am/glowing_entities/mixin/client/EntityRendererMixin.java +++ b/src/client/java/net/i_no_am/glowing_entities/mixin/client/EntityRendererMixin.java @@ -21,18 +21,20 @@ public void getLight(T entity, BlockPos pos, CallbackInfoRetu if (entity.getWorld().isClient() && MinecraftClient.getInstance().player != null) { PlayerEntity player = entity.getWorld().getPlayerByUuid(MinecraftClient.getInstance().player.getUuid()); IEntityDataSaver playerData = (IEntityDataSaver) player; - if (playerData != null && playerData.glowing_entities$getPersistentData().contains("glow")) + if (playerData != null && playerData.glowing_entities$getPersistentData().contains("glow")) { glow = playerData.glowing_entities$getPersistentData().getInt("glow"); + } else { + glow = 15; + } } if (glow == 0) { - cir.setReturnValue(0); // Return light level 0 if glow is explicitly set to 0 + cir.setReturnValue(0); return; } - if (glow > 15) - glow = 15; - if (glow < 0) + if (glow < 0) { cir.setReturnValue(entity.isOnFire() ? 15 : entity.getWorld().getLightLevel(LightType.BLOCK, pos)); - else - cir.setReturnValue(glow); + } else { + cir.setReturnValue(Math.min(glow, 15)); + } } -} +} \ No newline at end of file