Block groups added.
This commit is contained in:
parent
266e4b7453
commit
5c8d926315
@ -118,7 +118,11 @@ mod:block {
|
||||
mod:block {
|
||||
id = "oak_planks",
|
||||
name = "Oak Wood Planks",
|
||||
tiles = "oak_planks.png"
|
||||
tiles = "oak_planks.png",
|
||||
|
||||
groups = {
|
||||
om_planks = 1
|
||||
}
|
||||
}
|
||||
|
||||
mod:block {
|
||||
|
@ -513,7 +513,7 @@ mod:crafting_recipe {
|
||||
'#'
|
||||
},
|
||||
|
||||
keys = {['#'] = "default:oak_planks"}
|
||||
keys = {['#'] = "group:om_planks"}
|
||||
}
|
||||
|
||||
-- Planks
|
||||
@ -536,7 +536,7 @@ mod:crafting_recipe {
|
||||
"##",
|
||||
"##"
|
||||
},
|
||||
keys = {["#"] = "default:oak_planks"}
|
||||
keys = {["#"] = "group:om_planks"}
|
||||
}
|
||||
|
||||
-- Furnace
|
||||
|
@ -24,8 +24,6 @@
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include <iostream>
|
||||
|
||||
#include "Block.hpp"
|
||||
#include "NetworkUtils.hpp"
|
||||
#include "Player.hpp"
|
||||
@ -46,7 +44,7 @@ void Block::serialize(sf::Packet &packet) const {
|
||||
packet << u32(m_id) << m_stringID << m_label << u8(m_drawType)
|
||||
<< m_hardness << m_harvestRequirements << m_itemDrop << m_itemDropAmount << m_tiles
|
||||
<< m_boundingBox << m_isOpaque << m_isLightSource << m_canUpdate << m_canBeActivated
|
||||
<< m_colorMultiplier << m_isRotatable << m_inventoryImage;
|
||||
<< m_colorMultiplier << m_isRotatable << m_inventoryImage << m_groups;
|
||||
}
|
||||
|
||||
void Block::deserialize(sf::Packet &packet) {
|
||||
@ -56,7 +54,7 @@ void Block::deserialize(sf::Packet &packet) {
|
||||
packet >> id >> m_stringID >> m_label >> drawType
|
||||
>> m_hardness >> m_harvestRequirements >> m_itemDrop >> m_itemDropAmount >> m_tiles
|
||||
>> m_boundingBox >> m_isOpaque >> m_isLightSource >> m_canUpdate >> m_canBeActivated
|
||||
>> m_colorMultiplier >> m_isRotatable >> m_inventoryImage;
|
||||
>> m_colorMultiplier >> m_isRotatable >> m_inventoryImage >> m_groups;
|
||||
|
||||
m_id = id;
|
||||
m_drawType = BlockDrawType(drawType);
|
||||
|
@ -109,6 +109,17 @@ class Block : public ISerializable {
|
||||
const std::string &inventoryImage() const { return m_inventoryImage; }
|
||||
void setInventoryImage(const std::string &inventoryImage) { m_inventoryImage = inventoryImage; }
|
||||
|
||||
void addGroup(const std::string &name, u16 value) { m_groups.emplace(name, value); }
|
||||
bool hasGroup(const std::string &name) const { return m_groups.find(name) != m_groups.end(); }
|
||||
|
||||
u16 getGroupValue(const std::string &name) const {
|
||||
auto it = m_groups.find(name);
|
||||
if (it == m_groups.end())
|
||||
return 0;
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
protected:
|
||||
glm::vec4 getTexCoordsFromID(int textureID) const;
|
||||
|
||||
@ -141,6 +152,8 @@ class Block : public ISerializable {
|
||||
bool m_isRotatable = false;
|
||||
|
||||
std::string m_inventoryImage;
|
||||
|
||||
std::unordered_map<std::string, u16> m_groups;
|
||||
};
|
||||
|
||||
#endif // BLOCK_HPP_
|
||||
|
@ -46,12 +46,17 @@ void LuaBlockLoader::loadBlock(const sol::table &table) const {
|
||||
loadItemDrop(block, table);
|
||||
loadColorMultiplier(block, table);
|
||||
|
||||
Item *item = nullptr;
|
||||
if (!block.inventoryImage().empty()) {
|
||||
Registry::getInstance().registerItem(TilesDef{block.inventoryImage()}, stringID, label).setIsBlock(true);
|
||||
item = &Registry::getInstance().registerItem(TilesDef{block.inventoryImage()}, stringID, label);
|
||||
}
|
||||
else {
|
||||
Registry::getInstance().registerItem(block.tiles(), stringID, label).setIsBlock(true);
|
||||
item = &Registry::getInstance().registerItem(block.tiles(), stringID, label);
|
||||
}
|
||||
|
||||
item->setIsBlock(true);
|
||||
|
||||
loadGroups(block, *item, table);
|
||||
}
|
||||
|
||||
inline void LuaBlockLoader::loadProperties(ServerBlock &block, const sol::table &table) const {
|
||||
@ -126,3 +131,21 @@ inline void LuaBlockLoader::loadColorMultiplier(ServerBlock &block, const sol::t
|
||||
}
|
||||
}
|
||||
|
||||
inline void LuaBlockLoader::loadGroups(ServerBlock &block, Item &item, const sol::table &table) const {
|
||||
sol::object groupsObject = table["groups"];
|
||||
if (groupsObject.valid()) {
|
||||
if (groupsObject.get_type() == sol::type::table) {
|
||||
sol::table groupsTable = groupsObject.as<sol::table>();
|
||||
for (auto &groupObject : groupsTable) {
|
||||
std::string groupName = "group:" + groupObject.first.as<std::string>();
|
||||
u16 groupValue = groupObject.second.as<u16>();
|
||||
|
||||
block.addGroup(groupName, groupValue);
|
||||
item.addGroup(groupName, groupValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
DEBUG("ERROR: For block '" + block.stringID() + "': 'groups' should be a table");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include <sol.hpp>
|
||||
|
||||
class Item;
|
||||
class LuaMod;
|
||||
class ServerBlock;
|
||||
|
||||
@ -45,6 +46,8 @@ class LuaBlockLoader {
|
||||
void loadItemDrop(ServerBlock &block, const sol::table &table) const;
|
||||
void loadColorMultiplier(ServerBlock &block, const sol::table &table) const;
|
||||
|
||||
void loadGroups(ServerBlock &block, Item &item, const sol::table &table) const;
|
||||
|
||||
LuaMod &m_mod;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user