Skip to content

Commit

Permalink
Add firefly dynamic lights
Browse files Browse the repository at this point in the history
  • Loading branch information
doctor4t committed Jan 3, 2025
1 parent b209a9b commit 505be60
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 176 deletions.
11 changes: 8 additions & 3 deletions src/client/java/org/ladysnake/effective/core/Effective.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ladysnake.effective.core;

import foundry.veil.api.client.render.light.Light;
import foundry.veil.platform.VeilEventPlatform;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
Expand All @@ -15,7 +16,6 @@
import net.minecraft.particle.SimpleParticleType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
Expand All @@ -24,7 +24,6 @@
import net.minecraft.world.World;
import org.ladysnake.effective.core.gui.ParryScreen;
import org.ladysnake.effective.core.index.EffectiveParticles;
import org.ladysnake.effective.core.particle.ChorusPetalParticle;
import org.ladysnake.effective.core.particle.EyesParticle;
import org.ladysnake.effective.core.particle.WillOWispParticle;
import org.ladysnake.effective.core.render.entity.model.SplashBottomModel;
Expand All @@ -42,6 +41,9 @@
import org.ladysnake.satin.api.managed.ShaderEffectManager;
import org.ladysnake.satin.api.managed.uniform.Uniform1f;

import java.util.ArrayList;
import java.util.HashMap;

public class Effective implements ClientModInitializer {
public static final String MODID = "effective";

Expand All @@ -60,6 +62,9 @@ public class Effective implements ClientModInitializer {
// freeze frames for feedbacking
public static int freezeFrames = -1;

// particle lights cache
public static final ArrayList<Light> PARTICLE_LIGHTS = new ArrayList<>();

// particle types
public static SimpleParticleType EYES;
public static SimpleParticleType WILL_O_WISP;
Expand Down Expand Up @@ -236,7 +241,7 @@ public void onInitializeClient() {
}
});


// Inject into the Vanilla particle shader to lower the transparency discard threshold
VeilEventPlatform.INSTANCE.onVeilAddShaderProcessors((provider, registry) -> {
registry.addPreprocessor(new EffectiveTransparencyFixPreProcessor(), false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface EffectiveParticles {
SimpleParticleType GLOW_CASCADE = create("glow_cascade", FabricParticleTypes.simple(true));
SimpleParticleType MIST = create("mist", FabricParticleTypes.simple(true));
SimpleParticleType CHORUS_PETAL = create("chorus_petal", FabricParticleTypes.simple(true));
SimpleParticleType FIREFLY = create("firefly", FabricParticleTypes.simple(true));

static void initialize() {
PARTICLES.keySet().forEach(particle -> Registry.register(Registries.PARTICLE_TYPE, PARTICLES.get(particle), particle));
Expand All @@ -55,5 +56,6 @@ private static void registerFactories() {
ParticleFactoryRegistry.getInstance().register(GLOW_CASCADE, GlowCascadeParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(MIST, MistParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(CHORUS_PETAL, ChorusPetalParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(FIREFLY, FireflyParticle.Factory::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import org.jetbrains.annotations.Nullable;
import org.ladysnake.effective.core.Effective;
import org.ladysnake.effective.core.EffectiveConfig;
import org.ladysnake.effective.core.index.EffectiveParticles;
import org.ladysnake.effective.core.particle.FireflyParticle;
import org.ladysnake.effective.core.settings.SpawnSettings;
import org.ladysnake.effective.core.settings.data.FireflySpawnSetting;
import org.ladysnake.effective.core.utils.EffectiveUtils;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -76,27 +80,21 @@ protected ClientWorldMixin(MutableWorldProperties properties, RegistryKey<World>

// FIREFLIES
if (EffectiveConfig.fireflyDensity > 0) {
// FireflySpawnSetting fireflySpawnSetting = SpawnSettings.FIREFLIES.get(biome.getKey().get());
// if (fireflySpawnSetting != null) {
// if (random.nextFloat() * 250f <= fireflySpawnSetting.spawnChance() * EffectiveConfig.fireflyDensity && pos.getY() > this.getSeaLevel()) {
// for (int y = this.getSeaLevel(); y <= this.getSeaLevel() * 2; y++) {
// pos.setY(y);
// pos2.setY(y-1);
// boolean canSpawnFirefly = FireflyParticle.canFlyThroughBlock(this, pos, this.getBlockState(pos)) && !FireflyParticle.canFlyThroughBlock(this, pos2, this.getBlockState(pos2));
//
// if (canSpawnFirefly) {
// WorldParticleBuilder.create(Effective.FIREFLY)
// .enableForcedSpawn()
// .setColorData(ColorParticleData.create(fireflySpawnSetting.color(), fireflySpawnSetting.color()).build())
// .setScaleData(GenericParticleData.create(0.05f + random.nextFloat() * 0.10f).build())
// .setLifetime(ThreadLocalRandom.current().nextInt(40, 120))
// .setRenderType(LodestoneWorldParticleRenderType.ADDITIVE)
// .spawn(this, pos.getX() + random.nextFloat(), pos.getY() + random.nextFloat() * 5f, pos.getZ() + random.nextFloat());
// break;
// }
// }
// }
// }
FireflySpawnSetting fireflySpawnSetting = SpawnSettings.FIREFLIES.get(biome.getKey().get());
if (fireflySpawnSetting != null) {
if (random.nextFloat() * 250f <= fireflySpawnSetting.spawnChance() * EffectiveConfig.fireflyDensity && pos.getY() > this.getSeaLevel()) {
for (int y = this.getSeaLevel(); y <= this.getSeaLevel() * 2; y++) {
pos.setY(y);
pos2.setY(y - 1);
boolean canSpawnFirefly = FireflyParticle.canFlyThroughBlock(this, pos, this.getBlockState(pos)) && !FireflyParticle.canFlyThroughBlock(this, pos2, this.getBlockState(pos2));

if (canSpawnFirefly) {
this.addParticle(EffectiveParticles.FIREFLY, pos.getX() + random.nextFloat(), pos.getY() + random.nextFloat() * 5f, pos.getZ() + random.nextFloat(), 0, 0, 0);
break;
}
}
}
}
}

pos = blockPos.add(MathHelper.floor(EffectiveUtils.getRandomFloatOrNegative(this.random) * 50), MathHelper.floor(EffectiveUtils.getRandomFloatOrNegative(this.random) * 25), MathHelper.floor(EffectiveUtils.getRandomFloatOrNegative(this.random) * 50)).mutableCopy();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.ladysnake.effective.core.mixin.lights;

import foundry.veil.api.client.render.VeilRenderSystem;
import net.minecraft.client.particle.ParticleManager;
import org.ladysnake.effective.core.Effective;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ParticleManager.class)
public class ParticleManagerMixin {
@Inject(method = "clearParticles", at = @At("HEAD"))
private void effective$clearLightsOnClearParticles(CallbackInfo ci) {
Effective.PARTICLE_LIGHTS.forEach(light -> VeilRenderSystem.renderer().getLightRenderer().removeLight(light));
Effective.PARTICLE_LIGHTS.clear();
}
}
Loading

0 comments on commit 505be60

Please sign in to comment.