Skip to content

Commit

Permalink
Add dynamic lights to allays (respects color if golden allays is enab…
Browse files Browse the repository at this point in the history
…led) + toggle config option
  • Loading branch information
doctor4t committed Jan 4, 2025
1 parent 4e76734 commit 73204f3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public class EffectiveConfig extends MidnightConfig {
public static Comment entitiesDynamicLights;
@Entry(category = dynamicLights)
public static boolean glowSquidDynamicLights = true;
@Entry(category = dynamicLights)
public static boolean allayDynamicLights = true;
@Comment(category = dynamicLights, centered = true)
public static Comment particlesDynamicLights;
@Entry(category = dynamicLights)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,90 @@
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.AllayEntity;
import net.minecraft.entity.passive.GlowSquidEntity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.ladysnake.effective.core.EffectiveConfig;
import org.ladysnake.effective.core.utils.EffectiveUtils;

import java.util.ArrayList;
import java.util.Map;

public class EffectiveLights {
public static final ArrayList<Light> PARTICLE_LIGHTS = new ArrayList<>();
public static final Map<Integer, PointLight> GLOW_SQUID_LIGHTS = new Object2ObjectOpenHashMap<>();
public static final Map<Integer, PointLight> ENTITY_LIGHTS = new Object2ObjectOpenHashMap<>();

public static void initialize() {
VeilEventPlatform.INSTANCE.onVeilRenderLevelStage((stage, levelRenderer, bufferSource, matrixStack, frustumMatrix, projectionMatrix, renderTick, deltaTracker, camera, frustum) -> {
// load glow squid lights
for (Entity entity : MinecraftClient.getInstance().world.getEntities()) {
if (entity instanceof GlowSquidEntity glowSquidEntity && EffectiveConfig.glowSquidDynamicLights) {
PointLight light;

Vec3d renderPosition = glowSquidEntity.getLerpedPos(deltaTracker.getTickDelta(false));
if (!GLOW_SQUID_LIGHTS.containsKey(glowSquidEntity.getId())) {
light = new PointLight();
light.setBrightness(0f);
light.setColor(0x69E2D0);
light.setRadius(5f);
light.setPosition(renderPosition.getX(), renderPosition.getY(), renderPosition.getZ());

GLOW_SQUID_LIGHTS.put(glowSquidEntity.getId(), light);
VeilRenderSystem.renderer().getLightRenderer().addLight(light);
}

light = GLOW_SQUID_LIGHTS.get(glowSquidEntity.getId());
light.setPosition(renderPosition.getX(), renderPosition.getY(), renderPosition.getZ());
light.setBrightness(MathHelper.clampedLerp(0.0F, 2.0F, 1.0F - (float) glowSquidEntity.getDarkTicksRemaining() / 10.0F));
tickGlowSquidLight(glowSquidEntity, deltaTracker);
} else if (entity instanceof AllayEntity allayEntity && EffectiveConfig.allayDynamicLights) {
tickAllayLight(allayEntity, deltaTracker);
}
}

// clean glow squid light list of missing glow squids
ArrayList<Integer> lightsToRemove = new ArrayList<>();
for (Integer uuid : GLOW_SQUID_LIGHTS.keySet()) {
for (Integer uuid : ENTITY_LIGHTS.keySet()) {
Entity entity = MinecraftClient.getInstance().world.getEntityById(uuid);
if (entity == null) {
lightsToRemove.add(uuid);
}
}
for (Integer uuid : lightsToRemove) {
VeilRenderSystem.renderer().getLightRenderer().removeLight(GLOW_SQUID_LIGHTS.get(uuid));
GLOW_SQUID_LIGHTS.remove(uuid);
VeilRenderSystem.renderer().getLightRenderer().removeLight(ENTITY_LIGHTS.get(uuid));
ENTITY_LIGHTS.remove(uuid);
}
});

ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> {
GLOW_SQUID_LIGHTS.forEach((integer, pointLight) -> VeilRenderSystem.renderer().getLightRenderer().removeLight(pointLight));
client.execute(GLOW_SQUID_LIGHTS::clear);
ENTITY_LIGHTS.forEach((integer, pointLight) -> VeilRenderSystem.renderer().getLightRenderer().removeLight(pointLight));
client.execute(ENTITY_LIGHTS::clear);
});
}

private static void tickGlowSquidLight(GlowSquidEntity glowSquidEntity, RenderTickCounter deltaTracker) {
PointLight light;
Vec3d renderPosition = glowSquidEntity.getLerpedPos(deltaTracker.getTickDelta(false));

if (ENTITY_LIGHTS.containsKey(glowSquidEntity.getId())) {
light = ENTITY_LIGHTS.get(glowSquidEntity.getId());
} else {
light = new PointLight();
light.setBrightness(0f);
light.setColor(0x69E2D0);
light.setRadius(5f);
light.setPosition(renderPosition.getX(), renderPosition.getY(), renderPosition.getZ());

ENTITY_LIGHTS.put(glowSquidEntity.getId(), light);
VeilRenderSystem.renderer().getLightRenderer().addLight(light);
}

light.setPosition(renderPosition.getX(), renderPosition.getY(), renderPosition.getZ());
light.setBrightness(MathHelper.clampedLerp(0.0F, 2.0F, 1.0F - (float) glowSquidEntity.getDarkTicksRemaining() / 10.0F));
}

private static void tickAllayLight(AllayEntity allayEntity, RenderTickCounter deltaTracker) {
PointLight light;
Vec3d renderPosition = allayEntity.getLerpedPos(deltaTracker.getTickDelta(false));

if (ENTITY_LIGHTS.containsKey(allayEntity.getId())) {
light = ENTITY_LIGHTS.get(allayEntity.getId());
} else {
light = new PointLight();
light.setBrightness(0.5f);
light.setColor(EffectiveUtils.getAllayColor(allayEntity));
light.setRadius(3f);
light.setPosition(renderPosition.getX(), renderPosition.getY(), renderPosition.getZ());

ENTITY_LIGHTS.put(allayEntity.getId(), light);
VeilRenderSystem.renderer().getLightRenderer().addLight(light);
}

light.setPosition(renderPosition.getX(), renderPosition.getY(), renderPosition.getZ());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,8 @@ public static void spawnClosingBubble(World world, float x, float y, float z, Di
world.addParticle(endChest ? EffectiveParticles.END_BUBBLE : EffectiveParticles.BUBBLE, x, y, z, velX, .1f - (world.random.nextFloat() * .1f), velZ);
}
}

public static int getAllayColor(AllayEntity allayEntity) {
return allayEntity.getUuid().hashCode() % 2 == 0 && EffectiveConfig.goldenAllays ? 0xFFC200 : 0x22CFFF;
}
}

0 comments on commit 73204f3

Please sign in to comment.