[Block|Item] 'name' property renamed to 'stringID' for more coherency.
This commit is contained in:
parent
888db4e241
commit
2c5f289ef1
@ -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);
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,10 +35,10 @@
|
||||
class Registry : public ISerializable {
|
||||
public:
|
||||
template<typename T>
|
||||
auto registerBlock(const TilesDef &tiles, const std::string &id, const std::string &name) -> typename std::enable_if<std::is_base_of<Block, T>::value, T&>::type {
|
||||
u32 internalID = m_blocks.size();
|
||||
m_blocksID.emplace(id, internalID);
|
||||
m_blocks.emplace_back(std::make_unique<T>(internalID, tiles, id, name));
|
||||
auto registerBlock(const TilesDef &tiles, const std::string &stringID, const std::string &label) -> typename std::enable_if<std::is_base_of<Block, T>::value, T&>::type {
|
||||
u32 id = m_blocks.size();
|
||||
m_blocksID.emplace(stringID, id);
|
||||
m_blocks.emplace_back(std::make_unique<T>(id, tiles, stringID, label));
|
||||
return *static_cast<T*>(m_blocks.back().get());
|
||||
}
|
||||
|
||||
@ -47,13 +47,13 @@ class Registry : public ISerializable {
|
||||
m_blocks.emplace_back(std::make_unique<T>());
|
||||
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<T*>(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<typename T, typename... Args>
|
||||
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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>();
|
||||
std::string name = table["name"].get<std::string>();
|
||||
std::string stringID = m_id + ":" + table["id"].get<std::string>();
|
||||
std::string label = table["name"].get<std::string>();
|
||||
sol::function onBlockActivated = table["on_block_activated"];
|
||||
sol::function onTick = table["on_tick"];
|
||||
|
||||
ServerBlock &block = Registry::getInstance().registerBlock<ServerBlock>(tiles, id, name);
|
||||
ServerBlock &block = Registry::getInstance().registerBlock<ServerBlock>(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>();
|
||||
std::string name = table["name"].get<std::string>();
|
||||
std::string stringID = table["id"].get<std::string>();
|
||||
std::string label = table["name"].get<std::string>();
|
||||
|
||||
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));
|
||||
|
@ -106,7 +106,7 @@ void ScriptEngine::initUsertypes() {
|
||||
|
||||
m_lua.new_usertype<Item>("Item",
|
||||
"id", &Item::id,
|
||||
"name", &Item::name,
|
||||
"stringID", &Item::stringID,
|
||||
"burn_time", &Item::burnTime
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user