Skip to content

Commit 100e30d

Browse files
authored
fix: special case for light[level=0] emission (#29)
1 parent bbd916c commit 100e30d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

DataGenerator/src/main/java/net/minestom/generators/BlockGenerator.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.google.gson.JsonObject;
66
import net.minecraft.core.BlockPos;
77
import net.minecraft.core.registries.BuiltInRegistries;
8+
import net.minecraft.resources.ResourceLocation;
89
import net.minecraft.world.item.Item;
910
import net.minecraft.world.level.EmptyBlockGetter;
1011
import net.minecraft.world.level.block.Block;
@@ -62,7 +63,7 @@ public JsonObject generate() {
6263
}
6364
}
6465
// Default values
65-
writeState(block, defaultBlockState, null, blockJson);
66+
writeState(location, block, defaultBlockState, null, blockJson);
6667
{
6768
// List of properties
6869
JsonObject properties = new JsonObject();
@@ -83,7 +84,7 @@ public JsonObject generate() {
8384
for (BlockState bs : block.getStateDefinition().getPossibleStates()) {
8485
JsonObject state = new JsonObject();
8586
state.addProperty("stateId", Block.BLOCK_STATE_REGISTRY.getId(bs));
86-
writeState(block, bs, blockJson, state);
87+
writeState(location, block, bs, blockJson, state);
8788

8889
StringBuilder stateName = new StringBuilder("[");
8990
for (var propertyEntry : bs.getValues().entrySet()) {
@@ -123,11 +124,17 @@ public JsonObject generate() {
123124
return blocks;
124125
}
125126

126-
private void writeState(Block block, BlockState blockState, JsonObject blockJson, JsonObject state) {
127+
private void writeState(ResourceLocation location, Block block, BlockState blockState, JsonObject blockJson, JsonObject state) {
127128
// Data
128129
appendState(blockJson, state, "canRespawnIn", block.isPossibleToRespawnInThis(blockState), boolean.class);
129130
appendState(blockJson, state, "hardness", blockState.getDestroySpeed(EmptyBlockGetter.INSTANCE, BlockPos.ZERO), float.class);
130-
appendState(blockJson, state, "lightEmission", blockState.getLightEmission(), 0, int.class);
131+
if (location.toString().equals("minecraft:light")) {
132+
// This is a bad special case for light blocks. minecraft:light[level=0] has an emission value of 0, but the default
133+
// state has an emission value of 15 meaning if this is omitted light 0 will have an emission of 15.
134+
appendState(blockJson, state, "lightEmission", blockState.getLightEmission(), 15, int.class);
135+
} else {
136+
appendState(blockJson, state, "lightEmission", blockState.getLightEmission(), 0, int.class);
137+
}
131138
appendState(blockJson, state, "pushReaction", blockState.getPistonPushReaction().name(), String.class);
132139
appendState(blockJson, state, "mapColorId", blockState.getMapColor(EmptyBlockGetter.INSTANCE, BlockPos.ZERO).id, int.class);
133140
appendState(blockJson, state, "occludes", blockState.canOcclude(), boolean.class);

0 commit comments

Comments
 (0)