From 516f03aab6865484303db4e52cb556096e4611fa Mon Sep 17 00:00:00 2001
From: paulevsGitch <paulevs@yandex.ru>
Date: Fri, 20 Oct 2023 13:12:49 +0300
Subject: [PATCH 1/5] Light emission per blockstate

---
 .../sltest/block/Blocks.java                  |  3 +-
 .../sltest/block/LampBlock.java               | 52 +++++++++++++++++++
 .../stationapi/api/block/StationBlock.java    | 10 ++++
 .../impl/block/BlockBrightness.java           |  9 ++++
 .../stationapi/mixin/block/LevelMixin.java    | 22 ++++++++
 .../mixin/block/MixinBlockBase.java           | 41 ++++++++++++++-
 .../mixin/block/MixinBlockRenderer.java       | 27 ++++++++++
 .../stationapi/mixin/block/MixinClass417.java | 21 ++++++++
 .../resources/station-blocks-v0.mixins.json   | 47 +++++++++--------
 9 files changed, 209 insertions(+), 23 deletions(-)
 create mode 100644 src/test/java/net/modificationstation/sltest/block/LampBlock.java
 create mode 100644 station-blocks-v0/src/main/java/net/modificationstation/stationapi/impl/block/BlockBrightness.java
 create mode 100644 station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/LevelMixin.java
 create mode 100644 station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockRenderer.java
 create mode 100644 station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinClass417.java

