|
3 | 3 | import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
4 | 4 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
5 | 5 | import fun.qu_an.minecraft.asyncparticles.client.addon.LightCachedParticleAddon;
|
| 6 | +import fun.qu_an.minecraft.asyncparticles.client.config.SimplePropertiesConfig; |
| 7 | +import net.minecraft.client.multiplayer.ClientLevel; |
6 | 8 | import net.minecraft.client.particle.Particle;
|
| 9 | +import net.minecraft.client.renderer.LevelRenderer; |
| 10 | +import net.minecraft.core.BlockPos; |
| 11 | +import org.spongepowered.asm.mixin.Final; |
7 | 12 | import org.spongepowered.asm.mixin.Mixin;
|
8 | 13 | import org.spongepowered.asm.mixin.Shadow;
|
9 | 14 | import org.spongepowered.asm.mixin.Unique;
|
|
13 | 18 |
|
14 | 19 | @Mixin(Particle.class)
|
15 | 20 | public abstract class MixinParticle_LightCache implements LightCachedParticleAddon {
|
| 21 | + @Shadow @Final public ClientLevel level; |
| 22 | + @Shadow public double x; |
| 23 | + @Shadow public double y; |
| 24 | + @Shadow public double z; |
| 25 | + @Unique |
| 26 | + private byte asyncParticles$lightCache = INITIAL_LIGHT_CACHE; |
16 | 27 | @Shadow
|
17 | 28 | public abstract int getLightColor(float partialTick);
|
18 |
| - @Unique |
19 |
| - private short asyncParticles$lightCache = INITIAL_LIGHT_CACHE; |
20 | 29 |
|
21 | 30 | @WrapMethod(method = "getLightColor")
|
22 | 31 | private int wrapGetLightColor(float partialTick, Operation<Integer> original) {
|
23 |
| - short lightCache = asyncParticles$getPackedLight(); |
24 |
| - return LightCachedParticleAddon.isLightCacheValid(lightCache) |
25 |
| - ? unpackLight((byte) lightCache) |
| 32 | + return SimplePropertiesConfig.particleLightCache() |
| 33 | + ? decompress(asyncParticles$getCompressedLight()) |
26 | 34 | : original.call(partialTick);
|
27 | 35 | }
|
28 | 36 |
|
29 | 37 | @Override
|
30 |
| - public void asyncParticles$setLight(int light) { |
31 |
| - asyncParticles$lightCache = (short) (light >> 4 & 0xF | light >> 16 & 0xF0); |
| 38 | + public void asyncParticles$refresh() { |
| 39 | + // for some particles, light is hard coded to 15, so this is not necessary for all particles |
| 40 | + // do we need a better design? |
| 41 | + BlockPos blockPos = BlockPos.containing(x, y, z); |
| 42 | + int light = level.hasChunkAt(blockPos) ? LevelRenderer.getLightColor(level, blockPos) : 0; |
| 43 | + asyncParticles$setLight(light); |
32 | 44 | }
|
33 | 45 |
|
34 | 46 | @Override
|
35 |
| - public short asyncParticles$getPackedLight() { |
36 |
| - return asyncParticles$lightCache; |
| 47 | + public void asyncParticles$setLight(int light) { |
| 48 | + asyncParticles$lightCache = compress(light); |
37 | 49 | }
|
38 | 50 |
|
39 | 51 | @Override
|
40 |
| - public void asyncParticles$refresh() { |
41 |
| - // mark as outdated, we don't set to -1 because -1 was used as a special value for initial cache |
42 |
| - asyncParticles$lightCache |= Short.MIN_VALUE; |
43 |
| - asyncParticles$setLight(getLightColor(0)); |
| 52 | + public byte asyncParticles$getCompressedLight() { |
| 53 | + return asyncParticles$lightCache; |
44 | 54 | }
|
45 | 55 |
|
46 | 56 | @Override
|
|
0 commit comments