Skip to content

Commit

Permalink
Artisan Benches: Anvil: racial items can be crafted pnly by player of…
Browse files Browse the repository at this point in the history
… the same race. Closes #1852
  • Loading branch information
alek13 committed Dec 17, 2024
1 parent bd0d04e commit 317fea1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ local function get_craft_result(inv)
})
end

--- @param inv InvRef
local function make_result_prediction(inv)
local result = get_craft_result(inv)
--- @param inv InvRef
--- @param player Player
local function make_result_prediction(inv, player)
local result, _, recipe = get_craft_result(inv)
local player_race = races.get_race(player:get_player_name())

if recipe and recipe.for_race and recipe.for_race ~= player_race then
return
end

inv:set_list('craft_result', { result.item })
end

Expand All @@ -36,17 +43,17 @@ InventoryCallbacks = {
end,

on_put = function(inv, list_name, index, stack, player)
make_result_prediction(inv)
make_result_prediction(inv, player)
end,
on_move = function(inv, from_list, from_index, to_list, to_index, count, _)
make_result_prediction(inv)
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
make_result_prediction(inv, player)
end,

on_take = function(inv, list_name, index, stack, player)
if list_name == 'craft_result' then
do_craft(inv)
end
make_result_prediction(inv)
make_result_prediction(inv, player)
end,
}

Expand Down
2 changes: 1 addition & 1 deletion mods/lord/Tools/tools/mod.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = tools
depends = lord_overwrites_mtg_default, anvil
depends = lord_overwrites_mtg_default, anvil, lord_classes
36 changes: 21 additions & 15 deletions mods/lord/Tools/tools/src/racial.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,45 +63,51 @@ minetest.register_tool('tools:dagger_hobbit', {
})

minetest.register_craft({
method = minetest.CraftMethod.ANVIL,
output = 'tools:sword_elven',
recipe = {
method = minetest.CraftMethod.ANVIL,
output = 'tools:sword_elven',
for_race = races.name.ELF,
recipe = {
{ '', 'default:steel_ingot', '' },
{ 'default:bronze_ingot', 'default:steel_ingot', 'default:bronze_ingot' },
{ 'default:mese_crystal', 'group:stick', 'default:mese_crystal' },
}
})
minetest.register_mirrored_crafts({
method = minetest.CraftMethod.ANVIL,
output = 'tools:sword_orc',
recipe = {
method = minetest.CraftMethod.ANVIL,
output = 'tools:sword_orc',
for_race = races.name.ORC,
recipe = {
{ '', 'default:steel_ingot', 'default:steel_ingot' },
{ '', 'lottores:mithril_lump', '' },
{ '', 'default:mese_crystal', '' },
}
})
minetest.register_craft({
method = minetest.CraftMethod.ANVIL,
output = 'tools:battleaxe_dwarven',
recipe = {
method = minetest.CraftMethod.ANVIL,
output = 'tools:battleaxe_dwarven',
for_race = races.name.DWARF,
recipe = {
{ 'lottores:mithril_ingot', 'default:mese_crystal', 'lottores:mithril_ingot' },
{ 'lottores:mithril_ingot', 'group:stick', 'lottores:mithril_ingot' },
{ '', 'group:stick', '' }
}
})
minetest.register_craft({
method = minetest.CraftMethod.ANVIL,
output = 'tools:sword_human',
recipe = {
method = minetest.CraftMethod.ANVIL,
output = 'tools:sword_human',
for_race = races.name.HUMAN,
recipe = {
{ '', 'lottores:mithril_ingot', '' },
{ 'lottores:red_gem', 'lottores:mithril_ingot', 'lottores:red_gem' },
{ 'lottores:blue_gem', 'group:stick', 'lottores:blue_gem' },
}
})

minetest.register_craft({
method = minetest.CraftMethod.ANVIL,
output = 'tools:dagger_hobbit',
recipe = {
method = minetest.CraftMethod.ANVIL,
for_race = races.name.HOBBIT,
output = 'tools:dagger_hobbit',
recipe = {
{ '', 'default:mese_crystal', '' },
{ 'default:mese_crystal', 'tools:dagger_mithril', 'default:mese_crystal' },
{ '', '', '' }
Expand Down

0 comments on commit 317fea1

Please sign in to comment.