diff --git a/src/data/IDMapper.h b/src/data/IDMapper.h index 93db410..ebfb2c8 100644 --- a/src/data/IDMapper.h +++ b/src/data/IDMapper.h @@ -36,7 +36,7 @@ namespace Feather AddMapping(m_NextID, value); } - inline int GetID(T& value) const + inline int GetID(const T& value) const { return m_ValueToID.at(value); } diff --git a/src/world/Chunk.cpp b/src/world/Chunk.cpp index 8b7a7f0..01e495e 100644 --- a/src/world/Chunk.cpp +++ b/src/world/Chunk.cpp @@ -63,6 +63,8 @@ namespace Feather } catch (std::out_of_range& err) { (void)err; + int defaultId = World::GLOBAL_PALETTE.GetDefaultID(); + section->localPalette.AddMapping(i, defaultId); Log::Warn("Chunk Section Palette maps id {} to invalid block state with name '{}'", i, name); continue; } diff --git a/src/world/Palette.h b/src/world/Palette.h index abbdee2..3285f1a 100644 --- a/src/world/Palette.h +++ b/src/world/Palette.h @@ -14,7 +14,7 @@ namespace Feather m_registry(registry) {} - virtual int GetID(T& value) const = 0; + virtual int GetID(const T& value) const = 0; virtual const T& ByID(int id) const = 0; }; @@ -29,7 +29,10 @@ namespace Feather m_defaultValue(defaultValue) {} - inline virtual int GetID(T& value) const final { return m_registry.GetID(value); } + inline const T& GetDefault() const { return *m_defaultValue; } + inline int GetDefaultID() const { return GetID(GetDefault()); } + + inline virtual int GetID(const T& value) const final { return m_registry.GetID(value); } inline virtual const T& ByID(int id) const final { return m_registry.ByID(id); } }; } \ No newline at end of file