Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/bedrock-block-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,9 +1062,27 @@ class BlockData::Impl {
return bName;
}

static std::optional<i32> LightLevelFromName(String const &bName) {
std::u8string const key = Namespace::Remove(bName);
std::u8string const prefix = u8"light_block_";
if (!key.starts_with(prefix)) {
return std::nullopt;
}
auto suffix = key.substr(prefix.size());
if (suffix.empty()) {
return std::nullopt;
}
if (auto level = strings::ToI32(suffix); level) {
return ClosedRange<i32>::Clamp(*level, 0, 15);
} else {
return std::nullopt;
}
}

static String LightBlock(String const &bName, CompoundTag const &s, Props &p, int outputDataVersion) {
auto level = s.int32(u8"block_light_level", 0);
p[u8"level"] = Int(level);
auto level = LightLevelFromName(bName);
auto levelFromState = ClosedRange<i32>::Clamp(s.int32(u8"block_light_level", 0), 0, 15);
p[u8"level"] = Int(level ? *level : levelFromState);
Submergible(s, p);
return Ns() + u8"light";
}
Expand Down Expand Up @@ -2940,6 +2958,16 @@ class BlockData::Impl {
E(lever, Lever);
E(lightning_rod, LightningRod);
E(light_block, LightBlock);
static std::array<std::u8string, 16> const sLightBlockNames = []() {
std::array<std::u8string, 16> ret{};
for (int level = 0; level < 16; level++) {
ret[level] = u8"light_block_" + mcfile::String::ToString(level);
}
return ret;
}();
for (auto const &name : sLightBlockNames) {
table->try_emplace(name, LightBlock);
}
E(light_weighted_pressure_plate, BlockWithPowerFromRedstoneSignal);
E(waterlily, Rename(u8"lily_pad"));
E(loom, BlockWithFacing4FromDirectionA);
Expand Down
7 changes: 4 additions & 3 deletions src/java-block-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2443,10 +2443,11 @@ class BlockData::Impl {
}

static CompoundTagPtr Light(Block const &b, CompoundTagConstPtr const &, Options const &o) {
auto c = New(u8"light_block");
auto s = States();
auto level = strings::ToI32(b.property(u8"level", u8"15"));
s->set(u8"block_light_level", Int(level ? *level : 15));
auto clamped = ClosedRange<i32>::Clamp(level ? *level : 15, 0, 15);
auto name = u8"light_block_" + mcfile::String::ToString(clamped);
auto c = New(name);
auto s = States();
return AttachStates(c, s);
}

Expand Down