2017-02-27 23:34:35 -07:00
---------------------------------------------------------------------------------------
-- simple anvil that can be used to repair tools
---------------------------------------------------------------------------------------
-- * can be used to repair tools
2020-02-18 23:04:55 -07:00
-- * the hammer gets damaged a bit at each repair step
2017-02-27 23:34:35 -07:00
---------------------------------------------------------------------------------------
2017-05-30 09:25:14 +02:00
anvil = {
2019-01-19 14:50:39 +01:00
setting = {
2022-02-07 08:55:30 -08:00
item_displacement = 2 / 16 ,
2019-01-19 14:50:39 +01:00
}
2017-05-30 09:25:14 +02:00
}
2017-02-27 23:34:35 -07:00
minetest.register_alias ( " castle:anvil " , " anvil:anvil " )
2020-02-18 23:04:55 -07:00
local hammer_repairable = minetest.settings : get_bool ( " anvil_hammer_is_repairable " , true )
2022-02-09 14:44:13 -08:00
local hud_timeout = 2 -- seconds
2019-04-14 21:21:31 -06:00
2020-02-16 22:02:48 -07:00
anvil.make_unrepairable = function ( item_name )
2019-04-14 21:21:31 -06:00
local item_def = minetest.registered_items [ item_name ]
if item_def then
2020-11-30 20:21:07 +01:00
-- Drop table reference. Copy other values over.
2022-02-07 08:55:30 -08:00
local groups = { not_repaired_by_anvil = 1 }
for k , v in pairs ( item_def.groups ) do
groups [ k ] = v
end
2020-11-30 20:21:07 +01:00
minetest.override_item ( item_name , { groups = groups } )
2019-04-14 21:21:31 -06:00
end
end
2020-11-21 21:07:26 +01:00
2020-11-30 20:21:07 +01:00
if minetest.get_modpath ( " technic " ) then
-- make rechargeable technic tools unrepairable
anvil.make_unrepairable ( " technic:water_can " )
anvil.make_unrepairable ( " technic:lava_can " )
anvil.make_unrepairable ( " technic:flashlight " )
anvil.make_unrepairable ( " technic:battery " )
anvil.make_unrepairable ( " technic:vacuum " )
anvil.make_unrepairable ( " technic:prospector " )
anvil.make_unrepairable ( " technic:sonic_screwdriver " )
anvil.make_unrepairable ( " technic:chainsaw " )
anvil.make_unrepairable ( " technic:laser_mk1 " )
anvil.make_unrepairable ( " technic:laser_mk2 " )
anvil.make_unrepairable ( " technic:laser_mk3 " )
anvil.make_unrepairable ( " technic:mining_drill " )
anvil.make_unrepairable ( " technic:mining_drill_mk2 " )
anvil.make_unrepairable ( " technic:mining_drill_mk2_1 " )
anvil.make_unrepairable ( " technic:mining_drill_mk2_2 " )
anvil.make_unrepairable ( " technic:mining_drill_mk2_3 " )
anvil.make_unrepairable ( " technic:mining_drill_mk2_4 " )
anvil.make_unrepairable ( " technic:mining_drill_mk3 " )
anvil.make_unrepairable ( " technic:mining_drill_mk3_1 " )
anvil.make_unrepairable ( " technic:mining_drill_mk3_2 " )
anvil.make_unrepairable ( " technic:mining_drill_mk3_3 " )
anvil.make_unrepairable ( " technic:mining_drill_mk3_4 " )
anvil.make_unrepairable ( " technic:mining_drill_mk3_5 " )
end
2019-04-14 21:21:31 -06:00
2020-02-17 22:58:59 -07:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2017-02-27 23:34:35 -07:00
-- the hammer for the anvil
2019-04-14 21:21:31 -06:00
local hammer_def = {
2017-03-07 22:39:25 -07:00
description = S ( " Steel blacksmithing hammer " ) ,
_doc_items_longdesc = S ( " A tool for repairing other tools at a blacksmith's anvil. " ) ,
_doc_items_usagehelp = S ( " Use this hammer to strike blows upon an anvil bearing a damaged tool and you can repair it. It can also be used for smashing stone, but it is not well suited to this task. " ) ,
2022-02-07 08:55:30 -08:00
image = " anvil_tool_steelhammer.png " ,
2017-03-07 22:39:25 -07:00
inventory_image = " anvil_tool_steelhammer.png " ,
2019-01-19 14:50:39 +01:00
2017-03-07 22:39:25 -07:00
tool_capabilities = {
full_punch_interval = 0.8 ,
2022-02-07 08:55:30 -08:00
max_drop_level = 1 ,
groupcaps = {
-- about equal to a stone pick (it's not intended as a tool)
cracky = { times = { [ 2 ] = 2.00 , [ 3 ] = 1.20 } , uses = 30 , maxlevel = 1 } ,
2017-03-07 22:39:25 -07:00
} ,
2022-02-07 08:55:30 -08:00
damage_groups = { fleshy = 6 } ,
2017-03-07 22:39:25 -07:00
}
2019-04-14 21:21:31 -06:00
}
if not hammer_repairable then
hammer_def.groups = { [ " not_repaired_by_anvil " ] = 1 }
end
minetest.register_tool ( " anvil:hammer " , hammer_def )
2017-02-27 23:34:35 -07:00
2017-03-07 22:39:25 -07:00
local tmp = { }
2022-02-07 08:55:30 -08:00
minetest.register_entity ( " anvil:item " , {
2017-03-07 22:39:25 -07:00
hp_max = 1 ,
2022-02-07 08:55:30 -08:00
visual = " wielditem " ,
visual_size = { x = .33 , y = .33 } ,
collisionbox = { 0 , 0 , 0 , 0 , 0 , 0 } ,
physical = false ,
textures = { " air " } ,
2017-03-07 22:39:25 -07:00
on_activate = function ( self , staticdata )
if tmp.nodename ~= nil and tmp.texture ~= nil then
self.nodename = tmp.nodename
tmp.nodename = nil
self.texture = tmp.texture
tmp.texture = nil
else
if staticdata ~= nil and staticdata ~= " " then
2022-02-07 08:55:30 -08:00
local data = staticdata : split ( " ; " )
2017-03-07 22:39:25 -07:00
if data and data [ 1 ] and data [ 2 ] then
self.nodename = data [ 1 ]
self.texture = data [ 2 ]
end
end
end
if self.texture ~= nil then
2022-02-07 08:55:30 -08:00
self.object : set_properties ( { textures = { self.texture } } )
2017-03-07 22:39:25 -07:00
end
end ,
get_staticdata = function ( self )
if self.nodename ~= nil and self.texture ~= nil then
2022-02-07 08:55:30 -08:00
return self.nodename .. " ; " .. self.texture
2017-03-07 22:39:25 -07:00
end
return " "
end ,
} )
2017-02-27 23:34:35 -07:00
2017-03-07 22:39:25 -07:00
local remove_item = function ( pos , node )
2017-05-30 09:25:14 +02:00
local objs = minetest.get_objects_inside_radius ( { x = pos.x , y = pos.y + anvil.setting . item_displacement , z = pos.z } , .5 )
2017-03-07 22:39:25 -07:00
if objs then
for _ , obj in ipairs ( objs ) do
if obj and obj : get_luaentity ( ) and obj : get_luaentity ( ) . name == " anvil:item " then
obj : remove ( )
end
end
end
end
2017-02-27 23:34:35 -07:00
2017-03-07 22:39:25 -07:00
local update_item = function ( pos , node )
2017-04-21 16:58:03 -06:00
local meta = minetest.get_meta ( pos )
2017-03-07 22:39:25 -07:00
local inv = meta : get_inventory ( )
if not inv : is_empty ( " input " ) then
2017-05-30 09:25:14 +02:00
pos.y = pos.y + anvil.setting . item_displacement
2017-03-07 22:39:25 -07:00
tmp.nodename = node.name
tmp.texture = inv : get_stack ( " input " , 1 ) : get_name ( )
2022-02-07 08:55:30 -08:00
local e = minetest.add_entity ( pos , " anvil:item " )
local yaw = math.pi * 2 - node.param2 * math.pi / 2
2019-04-14 20:52:57 -06:00
if e.set_rotation == nil then
-- This is for 0.4.16 support, remove it eventually
e : set_yaw ( yaw )
2022-02-07 08:55:30 -08:00
pos.y = pos.y + 5 / 16
2019-04-14 20:52:57 -06:00
e : set_pos ( pos )
else
2022-02-07 08:55:30 -08:00
e : set_rotation ( { x = - 1.5708 , y = yaw , z = 0 } ) -- x is pitch, 1.5708 is 90 degrees.
2019-04-14 20:52:57 -06:00
end
2017-03-07 22:39:25 -07:00
end
end
2017-02-27 23:34:35 -07:00
2017-03-09 20:27:01 -07:00
local metal_sounds
-- Apparently node_sound_metal_defaults is a newer thing, I ran into games using an older version of the default mod without it.
if default.node_sound_metal_defaults ~= nil then
metal_sounds = default.node_sound_metal_defaults ( )
else
metal_sounds = default.node_sound_stone_defaults ( )
end
2022-02-09 14:44:13 -08:00
local hud_info_by_puncher_name = { }
2022-02-07 10:10:59 -08:00
minetest.register_globalstep ( function ( )
2022-02-09 14:44:13 -08:00
local now = os.time ( )
2022-02-07 10:10:59 -08:00
2022-02-09 14:44:13 -08:00
for puncher_name , hud_info in pairs ( hud_info_by_puncher_name ) do
local hud2 , hud3 , hud_expire_time = unpack ( hud_info )
if now > hud_expire_time then
2022-02-07 10:10:59 -08:00
local puncher = minetest.get_player_by_name ( puncher_name )
2022-02-09 14:44:13 -08:00
if puncher then
local hud2_def = puncher : hud_get ( hud2 )
if hud2_def and hud2_def.name == " anvil_background " then
2022-02-07 10:10:59 -08:00
puncher : hud_remove ( hud2 )
end
2022-02-09 14:44:13 -08:00
local hud3_def = puncher : hud_get ( hud3 )
if hud3_def and hud3_def.name == " anvil_foreground " then
2022-02-07 10:10:59 -08:00
puncher : hud_remove ( hud3 )
end
end
2022-02-09 14:44:13 -08:00
hud_info_by_puncher_name [ puncher_name ] = nil
2022-02-07 10:10:59 -08:00
end
end
end )
2017-02-27 23:34:35 -07:00
minetest.register_node ( " anvil:anvil " , {
drawtype = " nodebox " ,
2017-03-07 22:39:25 -07:00
description = S ( " Anvil " ) ,
_doc_items_longdesc = S ( " A tool for repairing other tools in conjunction with a blacksmith's hammer. " ) ,
_doc_items_usagehelp = S ( " Right-click on this anvil with a damaged tool to place the damaged tool upon it. You can then repair the damaged tool by striking it with a blacksmith's hammer. Repeated blows may be necessary to fully repair a badly worn tool. To retrieve the tool either punch or right-click the anvil with an empty hand. " ) ,
2017-02-27 23:34:35 -07:00
tiles = { " default_stone.png " } ,
2022-02-07 08:55:30 -08:00
paramtype = " light " ,
2017-03-07 22:39:25 -07:00
paramtype2 = " facedir " ,
2022-02-07 08:55:30 -08:00
groups = { cracky = 2 } ,
2017-03-09 20:27:01 -07:00
sounds = metal_sounds ,
2017-02-27 23:34:35 -07:00
-- the nodebox model comes from realtest
node_box = {
type = " fixed " ,
fixed = {
2022-02-07 08:55:30 -08:00
{ - 0.5 , - 0.5 , - 0.3 , 0.5 , - 0.4 , 0.3 } ,
{ - 0.35 , - 0.4 , - 0.25 , 0.35 , - 0.3 , 0.25 } ,
{ - 0.3 , - 0.3 , - 0.15 , 0.3 , - 0.1 , 0.15 } ,
{ - 0.35 , - 0.1 , - 0.2 , 0.35 , 0.1 , 0.2 } ,
2017-03-07 22:39:25 -07:00
} ,
2017-02-27 23:34:35 -07:00
} ,
selection_box = {
type = " fixed " ,
fixed = {
2022-02-07 08:55:30 -08:00
{ - 0.5 , - 0.5 , - 0.3 , 0.5 , - 0.4 , 0.3 } ,
{ - 0.35 , - 0.4 , - 0.25 , 0.35 , - 0.3 , 0.25 } ,
{ - 0.3 , - 0.3 , - 0.15 , 0.3 , - 0.1 , 0.15 } ,
{ - 0.35 , - 0.1 , - 0.2 , 0.35 , 0.1 , 0.2 } ,
2017-03-07 22:39:25 -07:00
}
2017-02-27 23:34:35 -07:00
} ,
2019-01-19 14:50:39 +01:00
2017-02-27 23:34:35 -07:00
on_construct = function ( pos )
2017-03-07 22:39:25 -07:00
local meta = minetest.get_meta ( pos )
local inv = meta : get_inventory ( )
inv : set_size ( " input " , 1 )
end ,
2019-01-19 14:50:39 +01:00
2020-12-12 01:26:56 +02:00
after_place_node = function ( pos , placer , itemstack )
2017-02-27 23:34:35 -07:00
local meta = minetest.get_meta ( pos )
2020-12-12 01:26:56 +02:00
local stackmeta = itemstack : get_meta ( )
if stackmeta : get_int ( " shared " ) == 1 then
meta : set_int ( " shared " , 1 )
meta : set_string ( " infotext " , S ( " Shared anvil " ) )
else
meta : set_string ( " owner " , placer : get_player_name ( ) or " " )
meta : set_string ( " infotext " , S ( " @1's anvil " , placer : get_player_name ( ) ) )
end
end ,
preserve_metadata = function ( pos , oldnode , oldmeta , drops )
if next ( drops ) and tonumber ( oldmeta.shared ) == 1 then
local meta = drops [ next ( drops ) ] : get_meta ( )
meta : set_int ( " shared " , 1 )
meta : set_string ( " description " , S ( " Shared anvil " ) )
end
return drops
2017-03-07 22:39:25 -07:00
end ,
2019-01-19 14:50:39 +01:00
2022-02-07 08:55:30 -08:00
can_dig = function ( pos , player )
local meta = minetest.get_meta ( pos )
local inv = meta : get_inventory ( )
2019-01-11 13:45:25 +01:00
2017-03-07 22:39:25 -07:00
if not inv : is_empty ( " input " ) then
return false
2017-02-27 23:34:35 -07:00
end
2017-03-07 22:39:25 -07:00
return true
2017-02-27 23:34:35 -07:00
end ,
2019-01-19 14:50:39 +01:00
2017-02-27 23:34:35 -07:00
allow_metadata_inventory_put = function ( pos , listname , index , stack , player )
local meta = minetest.get_meta ( pos )
2022-02-07 08:55:30 -08:00
if listname ~= " input " then
2017-03-09 20:27:01 -07:00
return 0
2017-02-27 23:34:35 -07:00
end
2020-10-13 21:46:31 +02:00
2022-02-07 08:55:30 -08:00
local player_name = player : get_player_name ( )
if stack : get_wear ( ) == 0 then
minetest.chat_send_player ( player_name , S ( " This anvil is for damaged tools only. " ) )
return 0
end
local stack_name = stack : get_name ( )
if minetest.get_item_group ( stack_name , " not_repaired_by_anvil " ) ~= 0 then
local item_def = minetest.registered_items [ stack_name ]
minetest.chat_send_player ( player_name , S ( " @1 cannot be repaired with an anvil. " , item_def.description ) )
return 0
2017-02-27 23:34:35 -07:00
end
2019-01-19 14:50:39 +01:00
2017-03-07 22:39:25 -07:00
if meta : get_inventory ( ) : room_for_item ( " input " , stack ) then
return stack : get_count ( )
end
return 0
2017-02-27 23:34:35 -07:00
end ,
2019-01-19 14:50:39 +01:00
2017-02-27 23:34:35 -07:00
allow_metadata_inventory_take = function ( pos , listname , index , stack , player )
2022-02-07 08:55:30 -08:00
if listname ~= " input " then
2017-03-07 22:39:25 -07:00
return 0
2017-02-27 23:34:35 -07:00
end
return stack : get_count ( )
end ,
2019-01-19 14:50:39 +01:00
2017-03-07 22:39:25 -07:00
on_rightclick = function ( pos , node , clicker , itemstack )
2019-08-18 16:10:47 -04:00
if not clicker or not itemstack then
return
end
2019-01-02 01:40:03 +01:00
local meta = minetest.get_meta ( pos )
local name = clicker : get_player_name ( )
2020-10-13 21:46:31 +02:00
local owner = meta : get_string ( " owner " )
2020-12-12 01:26:56 +02:00
local shared = meta : get_int ( " shared " ) == 1
2019-01-19 14:50:39 +01:00
2022-02-07 08:55:30 -08:00
if name ~= owner and not shared then
return itemstack
end
2019-01-11 13:45:25 +01:00
if itemstack : get_count ( ) == 0 then
2020-10-13 21:46:31 +02:00
local inv = meta : get_inventory ( )
2019-01-11 13:45:25 +01:00
if not inv : is_empty ( " input " ) then
local return_stack = inv : get_stack ( " input " , 1 )
inv : set_stack ( " input " , 1 , nil )
local wield_index = clicker : get_wield_index ( )
clicker : get_inventory ( ) : set_stack ( " main " , wield_index , return_stack )
2020-12-12 01:26:56 +02:00
if shared then
meta : set_string ( " infotext " , S ( " Shared anvil " ) )
else
meta : set_string ( " infotext " , S ( " @1's anvil " , owner ) )
end
2019-01-11 13:45:25 +01:00
remove_item ( pos , node )
return return_stack
2019-01-19 14:50:39 +01:00
end
2017-03-07 22:39:25 -07:00
end
2019-01-11 13:45:25 +01:00
local this_def = minetest.registered_nodes [ node.name ]
if this_def.allow_metadata_inventory_put ( pos , " input " , 1 , itemstack : peek_item ( ) , clicker ) > 0 then
local s = itemstack : take_item ( )
local meta = minetest.get_meta ( pos )
local inv = meta : get_inventory ( )
inv : add_item ( " input " , s )
2020-10-13 21:46:31 +02:00
local meta_description = s : get_meta ( ) : get_string ( " description " )
if " " ~= meta_description then
2020-12-12 01:26:56 +02:00
if shared then
meta : set_string ( " infotext " , S ( " Shared anvil " ) )
else
meta : set_string ( " infotext " , S ( " @1's anvil " , owner ) .. " \n " .. meta_description )
end
2020-10-13 21:46:31 +02:00
end
meta : set_int ( " informed " , 0 )
2022-02-07 08:55:30 -08:00
update_item ( pos , node )
2019-01-11 13:45:25 +01:00
end
2019-01-19 14:50:39 +01:00
2017-03-07 22:39:25 -07:00
return itemstack
end ,
2019-01-19 14:50:39 +01:00
2017-02-27 23:34:35 -07:00
on_punch = function ( pos , node , puncher )
2022-02-07 08:55:30 -08:00
if not pos or not node or not puncher then
2017-03-09 20:27:01 -07:00
return
2017-02-27 23:34:35 -07:00
end
2017-03-09 20:27:01 -07:00
local wielded = puncher : get_wielded_item ( )
local meta = minetest.get_meta ( pos )
2022-02-07 08:55:30 -08:00
local inv = meta : get_inventory ( )
2020-10-13 21:46:31 +02:00
local owner = meta : get_string ( " owner " )
2020-12-12 01:26:56 +02:00
local shared = meta : get_int ( " shared " ) == 1
2022-02-07 10:10:59 -08:00
local puncher_name = puncher : get_player_name ( )
if not shared and owner ~= puncher_name then
2019-01-19 14:50:39 +01:00
return
end
2017-03-07 22:39:25 -07:00
if wielded : get_count ( ) == 0 then
if not inv : is_empty ( " input " ) then
local return_stack = inv : get_stack ( " input " , 1 )
inv : set_stack ( " input " , 1 , nil )
2017-04-21 23:10:00 -06:00
local wield_index = puncher : get_wield_index ( )
puncher : get_inventory ( ) : set_stack ( " main " , wield_index , return_stack )
2020-12-12 01:26:56 +02:00
if shared then
meta : set_string ( " infotext " , S ( " Shared anvil " ) )
else
meta : set_string ( " infotext " , S ( " @1's anvil " , owner ) )
end
2017-03-07 22:39:25 -07:00
remove_item ( pos , node )
2019-01-19 14:50:39 +01:00
end
2017-03-07 22:39:25 -07:00
end
2019-01-19 14:50:39 +01:00
2017-03-07 22:39:25 -07:00
-- only punching with the hammer is supposed to work
2022-02-07 08:55:30 -08:00
if wielded : get_name ( ) ~= " anvil:hammer " then
2017-03-09 20:27:01 -07:00
return
2017-03-07 22:39:25 -07:00
end
2022-02-07 08:55:30 -08:00
local input = inv : get_stack ( " input " , 1 )
2019-01-19 14:50:39 +01:00
2017-02-27 23:34:35 -07:00
-- only tools can be repaired
2020-11-21 21:07:26 +01:00
if not input or input : is_empty ( ) then
2017-03-09 20:27:01 -07:00
return
2017-02-27 23:34:35 -07:00
end
2019-01-19 14:50:39 +01:00
2017-02-27 23:34:35 -07:00
-- 65535 is max damage
2022-02-07 08:55:30 -08:00
local damage_state = 40 - math.floor ( input : get_wear ( ) / 1638 )
2019-01-19 14:50:39 +01:00
2017-03-09 20:27:01 -07:00
local tool_name = input : get_name ( )
2017-03-07 22:39:25 -07:00
2022-02-07 08:55:30 -08:00
if input : get_wear ( ) > 0 then
2022-02-09 14:44:13 -08:00
local hud2 , hud3 , hud3_def
if hud_info_by_puncher_name [ puncher_name ] then
2023-05-23 20:33:42 +02:00
hud2 , hud3 = unpack ( hud_info_by_puncher_name [ puncher_name ] )
2022-02-09 14:44:13 -08:00
hud3_def = puncher : hud_get ( hud3 )
end
2022-02-07 10:10:59 -08:00
2022-02-09 14:44:13 -08:00
if hud3_def and hud3_def.name == " anvil_foreground " then
2022-02-07 10:10:59 -08:00
puncher : hud_change ( hud3 , " number " , damage_state )
2022-02-09 14:44:13 -08:00
2022-02-07 10:10:59 -08:00
else
2022-02-09 14:44:13 -08:00
hud2 = puncher : hud_add ( {
name = " anvil_background " ,
2022-02-07 10:10:59 -08:00
hud_elem_type = " statbar " ,
text = " default_cloud.png^[colorize:#ff0000:256 " ,
number = 40 ,
direction = 0 , -- left to right
position = { x = 0.5 , y = 0.65 } ,
alignment = { x = 0 , y = 0 } ,
offset = { x = - 320 , y = 0 } ,
size = { x = 32 , y = 32 } ,
} )
2022-02-09 14:44:13 -08:00
hud3 = puncher : hud_add ( {
name = " anvil_foreground " ,
2022-02-07 10:10:59 -08:00
hud_elem_type = " statbar " ,
text = " default_cloud.png^[colorize:#00ff00:256 " ,
number = damage_state ,
direction = 0 , -- left to right
position = { x = 0.5 , y = 0.65 } ,
alignment = { x = 0 , y = 0 } ,
offset = { x = - 320 , y = 0 } ,
size = { x = 32 , y = 32 } ,
} )
2017-02-27 23:34:35 -07:00
end
2022-02-07 10:10:59 -08:00
2022-02-09 14:44:13 -08:00
hud_info_by_puncher_name [ puncher_name ] = { hud2 , hud3 , os.time ( ) + hud_timeout }
2022-02-07 10:10:59 -08:00
end
2019-01-19 14:50:39 +01:00
2017-02-27 23:34:35 -07:00
-- tell the player when the job is done
2022-02-07 08:55:30 -08:00
if input : get_wear ( ) == 0 then
2020-10-13 21:46:31 +02:00
-- but only once
2022-02-07 08:55:30 -08:00
if 0 < meta : get_int ( " informed " ) then
return
end
2020-10-13 21:46:31 +02:00
meta : set_int ( " informed " , 1 )
2017-03-10 00:55:28 -07:00
local tool_desc
2020-10-13 21:46:31 +02:00
local meta_description = input : get_meta ( ) : get_string ( " description " )
if " " ~= meta_description then
tool_desc = meta_description
elseif minetest.registered_items [ tool_name ] and minetest.registered_items [ tool_name ] . description then
2017-03-10 00:55:28 -07:00
tool_desc = minetest.registered_items [ tool_name ] . description
else
tool_desc = tool_name
end
2022-02-07 10:10:59 -08:00
minetest.chat_send_player ( puncher_name , S ( " Your @1 has been repaired successfully. " , tool_desc ) )
2017-03-09 20:27:01 -07:00
return
else
2017-06-18 14:06:44 -06:00
pos.y = pos.y + anvil.setting . item_displacement
2022-02-07 08:55:30 -08:00
minetest.sound_play ( { name = " anvil_clang " } , { pos = pos } )
2017-03-09 20:27:01 -07:00
minetest.add_particlespawner ( {
2022-02-07 08:55:30 -08:00
amount = 10 ,
time = 0.1 ,
minpos = pos ,
maxpos = pos ,
minvel = { x = 2 , y = 3 , z = 2 } ,
maxvel = { x = - 2 , y = 1 , z = - 2 } ,
minacc = { x = 0 , y = - 10 , z = 0 } ,
maxacc = { x = 0 , y = - 10 , z = 0 } ,
minexptime = 0.5 ,
maxexptime = 1 ,
minsize = 1 ,
maxsize = 1 ,
collisiondetection = true ,
vertical = false ,
texture = " anvil_spark.png " ,
2017-03-09 20:27:01 -07:00
} )
2017-02-27 23:34:35 -07:00
end
2019-01-19 14:50:39 +01:00
2017-02-27 23:34:35 -07:00
-- do the actual repair
2022-02-07 08:55:30 -08:00
input : add_wear ( - 5000 ) -- equals to what technic toolshop does in 5 seconds
2017-02-27 23:34:35 -07:00
inv : set_stack ( " input " , 1 , input )
2019-01-19 14:50:39 +01:00
2017-02-27 23:34:35 -07:00
-- damage the hammer slightly
2022-02-07 08:55:30 -08:00
wielded : add_wear ( 100 )
puncher : set_wielded_item ( wielded )
2017-02-27 23:34:35 -07:00
end ,
is_ground_content = false ,
} )
2017-03-07 22:39:25 -07:00
-- automatically restore entities lost due to /clearobjects or similar
2017-03-09 20:27:01 -07:00
minetest.register_lbm ( {
name = " anvil:anvil_item_restoration " ,
2022-02-07 08:55:30 -08:00
nodenames = { " anvil:anvil " } ,
2017-03-09 20:27:01 -07:00
run_at_every_load = true ,
2017-03-07 22:39:25 -07:00
action = function ( pos , node , active_object_count , active_object_count_wider )
2022-02-07 08:55:30 -08:00
local test_pos = { x = pos.x , y = pos.y + anvil.setting . item_displacement , z = pos.z }
if # minetest.get_objects_inside_radius ( test_pos , 0.5 ) > 0 then
return
end
2017-03-07 22:39:25 -07:00
update_item ( pos , node )
end
} )
2017-02-27 23:34:35 -07:00
2017-03-07 22:39:25 -07:00
-- Transfer the hammer from the old hammer storage slot to the main slot, or else drop it in world
minetest.register_lbm ( {
name = " anvil:hammer_ejection " ,
nodenames = " anvil:anvil " ,
2017-03-09 20:27:01 -07:00
run_at_every_load = false ,
2017-03-07 22:39:25 -07:00
action = function ( pos , node )
2017-03-09 20:27:01 -07:00
local meta = minetest.get_meta ( pos )
2022-02-07 08:55:30 -08:00
local inv = meta : get_inventory ( )
2017-03-07 22:39:25 -07:00
if not inv : is_empty ( " hammer " ) then
local hammer = inv : get_stack ( " hammer " , 1 )
inv : set_stack ( " hammer " , 1 , nil )
inv : set_size ( " hammer " , 0 )
if inv : is_empty ( " input " ) then
inv : set_stack ( " input " , 1 , hammer ) -- the abm will ensure there's an entity showing the hammer is here
else
2022-02-07 08:55:30 -08:00
minetest.add_item ( { x = pos.x , y = pos.y + 1 , z = pos.z } , hammer )
2017-03-07 22:39:25 -07:00
end
end
end
} )
2017-02-27 23:34:35 -07:00
---------------------------------------------------------------------------------------
-- crafting receipes
---------------------------------------------------------------------------------------
2020-12-12 01:26:56 +02:00
minetest.register_craft ( {
output = " anvil:anvil " ,
type = " shapeless " ,
2022-02-07 08:55:30 -08:00
recipe = { " anvil:anvil " }
2020-12-12 01:26:56 +02:00
} )
local shared_anvil_craft_stack = ItemStack ( " anvil:anvil " )
shared_anvil_craft_stack : get_meta ( ) : set_int ( " shared " , 1 )
shared_anvil_craft_stack : get_meta ( ) : set_string ( " description " , S ( " Shared anvil " ) )
minetest.register_craft ( {
output = shared_anvil_craft_stack : to_string ( ) ,
type = " shapeless " ,
2022-02-07 08:55:30 -08:00
recipe = { " anvil:anvil " , " default:paper " }
2020-12-12 01:26:56 +02:00
} )
2017-02-27 23:34:35 -07:00
minetest.register_craft ( {
output = " anvil:anvil " ,
recipe = {
2022-02-07 08:55:30 -08:00
{ " default:steel_ingot " , " default:steel_ingot " , " default:steel_ingot " } ,
{ " " , " default:steel_ingot " , " " } ,
{ " default:steel_ingot " , " default:steel_ingot " , " default:steel_ingot " }
2019-01-19 14:50:39 +01:00
}
2017-02-27 23:34:35 -07:00
} )
minetest.register_craft ( {
output = " anvil:hammer " ,
recipe = {
2022-02-07 08:55:30 -08:00
{ " default:steel_ingot " , " default:steel_ingot " , " default:steel_ingot " } ,
{ " default:steel_ingot " , " default:steel_ingot " , " default:steel_ingot " } ,
{ " group:stick " , " " , " " }
2019-01-19 14:50:39 +01:00
}
2017-02-27 23:34:35 -07:00
} )