Files
src
build.gradle
settings.gradle
Code
8 305
src/client/java/com/kodari/grounditemglow/GroundItemGlowClient.java
package com.kodari.grounditemglow;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ItemEntity;
import java.util.Map;
import java.util.WeakHashMap;
public final class GroundItemGlowClient implements ClientModInitializer {
private final Map<ItemEntity, Boolean> originalGlowStates = new WeakHashMap<>();
private ClientWorld trackedWorld;
@Override
public void onInitializeClient() {
GroundItemGlowConfig.load();
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (trackedWorld != client.world) {
restoreGlowStates();
trackedWorld = client.world;
}
if (client.world == null) {
return;
}
for (Entity entity : client.world.getEntities()) {
if (!(entity instanceof ItemEntity itemEntity)) {
continue;
}
if (GroundItemGlowConfig.shouldGlow(itemEntity.getStack(), client.world)) {
originalGlowStates.putIfAbsent(itemEntity, itemEntity.isGlowingLocal());
itemEntity.setGlowing(true);
} else {
restoreGlowState(itemEntity);
}
}
});
}
private void restoreGlowState(ItemEntity itemEntity) {
Boolean wasGlowing = originalGlowStates.remove(itemEntity);
if (wasGlowing != null) {
itemEntity.setGlowing(wasGlowing);
}
}
private void restoreGlowStates() {
originalGlowStates.forEach(ItemEntity::setGlowing);
originalGlowStates.clear();
}
}