diff --git a/src/test/java/net/modificationstation/sltest/block/Blocks.java b/src/test/java/net/modificationstation/sltest/block/Blocks.java
index d0c7e41f1..74e38e182 100644
--- a/src/test/java/net/modificationstation/sltest/block/Blocks.java
+++ b/src/test/java/net/modificationstation/sltest/block/Blocks.java
@@ -21,7 +21,8 @@ public enum Blocks {
     CUSTOM_MODEL_BLOCK("farlands_block", "farlands_block", id -> new ModdedModelBlock(id, Material.DIRT).setHardness(1)),
     FREEZER("freezer", "freezer", id -> new BlockFreezer(id).setHardness(2.5F).setSounds(TemplateBlockBase.STONE_SOUNDS)),
     ALTAR("altar", "altar", id -> new BlockAltar(id, Material.STONE).setHardness(3)),
-    VARIATION_BLOCK("variation_block", "variationBlock", id -> new VariationBlock(id, Material.STONE).setHardness(.5F).setSounds(BlockBase.STONE_SOUNDS).disableAutomaticBlockItemRegistration());
+    VARIATION_BLOCK("variation_block", "variationBlock", id -> new VariationBlock(id, Material.STONE).setHardness(.5F).setSounds(BlockBase.STONE_SOUNDS).disableAutomaticBlockItemRegistration()),
+    EMISSION_CHECKER("emission_checker", "emissionChecker", LampBlock::new);
 
     private final Runnable register;
     private BlockBase block;
diff --git a/src/test/java/net/modificationstation/sltest/block/LampBlock.java b/src/test/java/net/modificationstation/sltest/block/LampBlock.java
new file mode 100644
index 000000000..fad36d476
--- /dev/null
+++ b/src/test/java/net/modificationstation/sltest/block/LampBlock.java
@@ -0,0 +1,52 @@
+package net.modificationstation.sltest.block;
+
+import net.minecraft.block.BlockBase;
+import net.minecraft.block.material.Material;
+import net.minecraft.entity.player.PlayerBase;
+import net.minecraft.level.BlockView;
+import net.minecraft.level.Level;
+import net.modificationstation.stationapi.api.block.BlockState;
+import net.modificationstation.stationapi.api.registry.Identifier;
+import net.modificationstation.stationapi.api.state.StateManager.Builder;
+import net.modificationstation.stationapi.api.state.property.BooleanProperty;
+import net.modificationstation.stationapi.api.template.block.TemplateBlockBase;
+import net.modificationstation.stationapi.api.world.BlockStateView;
+
+public class LampBlock extends TemplateBlockBase {
+	private static final BooleanProperty ACTIVE = BooleanProperty.of("active");
+	
+	public LampBlock(Identifier id) {
+		super(id, Material.WOOD);
+		setEmittance(state -> state.get(ACTIVE) ? 15 : 0);
+		setTranslationKey(id);
+		setSounds(WOOD_SOUNDS);
+		setDefaultState(getDefaultState().with(ACTIVE, false));
+	}
+	
+	@Override
+	public void appendProperties(Builder<BlockBase, BlockState> builder) {
+		super.appendProperties(builder);
+		builder.add(ACTIVE);
+	}
+	
+	@Override
+	public int getTextureForSide(BlockView view, int x, int y, int z, int side) {
+		if (view instanceof BlockStateView stateView) {
+			return stateView.getBlockState(x, y, z).get(ACTIVE) ? STILL_LAVA.texture : OBSIDIAN.texture;
+		}
+		return OBSIDIAN.texture;
+	}
+	
+	@Override
+	public int getTextureForSide(int side) {
+		return OBSIDIAN.texture;
+	}
+	
+	@Override
+	public boolean canUse(Level level, int x, int y, int z, PlayerBase player) {
+		BlockState state = level.getBlockState(x, y, z);
+		state = state.with(ACTIVE, !state.get(ACTIVE));
+		level.setBlockState(x, y, z, state);
+		return super.canUse(level, x, y, z, player);
+	}
+}
diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/api/block/StationBlock.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/api/block/StationBlock.java
index 0c36b17e9..f62628838 100644
--- a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/api/block/StationBlock.java
+++ b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/api/block/StationBlock.java
@@ -6,6 +6,8 @@
 import net.modificationstation.stationapi.api.registry.RemappableRawIdHolder;
 import net.modificationstation.stationapi.api.util.Util;
 
+import java.util.function.Function;
+
 public interface StationBlock extends RemappableRawIdHolder {
 
     default BlockBase setTranslationKey(ModID modID, String translationKey) {
@@ -15,4 +17,12 @@ default BlockBase setTranslationKey(ModID modID, String translationKey) {
     default BlockBase setTranslationKey(Identifier translationKey) {
         return Util.assertImpl();
     }
+    
+    default BlockBase setEmittance(Function<BlockState, Integer> provider) {
+       return Util.assertImpl();
+    }
+    
+    default int getEmittance(BlockState state) {
+        return Util.assertImpl();
+    }
 }
diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/impl/block/BlockBrightness.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/impl/block/BlockBrightness.java
new file mode 100644
index 000000000..57fa8aa55
--- /dev/null
+++ b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/impl/block/BlockBrightness.java
@@ -0,0 +1,9 @@
+package net.modificationstation.stationapi.impl.block;
+
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
+
+@Environment(EnvType.CLIENT)
+public class BlockBrightness {
+	public static int light;
+}
diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/LevelMixin.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/LevelMixin.java
new file mode 100644
index 000000000..18bad655b
--- /dev/null
+++ b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/LevelMixin.java
@@ -0,0 +1,22 @@
+package net.modificationstation.stationapi.mixin.block;
+
+import com.llamalad7.mixinextras.sugar.Local;
+import net.minecraft.level.Level;
+import net.modificationstation.stationapi.api.block.BlockState;
+import net.modificationstation.stationapi.api.world.BlockStateView;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.ModifyVariable;
+
+@Mixin(Level.class)
+public abstract class LevelMixin implements BlockStateView {
+	@ModifyVariable(
+		method = "method_165(Lnet/minecraft/level/LightType;IIII)V",
+		at = @At(value = "STORE", ordinal = 1), index = 5
+	)
+	private int getStateEmittance(int original, @Local(index = 2) int x, @Local(index = 3) int y, @Local(index = 4) int z, @Local(index = 5) int light) {
+		BlockState state = getBlockState(x, y, z);
+		int l = state.getBlock().getEmittance(state);
+		return l > light ? l : light;
+	}
+}
diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
index 495464f6c..443a37c6c 100644
--- a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
+++ b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
@@ -1,17 +1,32 @@
 package net.modificationstation.stationapi.mixin.block;
 
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
 import net.minecraft.block.BlockBase;
+import net.modificationstation.stationapi.api.block.BlockState;
 import net.modificationstation.stationapi.api.block.StationBlock;
 import net.modificationstation.stationapi.api.registry.Identifier;
 import net.modificationstation.stationapi.api.registry.ModID;
+import net.modificationstation.stationapi.impl.block.BlockBrightness;
+import org.spongepowered.asm.mixin.Final;
 import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.Unique;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.ModifyArg;
+
+import java.util.function.Function;
 
 @Mixin(BlockBase.class)
 public abstract class MixinBlockBase implements StationBlock {
+    @Unique private Function<BlockState, Integer> emittanceProvider;
 
     @Shadow public abstract BlockBase setTranslationKey(String string);
-
+    
+    @Shadow @Final public static BlockBase JACK_O_LANTERN;
+    
+    @Shadow @Final public int id;
+    
     @Override
     public BlockBase setTranslationKey(ModID modID, String translationKey) {
         return setTranslationKey(Identifier.of(modID, translationKey).toString());
@@ -21,4 +36,28 @@ public BlockBase setTranslationKey(ModID modID, String translationKey) {
     public BlockBase setTranslationKey(Identifier translationKey) {
         return setTranslationKey(translationKey.toString());
     }
+    
+    @Override
+    public BlockBase setEmittance(Function<BlockState, Integer> provider) {
+        emittanceProvider = provider;
+        
+        // Need for proper functionality of LevelMixin
+        BlockBase.EMITTANCE[BlockBase.class.cast(this).id] = 15;
+        
+        return BlockBase.class.cast(this);
+    }
+    
+    @Override
+    public int getEmittance(BlockState state) {
+        if (emittanceProvider != null) {
+            return emittanceProvider.apply(state);
+        }
+        return BlockBase.EMITTANCE[state.getBlock().id];
+    }
+    
+    @Environment(value= EnvType.CLIENT)
+    @ModifyArg(method = "getBrightness", at = @At(value = "INVOKE", target = "Lnet/minecraft/level/BlockView;method_1784(IIII)F"), index = 3)
+    private int getStateBrightness(int original) {
+        return BlockBrightness.light;
+    }
 }
diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockRenderer.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockRenderer.java
new file mode 100644
index 000000000..bd6ef0e10
--- /dev/null
+++ b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockRenderer.java
@@ -0,0 +1,27 @@
+package net.modificationstation.stationapi.mixin.block;
+
+import net.minecraft.block.BlockBase;
+import net.minecraft.client.render.block.BlockRenderer;
+import net.minecraft.level.BlockView;
+import net.modificationstation.stationapi.api.block.BlockState;
+import net.modificationstation.stationapi.api.world.BlockStateView;
+import net.modificationstation.stationapi.impl.block.BlockBrightness;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+@Mixin(value = BlockRenderer.class, priority = 500)
+public class MixinBlockRenderer {
+	@Shadow private BlockView blockView;
+	
+	@Inject(method = "render", at = @At("HEAD"))
+	private void captureLightEmission(BlockBase block, int x, int y, int z, CallbackInfoReturnable<Boolean> info) {
+		if (blockView instanceof BlockStateView stateView) {
+			BlockState state = stateView.getBlockState(x, y, z);
+			BlockBrightness.light = state.getBlock().getEmittance(state);
+		}
+		else BlockBrightness.light = BlockBase.EMITTANCE[block.id];
+	}
+}
diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinClass417.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinClass417.java
new file mode 100644
index 000000000..cd1bbf001
--- /dev/null
+++ b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinClass417.java
@@ -0,0 +1,21 @@
+package net.modificationstation.stationapi.mixin.block;
+
+import com.llamalad7.mixinextras.sugar.Local;
+import net.minecraft.class_417;
+import net.minecraft.level.Level;
+import net.modificationstation.stationapi.api.block.BlockState;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.ModifyVariable;
+
+@Mixin(class_417.class)
+public class MixinClass417 {
+	@ModifyVariable(
+		method = "method_1402(Lnet/minecraft/level/Level;)V",
+		at = @At(value = "STORE", ordinal = 2), index = 20
+	)
+	private int getStateEmittance(int original, @Local Level level, @Local(index = 10) int x, @Local(index = 15) int y, @Local(index = 11) int z) {
+		BlockState state = level.getBlockState(x, y, z);
+		return state.getBlock().getEmittance(state);
+	}
+}
diff --git a/station-blocks-v0/src/main/resources/station-blocks-v0.mixins.json b/station-blocks-v0/src/main/resources/station-blocks-v0.mixins.json
index 1036fa80a..07d60d2cc 100644
--- a/station-blocks-v0/src/main/resources/station-blocks-v0.mixins.json
+++ b/station-blocks-v0/src/main/resources/station-blocks-v0.mixins.json
@@ -1,23 +1,28 @@
 {
-  "required": true,
-  "minVersion": "0.8",
-  "package": "net.modificationstation.stationapi.mixin.block",
-  "compatibilityLevel": "JAVA_17",
-  "mixins": [
-    "AchievementGUIDAccessor",
-    "BlockBaseAccessor",
-    "FireAccessor",
-    "ItemBaseAccessor",
-    "MixinBlock",
-    "MixinBlockBase",
-    "MixinFire",
-    "MixinSecondaryBlock",
-    "MixinStats",
-    "StatAccessor",
-    "StatEntityAccessor",
-    "StatsAccessor"
-  ],
-  "injectors": {
-    "defaultRequire": 1
-  }
+	"required": true,
+	"minVersion": "0.8",
+	"package": "net.modificationstation.stationapi.mixin.block",
+	"compatibilityLevel": "JAVA_17",
+	"mixins": [
+		"AchievementGUIDAccessor",
+		"BlockBaseAccessor",
+		"FireAccessor",
+		"ItemBaseAccessor",
+		"LevelMixin",
+		"MixinBlock",
+		"MixinBlockBase",
+		"MixinClass417",
+		"MixinFire",
+		"MixinSecondaryBlock",
+		"MixinStats",
+		"StatAccessor",
+		"StatEntityAccessor",
+		"StatsAccessor"
+	],
+	"injectors": {
+		"defaultRequire": 1
+	},
+	"client": [
+		"MixinBlockRenderer"
+	]
 }

From df053006e7ecc4d4952c89c5cc47e09ab0bcca4d Mon Sep 17 00:00:00 2001
From: paulevsGitch <paulevs@yandex.ru>
Date: Sat, 21 Oct 2023 10:11:02 +0300
Subject: [PATCH 2/5] ToIntFunction instead of Function

---
 .../stationapi/api/block/StationBlock.java               | 3 ++-
 .../stationapi/mixin/block/MixinBlockBase.java           | 9 ++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/api/block/StationBlock.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/api/block/StationBlock.java
index f62628838..06201df24 100644
--- a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/api/block/StationBlock.java
+++ b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/api/block/StationBlock.java
@@ -7,6 +7,7 @@
 import net.modificationstation.stationapi.api.util.Util;
 
 import java.util.function.Function;
+import java.util.function.ToIntFunction;
 
 public interface StationBlock extends RemappableRawIdHolder {
 
@@ -18,7 +19,7 @@ default BlockBase setTranslationKey(Identifier translationKey) {
         return Util.assertImpl();
     }
     
-    default BlockBase setEmittance(Function<BlockState, Integer> provider) {
+    default BlockBase setEmittance(ToIntFunction<BlockState> provider) {
        return Util.assertImpl();
     }
     
diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
index 443a37c6c..620b33077 100644
--- a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
+++ b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
@@ -16,15 +16,14 @@
 import org.spongepowered.asm.mixin.injection.ModifyArg;
 
 import java.util.function.Function;
+import java.util.function.ToIntFunction;
 
 @Mixin(BlockBase.class)
 public abstract class MixinBlockBase implements StationBlock {
-    @Unique private Function<BlockState, Integer> emittanceProvider;
+    @Unique private ToIntFunction<BlockState> emittanceProvider;
 
     @Shadow public abstract BlockBase setTranslationKey(String string);
     
-    @Shadow @Final public static BlockBase JACK_O_LANTERN;
-    
     @Shadow @Final public int id;
     
     @Override
@@ -38,7 +37,7 @@ public BlockBase setTranslationKey(Identifier translationKey) {
     }
     
     @Override
-    public BlockBase setEmittance(Function<BlockState, Integer> provider) {
+    public BlockBase setEmittance(ToIntFunction<BlockState> provider) {
         emittanceProvider = provider;
         
         // Need for proper functionality of LevelMixin
@@ -50,7 +49,7 @@ public BlockBase setEmittance(Function<BlockState, Integer> provider) {
     @Override
     public int getEmittance(BlockState state) {
         if (emittanceProvider != null) {
-            return emittanceProvider.apply(state);
+            return emittanceProvider.applyAsInt(state);
         }
         return BlockBase.EMITTANCE[state.getBlock().id];
     }

From 951373ddfd89e8120c3898f9b3573d30cc277039 Mon Sep 17 00:00:00 2001
From: paulevsGitch <paulevs@yandex.ru>
Date: Sat, 21 Oct 2023 10:20:59 +0300
Subject: [PATCH 3/5] Removed redundant cast

---
 .../stationapi/mixin/block/MixinBlockBase.java             | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
index 620b33077..bdffcf41c 100644
--- a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
+++ b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
@@ -20,12 +20,11 @@
 
 @Mixin(BlockBase.class)
 public abstract class MixinBlockBase implements StationBlock {
-    @Unique private ToIntFunction<BlockState> emittanceProvider;
-
     @Shadow public abstract BlockBase setTranslationKey(String string);
-    
     @Shadow @Final public int id;
     
+    @Unique private ToIntFunction<BlockState> emittanceProvider;
+    
     @Override
     public BlockBase setTranslationKey(ModID modID, String translationKey) {
         return setTranslationKey(Identifier.of(modID, translationKey).toString());
@@ -41,7 +40,7 @@ public BlockBase setEmittance(ToIntFunction<BlockState> provider) {
         emittanceProvider = provider;
         
         // Need for proper functionality of LevelMixin
-        BlockBase.EMITTANCE[BlockBase.class.cast(this).id] = 15;
+        BlockBase.EMITTANCE[id] = 15;
         
         return BlockBase.class.cast(this);
     }

From 3110ea32c5fe8149a9fd7b3fe13ffe5295eb79ac Mon Sep 17 00:00:00 2001
From: paulevsGitch <paulevs@yandex.ru>
Date: Sat, 21 Oct 2023 17:16:04 +0300
Subject: [PATCH 4/5] Small optimisation

---
 .../stationapi/mixin/block/MixinBlockBase.java        | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
index bdffcf41c..893004b1c 100644
--- a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
+++ b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
@@ -3,6 +3,7 @@
 import net.fabricmc.api.EnvType;
 import net.fabricmc.api.Environment;
 import net.minecraft.block.BlockBase;
+import net.minecraft.block.material.Material;
 import net.modificationstation.stationapi.api.block.BlockState;
 import net.modificationstation.stationapi.api.block.StationBlock;
 import net.modificationstation.stationapi.api.registry.Identifier;
@@ -13,9 +14,10 @@
 import org.spongepowered.asm.mixin.Shadow;
 import org.spongepowered.asm.mixin.Unique;
 import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
 import org.spongepowered.asm.mixin.injection.ModifyArg;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
 
-import java.util.function.Function;
 import java.util.function.ToIntFunction;
 
 @Mixin(BlockBase.class)
@@ -23,7 +25,7 @@ public abstract class MixinBlockBase implements StationBlock {
     @Shadow public abstract BlockBase setTranslationKey(String string);
     @Shadow @Final public int id;
     
-    @Unique private ToIntFunction<BlockState> emittanceProvider;
+    @Unique private ToIntFunction<BlockState> emittanceProvider = state -> BlockBase.EMITTANCE[state.getBlock().id];
     
     @Override
     public BlockBase setTranslationKey(ModID modID, String translationKey) {
@@ -47,10 +49,7 @@ public BlockBase setEmittance(ToIntFunction<BlockState> provider) {
     
     @Override
     public int getEmittance(BlockState state) {
-        if (emittanceProvider != null) {
-            return emittanceProvider.applyAsInt(state);
-        }
-        return BlockBase.EMITTANCE[state.getBlock().id];
+        return emittanceProvider.applyAsInt(state);
     }
     
     @Environment(value= EnvType.CLIENT)

From a586c6466881ccbc4f4bf141f3d8b105bdf574d3 Mon Sep 17 00:00:00 2001
From: mineLdiver <aabesedin@mail.ru>
Date: Tue, 24 Oct 2023 17:09:24 +0500
Subject: [PATCH 5/5] Moved to flattening module. Renamed emittance to
 luminance. Implemented caching in BlockState. Reindented files.

---
 .../sltest/block/LampBlock.java               | 72 +++++++++----------
 .../stationapi/api/block/StationBlock.java    | 11 ---
 .../stationapi/mixin/block/LevelMixin.java    | 22 ------
 .../mixin/block/MixinBlockBase.java           | 40 +----------
 .../stationapi/mixin/block/MixinClass417.java | 21 ------
 .../resources/station-blocks-v0.mixins.json   | 47 ++++++------
 .../api/block/AbstractBlockState.java         |  6 +-
 .../api/block/StationFlatteningBlock.java     |  5 ++
 .../impl/block/BlockBrightness.java           |  2 +-
 .../block/StationFlatteningBlockInternal.java |  9 +++
 .../mixin/flattening/MixinBlockBase.java      | 31 +++++++-
 .../mixin/flattening/MixinClass417.java       | 19 +++--
 .../mixin/flattening/MixinLevel.java          | 13 ++++
 .../client}/MixinBlockRenderer.java           | 22 +++---
 .../station-flattening-v0.mixins.json         |  5 +-
 15 files changed, 150 insertions(+), 175 deletions(-)
 delete mode 100644 station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/LevelMixin.java
 delete mode 100644 station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinClass417.java
 rename {station-blocks-v0 => station-flattening-v0}/src/main/java/net/modificationstation/stationapi/impl/block/BlockBrightness.java (86%)
 create mode 100644 station-flattening-v0/src/main/java/net/modificationstation/stationapi/impl/block/StationFlatteningBlockInternal.java
 rename {station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block => station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/client}/MixinBlockRenderer.java (56%)

diff --git a/src/test/java/net/modificationstation/sltest/block/LampBlock.java b/src/test/java/net/modificationstation/sltest/block/LampBlock.java
index fad36d476..cdf7694d8 100644
--- a/src/test/java/net/modificationstation/sltest/block/LampBlock.java
+++ b/src/test/java/net/modificationstation/sltest/block/LampBlock.java
@@ -13,40 +13,40 @@
 import net.modificationstation.stationapi.api.world.BlockStateView;
 
 public class LampBlock extends TemplateBlockBase {
-	private static final BooleanProperty ACTIVE = BooleanProperty.of("active");
-	
-	public LampBlock(Identifier id) {
-		super(id, Material.WOOD);
-		setEmittance(state -> state.get(ACTIVE) ? 15 : 0);
-		setTranslationKey(id);
-		setSounds(WOOD_SOUNDS);
-		setDefaultState(getDefaultState().with(ACTIVE, false));
-	}
-	
-	@Override
-	public void appendProperties(Builder<BlockBase, BlockState> builder) {
-		super.appendProperties(builder);
-		builder.add(ACTIVE);
-	}
-	
-	@Override
-	public int getTextureForSide(BlockView view, int x, int y, int z, int side) {
-		if (view instanceof BlockStateView stateView) {
-			return stateView.getBlockState(x, y, z).get(ACTIVE) ? STILL_LAVA.texture : OBSIDIAN.texture;
-		}
-		return OBSIDIAN.texture;
-	}
-	
-	@Override
-	public int getTextureForSide(int side) {
-		return OBSIDIAN.texture;
-	}
-	
-	@Override
-	public boolean canUse(Level level, int x, int y, int z, PlayerBase player) {
-		BlockState state = level.getBlockState(x, y, z);
-		state = state.with(ACTIVE, !state.get(ACTIVE));
-		level.setBlockState(x, y, z, state);
-		return super.canUse(level, x, y, z, player);
-	}
+    private static final BooleanProperty ACTIVE = BooleanProperty.of("active");
+
+    public LampBlock(Identifier id) {
+        super(id, Material.WOOD);
+        setLuminance(state -> state.get(ACTIVE) ? 15 : 0);
+        setTranslationKey(id);
+        setSounds(WOOD_SOUNDS);
+        setDefaultState(getDefaultState().with(ACTIVE, false));
+    }
+
+    @Override
+    public void appendProperties(Builder<BlockBase, BlockState> builder) {
+        super.appendProperties(builder);
+        builder.add(ACTIVE);
+    }
+
+    @Override
+    public int getTextureForSide(BlockView view, int x, int y, int z, int side) {
+        if (view instanceof BlockStateView stateView) {
+            return stateView.getBlockState(x, y, z).get(ACTIVE) ? STILL_LAVA.texture : OBSIDIAN.texture;
+        }
+        return OBSIDIAN.texture;
+    }
+
+    @Override
+    public int getTextureForSide(int side) {
+        return OBSIDIAN.texture;
+    }
+
+    @Override
+    public boolean canUse(Level level, int x, int y, int z, PlayerBase player) {
+        BlockState state = level.getBlockState(x, y, z);
+        state = state.with(ACTIVE, !state.get(ACTIVE));
+        level.setBlockState(x, y, z, state);
+        return super.canUse(level, x, y, z, player);
+    }
 }
diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/api/block/StationBlock.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/api/block/StationBlock.java
index 06201df24..0c36b17e9 100644
--- a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/api/block/StationBlock.java
+++ b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/api/block/StationBlock.java
@@ -6,9 +6,6 @@
 import net.modificationstation.stationapi.api.registry.RemappableRawIdHolder;
 import net.modificationstation.stationapi.api.util.Util;
 
-import java.util.function.Function;
-import java.util.function.ToIntFunction;
-
 public interface StationBlock extends RemappableRawIdHolder {
 
     default BlockBase setTranslationKey(ModID modID, String translationKey) {
@@ -18,12 +15,4 @@ default BlockBase setTranslationKey(ModID modID, String translationKey) {
     default BlockBase setTranslationKey(Identifier translationKey) {
         return Util.assertImpl();
     }
-    
-    default BlockBase setEmittance(ToIntFunction<BlockState> provider) {
-       return Util.assertImpl();
-    }
-    
-    default int getEmittance(BlockState state) {
-        return Util.assertImpl();
-    }
 }
diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/LevelMixin.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/LevelMixin.java
deleted file mode 100644
index 18bad655b..000000000
--- a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/LevelMixin.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package net.modificationstation.stationapi.mixin.block;
-
-import com.llamalad7.mixinextras.sugar.Local;
-import net.minecraft.level.Level;
-import net.modificationstation.stationapi.api.block.BlockState;
-import net.modificationstation.stationapi.api.world.BlockStateView;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.ModifyVariable;
-
-@Mixin(Level.class)
-public abstract class LevelMixin implements BlockStateView {
-	@ModifyVariable(
-		method = "method_165(Lnet/minecraft/level/LightType;IIII)V",
-		at = @At(value = "STORE", ordinal = 1), index = 5
-	)
-	private int getStateEmittance(int original, @Local(index = 2) int x, @Local(index = 3) int y, @Local(index = 4) int z, @Local(index = 5) int light) {
-		BlockState state = getBlockState(x, y, z);
-		int l = state.getBlock().getEmittance(state);
-		return l > light ? l : light;
-	}
-}
diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
index 893004b1c..495464f6c 100644
--- a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
+++ b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockBase.java
@@ -1,32 +1,17 @@
 package net.modificationstation.stationapi.mixin.block;
 
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
 import net.minecraft.block.BlockBase;
-import net.minecraft.block.material.Material;
-import net.modificationstation.stationapi.api.block.BlockState;
 import net.modificationstation.stationapi.api.block.StationBlock;
 import net.modificationstation.stationapi.api.registry.Identifier;
 import net.modificationstation.stationapi.api.registry.ModID;
-import net.modificationstation.stationapi.impl.block.BlockBrightness;
-import org.spongepowered.asm.mixin.Final;
 import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.Shadow;
-import org.spongepowered.asm.mixin.Unique;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.ModifyArg;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-
-import java.util.function.ToIntFunction;
 
 @Mixin(BlockBase.class)
 public abstract class MixinBlockBase implements StationBlock {
+
     @Shadow public abstract BlockBase setTranslationKey(String string);
-    @Shadow @Final public int id;
-    
-    @Unique private ToIntFunction<BlockState> emittanceProvider = state -> BlockBase.EMITTANCE[state.getBlock().id];
-    
+
     @Override
     public BlockBase setTranslationKey(ModID modID, String translationKey) {
         return setTranslationKey(Identifier.of(modID, translationKey).toString());
@@ -36,25 +21,4 @@ public BlockBase setTranslationKey(ModID modID, String translationKey) {
     public BlockBase setTranslationKey(Identifier translationKey) {
         return setTranslationKey(translationKey.toString());
     }
-    
-    @Override
-    public BlockBase setEmittance(ToIntFunction<BlockState> provider) {
-        emittanceProvider = provider;
-        
-        // Need for proper functionality of LevelMixin
-        BlockBase.EMITTANCE[id] = 15;
-        
-        return BlockBase.class.cast(this);
-    }
-    
-    @Override
-    public int getEmittance(BlockState state) {
-        return emittanceProvider.applyAsInt(state);
-    }
-    
-    @Environment(value= EnvType.CLIENT)
-    @ModifyArg(method = "getBrightness", at = @At(value = "INVOKE", target = "Lnet/minecraft/level/BlockView;method_1784(IIII)F"), index = 3)
-    private int getStateBrightness(int original) {
-        return BlockBrightness.light;
-    }
 }
diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinClass417.java b/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinClass417.java
deleted file mode 100644
index cd1bbf001..000000000
--- a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinClass417.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package net.modificationstation.stationapi.mixin.block;
-
-import com.llamalad7.mixinextras.sugar.Local;
-import net.minecraft.class_417;
-import net.minecraft.level.Level;
-import net.modificationstation.stationapi.api.block.BlockState;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.ModifyVariable;
-
-@Mixin(class_417.class)
-public class MixinClass417 {
-	@ModifyVariable(
-		method = "method_1402(Lnet/minecraft/level/Level;)V",
-		at = @At(value = "STORE", ordinal = 2), index = 20
-	)
-	private int getStateEmittance(int original, @Local Level level, @Local(index = 10) int x, @Local(index = 15) int y, @Local(index = 11) int z) {
-		BlockState state = level.getBlockState(x, y, z);
-		return state.getBlock().getEmittance(state);
-	}
-}
diff --git a/station-blocks-v0/src/main/resources/station-blocks-v0.mixins.json b/station-blocks-v0/src/main/resources/station-blocks-v0.mixins.json
index 07d60d2cc..1036fa80a 100644
--- a/station-blocks-v0/src/main/resources/station-blocks-v0.mixins.json
+++ b/station-blocks-v0/src/main/resources/station-blocks-v0.mixins.json
@@ -1,28 +1,23 @@
 {
-	"required": true,
-	"minVersion": "0.8",
-	"package": "net.modificationstation.stationapi.mixin.block",
-	"compatibilityLevel": "JAVA_17",
-	"mixins": [
-		"AchievementGUIDAccessor",
-		"BlockBaseAccessor",
-		"FireAccessor",
-		"ItemBaseAccessor",
-		"LevelMixin",
-		"MixinBlock",
-		"MixinBlockBase",
-		"MixinClass417",
-		"MixinFire",
-		"MixinSecondaryBlock",
-		"MixinStats",
-		"StatAccessor",
-		"StatEntityAccessor",
-		"StatsAccessor"
-	],
-	"injectors": {
-		"defaultRequire": 1
-	},
-	"client": [
-		"MixinBlockRenderer"
-	]
+  "required": true,
+  "minVersion": "0.8",
+  "package": "net.modificationstation.stationapi.mixin.block",
+  "compatibilityLevel": "JAVA_17",
+  "mixins": [
+    "AchievementGUIDAccessor",
+    "BlockBaseAccessor",
+    "FireAccessor",
+    "ItemBaseAccessor",
+    "MixinBlock",
+    "MixinBlockBase",
+    "MixinFire",
+    "MixinSecondaryBlock",
+    "MixinStats",
+    "StatAccessor",
+    "StatEntityAccessor",
+    "StatsAccessor"
+  ],
+  "injectors": {
+    "defaultRequire": 1
+  }
 }
diff --git a/station-flattening-v0/src/main/java/net/modificationstation/stationapi/api/block/AbstractBlockState.java b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/api/block/AbstractBlockState.java
index 304e04eb0..8ed56ca68 100644
--- a/station-flattening-v0/src/main/java/net/modificationstation/stationapi/api/block/AbstractBlockState.java
+++ b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/api/block/AbstractBlockState.java
@@ -16,6 +16,7 @@
 import net.modificationstation.stationapi.api.state.property.Property;
 import net.modificationstation.stationapi.api.tag.TagKey;
 import net.modificationstation.stationapi.api.util.math.MathHelper;
+import net.modificationstation.stationapi.impl.block.StationFlatteningBlockInternal;
 
 import java.util.function.Predicate;
 import java.util.stream.Stream;
@@ -26,6 +27,7 @@ public abstract class AbstractBlockState extends State<BlockBase, BlockState> {
     private final MaterialColour materialColor;
     private final boolean toolRequired;
     private final boolean opaque;
+    private int luminance = -1;
 
     protected AbstractBlockState(BlockBase block, ImmutableMap<Property<?>, Comparable<?>> propertyMap, MapCodec<BlockState> mapCodec) {
         super(block, propertyMap, mapCodec);
@@ -48,7 +50,9 @@ public Material getMaterial() {
      * Returns the light level emitted by this block state.
      */
     public int getLuminance() {
-        return BlockBase.EMITTANCE[owner.id];
+        return luminance == -1 ?
+                luminance = ((StationFlatteningBlockInternal) owner).stationapi_getLuminanceProvider().applyAsInt(asBlockState()) :
+                luminance;
     }
 
     public boolean isAir() {
diff --git a/station-flattening-v0/src/main/java/net/modificationstation/stationapi/api/block/StationFlatteningBlock.java b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/api/block/StationFlatteningBlock.java
index 31d1203b5..46688bef1 100644
--- a/station-flattening-v0/src/main/java/net/modificationstation/stationapi/api/block/StationFlatteningBlock.java
+++ b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/api/block/StationFlatteningBlock.java
@@ -17,6 +17,7 @@
 import org.jetbrains.annotations.ApiStatus;
 
 import java.util.List;
+import java.util.function.ToIntFunction;
 
 public interface StationFlatteningBlock extends
         RemappableRawIdHolder,
@@ -103,4 +104,8 @@ default boolean canReplace(BlockState state, ItemPlacementContext context) {
     default void onBlockPlaced(Level world, int x, int y, int z, BlockState replacedState) {
         Util.assertImpl();
     }
+
+    default BlockBase setLuminance(ToIntFunction<BlockState> provider) {
+        return Util.assertImpl();
+    }
 }
diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/impl/block/BlockBrightness.java b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/impl/block/BlockBrightness.java
similarity index 86%
rename from station-blocks-v0/src/main/java/net/modificationstation/stationapi/impl/block/BlockBrightness.java
rename to station-flattening-v0/src/main/java/net/modificationstation/stationapi/impl/block/BlockBrightness.java
index 57fa8aa55..a4b519004 100644
--- a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/impl/block/BlockBrightness.java
+++ b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/impl/block/BlockBrightness.java
@@ -5,5 +5,5 @@
 
 @Environment(EnvType.CLIENT)
 public class BlockBrightness {
-	public static int light;
+    public static int light;
 }
diff --git a/station-flattening-v0/src/main/java/net/modificationstation/stationapi/impl/block/StationFlatteningBlockInternal.java b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/impl/block/StationFlatteningBlockInternal.java
new file mode 100644
index 000000000..7e5bfb9c0
--- /dev/null
+++ b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/impl/block/StationFlatteningBlockInternal.java
@@ -0,0 +1,9 @@
+package net.modificationstation.stationapi.impl.block;
+
+import net.modificationstation.stationapi.api.block.BlockState;
+
+import java.util.function.ToIntFunction;
+
+public interface StationFlatteningBlockInternal {
+    ToIntFunction<BlockState> stationapi_getLuminanceProvider();
+}
diff --git a/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/MixinBlockBase.java b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/MixinBlockBase.java
index 803885fe3..0b8f019ba 100644
--- a/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/MixinBlockBase.java
+++ b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/MixinBlockBase.java
@@ -1,5 +1,7 @@
 package net.modificationstation.stationapi.mixin.flattening;
 
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
 import net.minecraft.block.BlockBase;
 import net.minecraft.block.material.Material;
 import net.minecraft.entity.player.PlayerBase;
@@ -19,16 +21,19 @@
 import net.modificationstation.stationapi.api.registry.RegistryEntry;
 import net.modificationstation.stationapi.api.registry.sync.trackers.*;
 import net.modificationstation.stationapi.api.state.StateManager;
+import net.modificationstation.stationapi.impl.block.BlockBrightness;
 import net.modificationstation.stationapi.impl.block.BlockDropListImpl;
+import net.modificationstation.stationapi.impl.block.StationFlatteningBlockInternal;
 import org.objectweb.asm.Opcodes;
 import org.spongepowered.asm.mixin.*;
 import org.spongepowered.asm.mixin.injection.*;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
 
 import java.util.List;
+import java.util.function.ToIntFunction;
 
 @Mixin(BlockBase.class)
-public abstract class MixinBlockBase implements StationFlatteningBlock {
+public abstract class MixinBlockBase implements StationFlatteningBlock, StationFlatteningBlockInternal {
 
     @Shadow public abstract void beforeDestroyedByExplosion(Level arg, int i, int j, int k, int l, float f);
 
@@ -318,4 +323,28 @@ private int ensureCapacity(int rawId) {
     private static ItemBase onlyUnderShift(ItemBase[] array, int index) {
         return index < ItemRegistry.ID_SHIFT ? array[index] : null;
     }
+
+    @Unique private ToIntFunction<BlockState> stationapi_luminance = state -> BlockBase.EMITTANCE[state.getBlock().id];
+
+    @Override
+    public BlockBase setLuminance(ToIntFunction<BlockState> provider) {
+        stationapi_luminance = provider;
+
+        // Need for proper functionality of LevelMixin
+        BlockBase.EMITTANCE[id] = 15;
+
+        return BlockBase.class.cast(this);
+    }
+
+    @Override
+    @Unique
+    public ToIntFunction<BlockState> stationapi_getLuminanceProvider() {
+        return stationapi_luminance;
+    }
+
+    @Environment(value= EnvType.CLIENT)
+    @ModifyArg(method = "getBrightness", at = @At(value = "INVOKE", target = "Lnet/minecraft/level/BlockView;method_1784(IIII)F"), index = 3)
+    private int getStateBrightness(int original) {
+        return BlockBrightness.light;
+    }
 }
diff --git a/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/MixinClass417.java b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/MixinClass417.java
index b2443896f..32052a76a 100644
--- a/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/MixinClass417.java
+++ b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/MixinClass417.java
@@ -1,13 +1,11 @@
 package net.modificationstation.stationapi.mixin.flattening;
 
+import com.llamalad7.mixinextras.sugar.Local;
 import net.minecraft.class_417;
 import net.minecraft.level.Level;
 import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.Unique;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Constant;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.ModifyConstant;
+import org.spongepowered.asm.mixin.injection.*;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
 
 @Mixin(class_417.class)
@@ -21,7 +19,6 @@ private void method_1869(Level level, CallbackInfo info) {
         minBlock = (short) level.getBottomY();
     }
 
-    @SuppressWarnings("MixinAnnotationTarget")
     @ModifyConstant(method = "method_1402(Lnet/minecraft/level/Level;)V", constant = @Constant(expandZeroConditions = Constant.Condition.GREATER_THAN_OR_EQUAL_TO_ZERO, ordinal = 0))
     private int changeMinHeight(int value) {
         return minBlock;
@@ -41,4 +38,16 @@ private int changeMaxHeight(int value) {
     private int changeMaxHeightFallback(int value) {
         return maxBlock - 1;
     }
+
+    @ModifyVariable(
+            method = "method_1402(Lnet/minecraft/level/Level;)V",
+            at = @At(
+                    value = "STORE",
+                    ordinal = 2
+            ),
+            index = 20
+    )
+    private int getStateLuminance(int original, @Local Level level, @Local(index = 10) int x, @Local(index = 15) int y, @Local(index = 11) int z) {
+        return level.getBlockState(x, y, z).getLuminance();
+    }
 }
diff --git a/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/MixinLevel.java b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/MixinLevel.java
index 00ede8e46..dc03b491c 100644
--- a/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/MixinLevel.java
+++ b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/MixinLevel.java
@@ -214,4 +214,17 @@ public int getBottomY() {
     private BlockBase accountForAirBlock(BlockBase value) {
         return value == States.AIR.get().getBlock() ? null : value;
     }
+
+    @ModifyVariable(
+            method = "method_165(Lnet/minecraft/level/LightType;IIII)V",
+            at = @At(
+                    value = "STORE",
+                    ordinal = 1
+            ),
+            index = 5,
+            argsOnly = true
+    )
+    private int getStateLuminance(int original, @Local(index = 2) int x, @Local(index = 3) int y, @Local(index = 4) int z, @Local(index = 5) int light) {
+        return Math.max(getBlockState(x, y, z).getLuminance(), light);
+    }
 }
diff --git a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockRenderer.java b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/client/MixinBlockRenderer.java
similarity index 56%
rename from station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockRenderer.java
rename to station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/client/MixinBlockRenderer.java
index bd6ef0e10..07cc3a2a4 100644
--- a/station-blocks-v0/src/main/java/net/modificationstation/stationapi/mixin/block/MixinBlockRenderer.java
+++ b/station-flattening-v0/src/main/java/net/modificationstation/stationapi/mixin/flattening/client/MixinBlockRenderer.java
@@ -1,4 +1,4 @@
-package net.modificationstation.stationapi.mixin.block;
+package net.modificationstation.stationapi.mixin.flattening.client;
 
 import net.minecraft.block.BlockBase;
 import net.minecraft.client.render.block.BlockRenderer;
@@ -14,14 +14,14 @@
 
 @Mixin(value = BlockRenderer.class, priority = 500)
 public class MixinBlockRenderer {
-	@Shadow private BlockView blockView;
-	
-	@Inject(method = "render", at = @At("HEAD"))
-	private void captureLightEmission(BlockBase block, int x, int y, int z, CallbackInfoReturnable<Boolean> info) {
-		if (blockView instanceof BlockStateView stateView) {
-			BlockState state = stateView.getBlockState(x, y, z);
-			BlockBrightness.light = state.getBlock().getEmittance(state);
-		}
-		else BlockBrightness.light = BlockBase.EMITTANCE[block.id];
-	}
+    @Shadow private BlockView blockView;
+
+    @Inject(method = "render", at = @At("HEAD"))
+    private void captureLightEmission(BlockBase block, int x, int y, int z, CallbackInfoReturnable<Boolean> info) {
+        if (blockView instanceof BlockStateView stateView) {
+            BlockState state = stateView.getBlockState(x, y, z);
+            BlockBrightness.light = state.getLuminance();
+        }
+        else BlockBrightness.light = BlockBase.EMITTANCE[block.id];
+    }
 }
diff --git a/station-flattening-v0/src/main/resources/station-flattening-v0.mixins.json b/station-flattening-v0/src/main/resources/station-flattening-v0.mixins.json
index 70daffa1d..478387a2f 100644
--- a/station-flattening-v0/src/main/resources/station-flattening-v0.mixins.json
+++ b/station-flattening-v0/src/main/resources/station-flattening-v0.mixins.json
@@ -34,6 +34,8 @@
     "RegionFileAccessor"
   ],
   "client": [
+    "client.MixinBaseClientInteractionManager",
+    "client.MixinBlockRenderer",
     "client.MixinClientLevel",
     "client.MixinInGame",
     "client.MixinMinecraft",
@@ -41,8 +43,7 @@
     "client.MixinMultiPlayerClientInteractionManager",
     "client.MixinPlayerRenderer",
     "client.MixinSinglePlayerClientInteractionManager",
-    "client.MixinWorldRenderer",
-    "client.MixinBaseClientInteractionManager"
+    "client.MixinWorldRenderer"
   ],
   "injectors": {
     "defaultRequire": 1