Handle invalid local palette block states

This commit is contained in:
DankParrot 2020-08-13 18:45:34 -07:00
parent ea2ff1b8fd
commit 2db8c240c1
3 changed files with 8 additions and 3 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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); }
};
}