Skip to content

Commit

Permalink
fix: special case for light[level=0] emission (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
mworzala authored Jul 24, 2024
1 parent bbd916c commit 100e30d
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.gson.JsonObject;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -62,7 +63,7 @@ public JsonObject generate() {
}
}
// Default values
writeState(block, defaultBlockState, null, blockJson);
writeState(location, block, defaultBlockState, null, blockJson);
{
// List of properties
JsonObject properties = new JsonObject();
Expand All @@ -83,7 +84,7 @@ public JsonObject generate() {
for (BlockState bs : block.getStateDefinition().getPossibleStates()) {
JsonObject state = new JsonObject();
state.addProperty("stateId", Block.BLOCK_STATE_REGISTRY.getId(bs));
writeState(block, bs, blockJson, state);
writeState(location, block, bs, blockJson, state);

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

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

0 comments on commit 100e30d

Please sign in to comment.