Groups can now be used in recipes.
This commit is contained in:
parent
786aaff198
commit
266e4b7453
@ -184,12 +184,12 @@ mod:block {
|
||||
end
|
||||
|
||||
if ticks_remaining == 0 and recipe and fuel_stack:amount() > 0 and
|
||||
fuel_stack:item():has_group("om_fuel") and
|
||||
fuel_stack:item():has_group("group:om_fuel") 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():string_id(), fuel_stack:amount() - 1)
|
||||
ticks_remaining = fuel_stack:item():get_group_value("om_fuel")
|
||||
current_burn_time = fuel_stack:item():get_group_value("om_fuel")
|
||||
ticks_remaining = fuel_stack:item():get_group_value("group:om_fuel")
|
||||
current_burn_time = fuel_stack:item():get_group_value("group:om_fuel")
|
||||
data.use_alt_tiles = true;
|
||||
-- world:set_data(pos.x, pos.y, pos.z, 1)
|
||||
elseif ticks_remaining > 0 then
|
||||
|
@ -178,8 +178,8 @@ void MouseItemWidget::updateCurrentItem(ItemWidget *currentItemWidget) {
|
||||
m_currentItemWidget = (currentItemWidget->stack().item().id()) ? currentItemWidget : nullptr;
|
||||
m_tooltipText.setText(currentItemWidget->stack().item().label() + " [" + std::to_string(currentItemWidget->stack().item().id()) + "]");
|
||||
|
||||
if (currentItemWidget->stack().item().hasGroup("om_fuel"))
|
||||
m_tooltipInfoText.setText("Burn time: " + std::to_string(currentItemWidget->stack().item().getGroupValue("om_fuel")) + " ticks");
|
||||
if (currentItemWidget->stack().item().hasGroup("group:om_fuel"))
|
||||
m_tooltipInfoText.setText("Burn time: " + std::to_string(currentItemWidget->stack().item().getGroupValue("group:om_fuel")) + " ticks");
|
||||
else
|
||||
m_tooltipInfoText.setText("");
|
||||
}
|
||||
|
@ -100,17 +100,17 @@ 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().stringID();
|
||||
const Item &item = inventory.getStack(offsetX + x, offsetY + y).item();
|
||||
if (m_pattern[y][x] == ' ') {
|
||||
itemFound = (inventoryItem.empty() || inventoryItem == "_:air");
|
||||
itemFound = (item.stringID().empty() || item.stringID() == "_:air");
|
||||
}
|
||||
else {
|
||||
auto it = m_keys.find(m_pattern[y][x]);
|
||||
if (it == m_keys.end())
|
||||
throw EXCEPTION("Recipe error: Invalid key char(", (int)m_pattern[y][x], ")'");
|
||||
|
||||
for (const std::string &item : it->second) {
|
||||
if (item == inventoryItem)
|
||||
for (const std::string &itemID : it->second) {
|
||||
if (itemID == item.stringID() || (itemID.substr(0, 6) == "group:" && item.hasGroup(itemID)))
|
||||
itemFound = true;
|
||||
}
|
||||
}
|
||||
|
@ -26,20 +26,26 @@
|
||||
*/
|
||||
#include "SmeltingRecipe.hpp"
|
||||
|
||||
SmeltingRecipe::SmeltingRecipe(const ItemStack &input, const ItemStack &output) : Recipe("smelt", output) {
|
||||
m_input = input;
|
||||
SmeltingRecipe::SmeltingRecipe(const std::string &inputID, u16 inputAmount, const ItemStack &output) : Recipe("smelt", output) {
|
||||
m_inputID = inputID;
|
||||
m_inputAmount = inputAmount;
|
||||
}
|
||||
|
||||
void SmeltingRecipe::serialize(sf::Packet &packet) const {
|
||||
packet << m_result << m_input;
|
||||
packet << m_result << m_inputID << m_inputAmount;
|
||||
}
|
||||
|
||||
void SmeltingRecipe::deserialize(sf::Packet &packet) {
|
||||
packet >> m_result >> m_input;
|
||||
packet >> m_result >> m_inputID >> m_inputAmount;
|
||||
}
|
||||
|
||||
bool SmeltingRecipe::isMatching(const Inventory &inventory) const {
|
||||
return (inventory.getStack(0, 0).item().id() == m_input.item().id()
|
||||
&& inventory.getStack(0, 0).amount() >= m_input.amount());
|
||||
bool isItemMatching = true;
|
||||
if (m_inputID.substr(0, 6) == "group:")
|
||||
isItemMatching = inventory.getStack(0, 0).item().hasGroup(m_inputID);
|
||||
else
|
||||
isItemMatching = (inventory.getStack(0, 0).item().stringID() == m_inputID);
|
||||
|
||||
return isItemMatching && inventory.getStack(0, 0).amount() >= m_inputAmount;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
class SmeltingRecipe : public Recipe {
|
||||
public:
|
||||
SmeltingRecipe() : Recipe("smelt") {}
|
||||
SmeltingRecipe(const ItemStack &input, const ItemStack &output);
|
||||
SmeltingRecipe(const std::string &inputID, u16 inputAmount, const ItemStack &output);
|
||||
|
||||
void serialize(sf::Packet &packet) const override;
|
||||
void deserialize(sf::Packet &packet) override;
|
||||
@ -40,7 +40,8 @@ class SmeltingRecipe : public Recipe {
|
||||
bool isMatching(const Inventory &inventory) const override;
|
||||
|
||||
private:
|
||||
ItemStack m_input;
|
||||
std::string m_inputID;
|
||||
u16 m_inputAmount = 0;
|
||||
};
|
||||
|
||||
#endif // SMELTINGRECIPE_HPP_
|
||||
|
@ -57,16 +57,14 @@ void LuaRecipeLoader::loadSmeltingRecipe(const sol::table &table) const {
|
||||
sol::table inputTable = table["input"];
|
||||
sol::table outputTable = table["output"];
|
||||
|
||||
ItemStack input = {
|
||||
inputTable["id"].get<std::string>(),
|
||||
inputTable["amount"].get<u16>()
|
||||
};
|
||||
std::string inputID = inputTable["id"].get<std::string>();
|
||||
u16 inputAmount = inputTable["amount"].get<u16>();
|
||||
|
||||
ItemStack output = {
|
||||
outputTable["id"].get<std::string>(),
|
||||
outputTable["amount"].get<u16>()
|
||||
};
|
||||
|
||||
Registry::getInstance().registerRecipe<SmeltingRecipe>(input, output);
|
||||
Registry::getInstance().registerRecipe<SmeltingRecipe>(inputID, inputAmount, output);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user