From 2c5f289ef172fcb0dca2e6ee7c8fe6c5ffa38f9e Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Mon, 17 Feb 2020 15:54:19 +0900 Subject: [PATCH] [Block|Item] 'name' property renamed to 'stringID' for more coherency. --- client/source/gui/CraftingWidget.cpp | 4 ++-- client/source/gui/MouseItemWidget.cpp | 20 ++++++++-------- client/source/hud/BlockCursor.cpp | 4 ++-- client/source/hud/BlockInfoWidget.cpp | 2 +- client/source/hud/Hotbar.cpp | 2 +- common/include/core/Registry.hpp | 18 +++++++------- common/include/inventory/Inventory.hpp | 4 ++-- common/include/inventory/Item.hpp | 8 +++---- common/include/inventory/ItemStack.hpp | 8 +++---- common/include/world/Block.hpp | 8 +++---- common/source/core/Registry.cpp | 28 +++++++++++----------- common/source/inventory/CraftingRecipe.cpp | 2 +- common/source/inventory/Inventory.cpp | 14 +++++------ common/source/inventory/Item.cpp | 8 +++---- common/source/inventory/ItemStack.cpp | 10 ++++---- common/source/world/Block.cpp | 10 ++++---- mods/default/furnace.lua | 6 ++--- server/source/lua/LuaMod.cpp | 14 +++++------ server/source/lua/ScriptEngine.cpp | 2 +- 19 files changed, 86 insertions(+), 86 deletions(-) diff --git a/client/source/gui/CraftingWidget.cpp b/client/source/gui/CraftingWidget.cpp index e7cc6305..deea6958 100644 --- a/client/source/gui/CraftingWidget.cpp +++ b/client/source/gui/CraftingWidget.cpp @@ -45,7 +45,7 @@ void CraftingWidget::onMouseEvent(const SDL_Event &event, MouseItemWidget &mouse for (u8 y = 0 ; y < m_craftingInventory.height() ; ++y) { const ItemStack &stack = m_craftingInventory.getStack(x, y); if (stack.item().id()) { - m_craftingInventory.setStack(x, y, (stack.amount() > 1) ? stack.item().name() : "", stack.amount() - 1); + m_craftingInventory.setStack(x, y, (stack.amount() > 1) ? stack.item().stringID() : "", stack.amount() - 1); } } } @@ -65,7 +65,7 @@ void CraftingWidget::update() { m_recipe = recipe; if (m_recipe) - m_craftingResultInventory.setStack(0, 0, m_recipe->result().item().name(), m_recipe->result().amount()); + m_craftingResultInventory.setStack(0, 0, m_recipe->result().item().stringID(), m_recipe->result().amount()); else m_craftingResultInventory.setStack(0, 0, "", 0); diff --git a/client/source/gui/MouseItemWidget.cpp b/client/source/gui/MouseItemWidget.cpp index ff3caf40..2b51ba56 100644 --- a/client/source/gui/MouseItemWidget.cpp +++ b/client/source/gui/MouseItemWidget.cpp @@ -58,12 +58,12 @@ void MouseItemWidget::updateCurrentItem(const ItemWidget *currentItemWidget) { } void MouseItemWidget::swapItems(ItemWidget &widget, bool isReadOnly) { - std::string widgetItemName = widget.stack().item().name(); + std::string widgetItemName = widget.stack().item().stringID(); u32 widgetItemAmount = widget.stack().amount(); - if (!isReadOnly || stack().item().id() == 0 || stack().item().name() == widgetItemName) { - if (stack().item().name() != widgetItemName) { - widget.setStack(stack().item().name(), stack().amount()); + if (!isReadOnly || stack().item().id() == 0 || stack().item().stringID() == widgetItemName) { + if (stack().item().stringID() != widgetItemName) { + widget.setStack(stack().item().stringID(), stack().amount()); setStack(widgetItemName, widgetItemAmount); } else if (!isReadOnly) { @@ -71,24 +71,24 @@ void MouseItemWidget::swapItems(ItemWidget &widget, bool isReadOnly) { setStack("", 0); } else { - setStack(stack().item().name(), stack().amount() + widgetItemAmount); + setStack(stack().item().stringID(), stack().amount() + widgetItemAmount); widget.setStack("", 0); } } } void MouseItemWidget::putItem(ItemWidget &widget) { - std::string widgetItemName = widget.stack().item().name(); + std::string widgetItemName = widget.stack().item().stringID(); u32 widgetItemID = widget.stack().item().id(); u32 widgetItemAmount = widget.stack().amount(); if (!widgetItemID && stack().item().id()) { - widget.setStack(stack().item().name(), 1); - setStack(stack().amount() > 1 ? stack().item().name() : "", stack().amount() - 1); + widget.setStack(stack().item().stringID(), 1); + setStack(stack().amount() > 1 ? stack().item().stringID() : "", stack().amount() - 1); } else if (widgetItemID && widgetItemID == stack().item().id()) { - widget.setStack(stack().item().name(), widgetItemAmount + 1); - setStack(stack().amount() > 1 ? stack().item().name() : "", stack().amount() - 1); + widget.setStack(stack().item().stringID(), widgetItemAmount + 1); + setStack(stack().amount() > 1 ? stack().item().stringID() : "", stack().amount() - 1); } else if (stack().item().id() == 0) { setStack(widgetItemName, ceil(widgetItemAmount / 2.0)); diff --git a/client/source/hud/BlockCursor.cpp b/client/source/hud/BlockCursor.cpp index 6d6b140d..d11da337 100644 --- a/client/source/hud/BlockCursor.cpp +++ b/client/source/hud/BlockCursor.cpp @@ -117,7 +117,7 @@ void BlockCursor::onEvent(const SDL_Event &event, const Hotbar &hotbar) { m_client.sendPlayerPlaceBlock(x, y, z, hotbar.currentItem()); const ItemStack ¤tStack = m_player.inventory().getStack(hotbar.cursorPos(), 0); - m_player.inventory().setStack(hotbar.cursorPos(), 0, currentStack.amount() > 1 ? currentStack.item().name() : "", currentStack.amount() - 1); + m_player.inventory().setStack(hotbar.cursorPos(), 0, currentStack.amount() > 1 ? currentStack.item().stringID() : "", currentStack.amount() - 1); m_client.sendPlayerInvUpdate(); } @@ -160,7 +160,7 @@ void BlockCursor::update(const Hotbar &hotbar) { if (gk::GameClock::getTicks() > m_animationStart + timeToBreak * 1000) { ItemStack itemDrop = m_currentBlock->getItemDrop(); - m_player.inventory().addStack(itemDrop.item().name(), itemDrop.amount()); + m_player.inventory().addStack(itemDrop.item().stringID(), itemDrop.amount()); m_world.setBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z, 0); m_animationStart = gk::GameClock::getTicks(); diff --git a/client/source/hud/BlockInfoWidget.cpp b/client/source/hud/BlockInfoWidget.cpp index ea922177..1a23ab2b 100644 --- a/client/source/hud/BlockInfoWidget.cpp +++ b/client/source/hud/BlockInfoWidget.cpp @@ -45,7 +45,7 @@ void BlockInfoWidget::setCurrentBlock(const Block *block) { m_isVisible = true; m_text.setText(block->label()); - m_itemWidget.setStack(block->name(), 1); + m_itemWidget.setStack(block->stringID(), 1); } } diff --git a/client/source/hud/Hotbar.cpp b/client/source/hud/Hotbar.cpp index 7a5e0acd..d413d82a 100644 --- a/client/source/hud/Hotbar.cpp +++ b/client/source/hud/Hotbar.cpp @@ -53,7 +53,7 @@ void Hotbar::update() { widget.setPosition(5 + 20 * i - 3, 2, 0); } - m_items[i].setStack(m_inventory.getStack(i, 0).item().name(), m_inventory.getStack(i, 0).amount()); + m_items[i].setStack(m_inventory.getStack(i, 0).item().stringID(), m_inventory.getStack(i, 0).amount()); } } diff --git a/common/include/core/Registry.hpp b/common/include/core/Registry.hpp index 4e040094..216ab72a 100644 --- a/common/include/core/Registry.hpp +++ b/common/include/core/Registry.hpp @@ -35,10 +35,10 @@ class Registry : public ISerializable { public: template - auto registerBlock(const TilesDef &tiles, const std::string &id, const std::string &name) -> typename std::enable_if::value, T&>::type { - u32 internalID = m_blocks.size(); - m_blocksID.emplace(id, internalID); - m_blocks.emplace_back(std::make_unique(internalID, tiles, id, name)); + auto registerBlock(const TilesDef &tiles, const std::string &stringID, const std::string &label) -> typename std::enable_if::value, T&>::type { + u32 id = m_blocks.size(); + m_blocksID.emplace(stringID, id); + m_blocks.emplace_back(std::make_unique(id, tiles, stringID, label)); return *static_cast(m_blocks.back().get()); } @@ -47,13 +47,13 @@ class Registry : public ISerializable { m_blocks.emplace_back(std::make_unique()); m_blocks.back()->deserialize(packet); - u32 internalID = m_blocks.size() - 1; - m_blocksID.emplace(m_blocks.back()->name(), internalID); + u32 id = m_blocks.size() - 1; + m_blocksID.emplace(m_blocks.back()->stringID(), id); return *static_cast(m_blocks.back().get()); } - Item ®isterItem(const TilesDef &tiles, const std::string &id, const std::string &name); + Item ®isterItem(const TilesDef &tiles, const std::string &stringID, const std::string &name); Item ®isterSerializedItem(sf::Packet &packet); template @@ -65,8 +65,8 @@ class Registry : public ISerializable { const Block &getBlock(std::size_t id) const { return *m_blocks.at(id).get(); } const Item &getItem(std::size_t id) const { return m_items.at(id); } - const Block &getBlockFromStringID(const std::string &id); - const Item &getItemFromStringID(const std::string &id); + const Block &getBlockFromStringID(const std::string &stringID); + const Item &getItemFromStringID(const std::string &stringID); const Recipe *getRecipe(const Inventory &inventory) const; diff --git a/common/include/inventory/Inventory.hpp b/common/include/inventory/Inventory.hpp index 40e0ff32..2e2f7707 100644 --- a/common/include/inventory/Inventory.hpp +++ b/common/include/inventory/Inventory.hpp @@ -37,8 +37,8 @@ class Inventory : public ISerializable { const ItemStack &getStack(u16 x, u16 y) const { return m_items.at(x + y * m_width); } ItemStack &getStackRef(u16 x, u16 y) { return m_items.at(x + y * m_width); } - void setStack(u16 x, u16 y, const std::string &name, u16 amount = 1); - void addStack(const std::string &name, u16 amount = 1); + void setStack(u16 x, u16 y, const std::string &stringID, u16 amount = 1); + void addStack(const std::string &stringID, u16 amount = 1); void serialize(sf::Packet &packet) const override; void deserialize(sf::Packet &packet) override; diff --git a/common/include/inventory/Item.hpp b/common/include/inventory/Item.hpp index 498f1603..8c0169e3 100644 --- a/common/include/inventory/Item.hpp +++ b/common/include/inventory/Item.hpp @@ -34,15 +34,15 @@ class Item : public ISerializable { public: Item() = default; - Item(u32 id, const TilesDef &tiles, const std::string &name, const std::string &label); + Item(u32 id, const TilesDef &tiles, const std::string &stringID, const std::string &label); void serialize(sf::Packet &packet) const override; void deserialize(sf::Packet &packet) override; - const std::string &name() const { return m_name; } + const std::string &stringID() const { return m_stringID; } const std::string &label() const { return m_label; } - std::string modName() const { return m_name.substr(0, m_name.find_first_of(":")); } + std::string modName() const { return m_stringID.substr(0, m_stringID.find_first_of(":")); } u32 id() const { return m_id; } const TilesDef &tiles() const { return m_tiles; } @@ -72,7 +72,7 @@ class Item : public ISerializable { u32 m_id = 0; TilesDef m_tiles; - std::string m_name; + std::string m_stringID; std::string m_label; u8 m_harvestCapability = 0; diff --git a/common/include/inventory/ItemStack.hpp b/common/include/inventory/ItemStack.hpp index ba0de869..e868a597 100644 --- a/common/include/inventory/ItemStack.hpp +++ b/common/include/inventory/ItemStack.hpp @@ -30,17 +30,17 @@ namespace sf { class Packet; } class ItemStack { public: ItemStack() = default; - ItemStack(const std::string &name, u16 amount = 1) - : m_name(name), m_amount(amount) {} + ItemStack(const std::string &stringID, u16 amount = 1) + : m_stringID(stringID), m_amount(amount) {} const Item &item() const; - void setItem(const std::string &name) { m_name = name; } + void setItem(const std::string &stringID) { m_stringID = stringID; } u16 amount() const { return m_amount; } void setAmount(u16 amount) { m_amount = amount; } private: - std::string m_name; + std::string m_stringID; u16 m_amount = 0; }; diff --git a/common/include/world/Block.hpp b/common/include/world/Block.hpp index 3322eeef..40e8668d 100644 --- a/common/include/world/Block.hpp +++ b/common/include/world/Block.hpp @@ -49,7 +49,7 @@ enum class BlockDrawType { class Block : public ISerializable { public: Block() = default; - Block(u32 id, const TilesDef &tiles, const std::string &name, const std::string &label); + Block(u32 id, const TilesDef &tiles, const std::string &stringID, const std::string &label); virtual ~Block() = default; void serialize(sf::Packet &packet) const override; @@ -59,11 +59,11 @@ class Block : public ISerializable { u16 data() const { return (m_id >> 16) & 0xffff; } const TilesDef &tiles() const { return m_tiles; } - const std::string &name() const { return m_name; } + const std::string &stringID() const { return m_stringID; } const std::string &label() const { return m_label; } void setLabel(const std::string &label) { m_label = label; } - std::string modName() const { return m_name.substr(0, m_name.find_first_of(":")); } + std::string modName() const { return m_stringID.substr(0, m_stringID.find_first_of(":")); } bool isOpaque() const { return m_id != 0 && m_isOpaque && m_drawType != BlockDrawType::XShape; } void setOpaque(bool isOpaque) { m_isOpaque = isOpaque; } @@ -103,7 +103,7 @@ class Block : public ISerializable { u32 m_id = 0; TilesDef m_tiles; - std::string m_name; + std::string m_stringID; std::string m_label; std::string m_itemDrop; diff --git a/common/source/core/Registry.cpp b/common/source/core/Registry.cpp index e7750efa..49da54df 100644 --- a/common/source/core/Registry.cpp +++ b/common/source/core/Registry.cpp @@ -28,10 +28,10 @@ Registry *Registry::s_instance = nullptr; -Item &Registry::registerItem(const TilesDef &tiles, const std::string &id, const std::string &name) { - u32 internalID = m_items.size(); - m_itemsID.emplace(id, internalID); - m_items.emplace_back(internalID, tiles, id, name); +Item &Registry::registerItem(const TilesDef &tiles, const std::string &stringID, const std::string &label) { + u32 id = m_items.size(); + m_itemsID.emplace(stringID, id); + m_items.emplace_back(id, tiles, stringID, label); return m_items.back(); } @@ -39,25 +39,25 @@ Item &Registry::registerSerializedItem(sf::Packet &packet) { m_items.emplace_back(); m_items.back().deserialize(packet); - u32 internalID = m_items.size() - 1; - m_itemsID.emplace(m_items.back().name(), internalID); + u32 id = m_items.size() - 1; + m_itemsID.emplace(m_items.back().stringID(), id); return m_items.back(); } -const Block &Registry::getBlockFromStringID(const std::string &id) { - if (id.empty()) return getBlock(0); - auto it = m_blocksID.find(id); +const Block &Registry::getBlockFromStringID(const std::string &stringID) { + if (stringID.empty()) return getBlock(0); + auto it = m_blocksID.find(stringID); if (it == m_blocksID.end()) - throw EXCEPTION("Unknown block:", id); + throw EXCEPTION("Unknown block:", stringID); return getBlock(it->second); } -const Item &Registry::getItemFromStringID(const std::string &id) { - if (id.empty()) return getItem(0); - auto it = m_itemsID.find(id); +const Item &Registry::getItemFromStringID(const std::string &stringID) { + if (stringID.empty()) return getItem(0); + auto it = m_itemsID.find(stringID); if (it == m_itemsID.end()) - throw EXCEPTION("Unknown item:", id); + throw EXCEPTION("Unknown item:", stringID); return getItem(it->second); } diff --git a/common/source/inventory/CraftingRecipe.cpp b/common/source/inventory/CraftingRecipe.cpp index 66aa9625..a08e163a 100644 --- a/common/source/inventory/CraftingRecipe.cpp +++ b/common/source/inventory/CraftingRecipe.cpp @@ -96,7 +96,7 @@ bool CraftingRecipe::checkMatch(const Inventory &inventory, int offsetX, int off for (x = 0 ; x < m_pattern[y].size() ; ++x) { itemFound = false; - std::string inventoryItem = inventory.getStack(offsetX + x, offsetY + y).item().name(); + std::string inventoryItem = inventory.getStack(offsetX + x, offsetY + y).item().stringID(); if (m_pattern[y][x] == ' ') { itemFound = (inventoryItem.empty() || inventoryItem == "_:air"); } diff --git a/common/source/inventory/Inventory.cpp b/common/source/inventory/Inventory.cpp index ae551ce8..e9913ee8 100644 --- a/common/source/inventory/Inventory.cpp +++ b/common/source/inventory/Inventory.cpp @@ -23,20 +23,20 @@ #include "Inventory.hpp" #include "Network.hpp" -void Inventory::setStack(u16 x, u16 y, const std::string &name, u16 amount) { - m_items.at(x + y * m_width) = ItemStack(name, amount); +void Inventory::setStack(u16 x, u16 y, const std::string &stringID, u16 amount) { + m_items.at(x + y * m_width) = ItemStack(stringID, amount); m_hasChanged = true; } -void Inventory::addStack(const std::string &name, u16 amount) { +void Inventory::addStack(const std::string &stringID, u16 amount) { for (std::size_t i = 0 ; i < m_items.size() ; ++i) { if (m_items[i].item().id() == 0) { - m_items[i] = ItemStack(name, amount); + m_items[i] = ItemStack(stringID, amount); m_hasChanged = true; break; } - else if (m_items[i].item().name() == name) { - m_items[i] = ItemStack(name, m_items[i].amount() + amount); + else if (m_items[i].item().stringID() == stringID) { + m_items[i] = ItemStack(stringID, m_items[i].amount() + amount); m_hasChanged = true; break; } @@ -49,7 +49,7 @@ void Inventory::serialize(sf::Packet &packet) const { int i = 0; for (auto &it : m_items) { - packet << it.item().name() << it.amount() + packet << it.item().stringID() << it.amount() << u8(i % m_width) << u8(i / m_width); ++i; } diff --git a/common/source/inventory/Item.cpp b/common/source/inventory/Item.cpp index f54796c7..c4560105 100644 --- a/common/source/inventory/Item.cpp +++ b/common/source/inventory/Item.cpp @@ -24,21 +24,21 @@ #include "Item.hpp" -Item::Item(u32 id, const TilesDef &tiles, const std::string &name, const std::string &label) { +Item::Item(u32 id, const TilesDef &tiles, const std::string &stringID, const std::string &label) { m_id = id; m_tiles = tiles; - m_name = name; + m_stringID = stringID; m_label = label; } void Item::serialize(sf::Packet &packet) const { - packet << m_id << m_name << m_label << m_isBlock << m_isFuel + packet << m_id << m_stringID << m_label << m_isBlock << m_isFuel << m_burnTime << m_miningSpeed << m_harvestCapability << m_tiles; } void Item::deserialize(sf::Packet &packet) { - packet >> m_id >> m_name >> m_label >> m_isBlock >> m_isFuel + packet >> m_id >> m_stringID >> m_label >> m_isBlock >> m_isFuel >> m_burnTime >> m_miningSpeed >> m_harvestCapability >> m_tiles; } diff --git a/common/source/inventory/ItemStack.cpp b/common/source/inventory/ItemStack.cpp index 9ba0d3a6..8845f572 100644 --- a/common/source/inventory/ItemStack.cpp +++ b/common/source/inventory/ItemStack.cpp @@ -24,18 +24,18 @@ #include "Registry.hpp" const Item &ItemStack::item() const { - return Registry::getInstance().getItemFromStringID(m_name); + return Registry::getInstance().getItemFromStringID(m_stringID); } sf::Packet &operator<<(sf::Packet &packet, const ItemStack &itemStack) { - return packet << itemStack.item().name() << itemStack.amount(); + return packet << itemStack.item().stringID() << itemStack.amount(); } sf::Packet &operator>>(sf::Packet &packet, ItemStack &itemStack) { - std::string name; + std::string stringID; u16 amount; - packet >> name >> amount; - itemStack.setItem(name); + packet >> stringID >> amount; + itemStack.setItem(stringID); itemStack.setAmount(amount); return packet; } diff --git a/common/source/world/Block.cpp b/common/source/world/Block.cpp index 5e32e226..55e80618 100644 --- a/common/source/world/Block.cpp +++ b/common/source/world/Block.cpp @@ -28,19 +28,19 @@ #include "Player.hpp" #include "World.hpp" -Block::Block(u32 id, const TilesDef &tiles, const std::string &name, const std::string &label) { +Block::Block(u32 id, const TilesDef &tiles, const std::string &stringID, const std::string &label) { m_id = id; m_tiles = tiles; - m_name = name; + m_stringID = stringID; m_label = label; - m_itemDrop = name; + m_itemDrop = stringID; m_itemDropAmount = 1; } void Block::serialize(sf::Packet &packet) const { - packet << u32(m_id) << m_name << m_label << u8(m_drawType) + packet << u32(m_id) << m_stringID << m_label << u8(m_drawType) << m_hardness << m_harvestRequirements << m_itemDrop << m_itemDropAmount << m_tiles << m_boundingBox.x << m_boundingBox.y << m_boundingBox.z << m_boundingBox.width << m_boundingBox.height << m_boundingBox.depth @@ -51,7 +51,7 @@ void Block::deserialize(sf::Packet &packet) { u32 id; u8 drawType; - packet >> id >> m_name >> m_label >> drawType >> m_hardness + packet >> id >> m_stringID >> m_label >> drawType >> m_hardness >> m_harvestRequirements >> m_itemDrop >> m_itemDropAmount >> m_tiles >> m_boundingBox.x >> m_boundingBox.y >> m_boundingBox.z >> m_boundingBox.width >> m_boundingBox.height >> m_boundingBox.depth diff --git a/mods/default/furnace.lua b/mods/default/furnace.lua index 8f7b0f7f..91b5cba6 100644 --- a/mods/default/furnace.lua +++ b/mods/default/furnace.lua @@ -69,7 +69,7 @@ mod:block { if ticks_remaining == 0 and recipe and fuel_stack:amount() > 0 and (output_stack:item():id() == 0 or output_stack:amount() == 0 or output_stack:item():id() == recipe:result():item():id()) then - data.inventory:set_stack(2, 0, fuel_stack:item():name(), fuel_stack:amount() - 1) + data.inventory:set_stack(2, 0, fuel_stack:item():stringID(), fuel_stack:amount() - 1) ticks_remaining = fuel_stack:item():burn_time() current_burn_time = fuel_stack:item():burn_time() data.useAltTiles = true; @@ -91,8 +91,8 @@ mod:block { if item_progress >= 200 and recipe then item_progress = 0; - data.inventory:set_stack(0, 0, (input_stack:amount() - 1 > 0) and input_stack:item():name() or "", input_stack:amount() - 1) - data.inventory:set_stack(1, 0, recipe:result():item():name(), output_stack:amount() + recipe:result():amount()) + data.inventory:set_stack(0, 0, (input_stack:amount() - 1 > 0) and input_stack:item():stringID() or "", input_stack:amount() - 1) + data.inventory:set_stack(1, 0, recipe:result():item():stringID(), output_stack:amount() + recipe:result():amount()) end data.meta:set_int("ticks_remaining", ticks_remaining); diff --git a/server/source/lua/LuaMod.cpp b/server/source/lua/LuaMod.cpp index 62a78a1f..57130503 100644 --- a/server/source/lua/LuaMod.cpp +++ b/server/source/lua/LuaMod.cpp @@ -32,12 +32,12 @@ void LuaMod::registerBlock(const sol::table &table) { TilesDef tiles; tiles.loadFromLuaTable(table); - std::string id = m_id + ":" + table["id"].get(); - std::string name = table["name"].get(); + std::string stringID = m_id + ":" + table["id"].get(); + std::string label = table["name"].get(); sol::function onBlockActivated = table["on_block_activated"]; sol::function onTick = table["on_tick"]; - ServerBlock &block = Registry::getInstance().registerBlock(tiles, id, name); + ServerBlock &block = Registry::getInstance().registerBlock(tiles, stringID, label); block.setHarvestRequirements(table["harvest_requirements"].get_or(0)); block.setHardness(table["hardness"].get_or(1.0f)); block.setOpaque(table["is_opaque"].get_or(true)); @@ -71,17 +71,17 @@ void LuaMod::registerBlock(const sol::table &table) { block.setItemDrop(dropID, dropAmount); } - Registry::getInstance().registerItem(block.tiles(), id, name).setIsBlock(true); + Registry::getInstance().registerItem(block.tiles(), stringID, label).setIsBlock(true); } void LuaMod::registerItem(const sol::table &table) { TilesDef tiles; tiles.loadFromLuaTable(table); - std::string id = table["id"].get(); - std::string name = table["name"].get(); + std::string stringID = table["id"].get(); + std::string label = table["name"].get(); - Item &item = Registry::getInstance().registerItem(tiles, id, name); + Item &item = Registry::getInstance().registerItem(tiles, stringID, label); item.setIsFuel(table["is_fuel"].get_or(false)); item.setBurnTime(table["burn_time"].get_or(0)); item.setHarvestCapability(table["harvest_capability"].get_or(0)); diff --git a/server/source/lua/ScriptEngine.cpp b/server/source/lua/ScriptEngine.cpp index ce267be3..d54538e8 100644 --- a/server/source/lua/ScriptEngine.cpp +++ b/server/source/lua/ScriptEngine.cpp @@ -106,7 +106,7 @@ void ScriptEngine::initUsertypes() { m_lua.new_usertype("Item", "id", &Item::id, - "name", &Item::name, + "stringID", &Item::stringID, "burn_time", &Item::burnTime );