Skip to content

Commit

Permalink
[Glowing entities 3.0] - Change Glowing logic, updated to Minecraft v…
Browse files Browse the repository at this point in the history
…ersion 1.20.5, I will update Read.md soon.
  • Loading branch information
I-No-oNe committed Apr 24, 2024
1 parent 58a8831 commit 677378b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ public <T extends Entity> 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));
}
}
}
}

0 comments on commit 677378b

Please sign in to comment.