2019-08-23 05:16:08 +02:00
-- internationalization boilerplate
local MP = minetest.get_modpath ( minetest.get_current_modname ( ) )
local S , NS = dofile ( MP .. " /intllib.lua " )
2019-08-26 04:09:09 +02:00
-- TODO: make global
2019-08-25 06:52:02 +02:00
local player_interacting_with_digtron_pos = { }
local get_formspec = function ( pos , player_name )
local meta = minetest.get_meta ( pos )
local period = meta : get_int ( " period " )
if period < 1 then period = 1 end
local offset = meta : get_int ( " offset " )
return
" size[5,3] " ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
" field[0.5,0.8;1,0.1;period; " .. S ( " Periodicity " ) .. " ; " .. period .. " ] " ..
" field_close_on_enter[period;false] " ..
" tooltip[period; " .. S ( " Digger will dig once every n steps. \n These steps are globally aligned, all diggers with \n the same period and offset will dig on the same location. " ) .. " ] " ..
" field[1.5,0.8;1,0.1;offset; " .. S ( " Offset " ) .. " ; " .. offset .. " ] " ..
" field_close_on_enter[offset;false] " ..
" tooltip[offset; " .. S ( " Offsets the start of periodicity counting by this amount. \n For example, a digger with period 2 and offset 0 digs \n every even-numbered block and one with period 2 and \n offset 1 digs every odd-numbered block. " ) .. " ] " ..
" button[2.2,0.5;1,0.1;set; " .. S ( " Save & \n Show " ) .. " ] " ..
" tooltip[set; " .. S ( " Saves settings " ) .. " ] "
end
local update_infotext = function ( meta )
local period = meta : get_int ( " period " )
if period < 1 then period = 1 end
local offset = meta : get_int ( " offset " )
2019-08-27 03:36:27 +02:00
meta : set_string ( " infotext " , S ( " Digger \n period @1, offset @2 " , period , offset ) )
2019-08-25 06:52:02 +02:00
end
2019-09-01 20:49:15 +02:00
local single_drill_nodebox = {
type = " fixed " ,
fixed = {
{ - 0.25 , - 0.25 , 0.5 , 0.25 , 0.25 , 0.8125 } , -- Drill
{ - 0.5 , - 0.5 , 0 , 0.5 , 0.5 , 0.5 } , -- Block
{ - 0.25 , - 0.25 , - 0.5 , 0.25 , 0.25 , 0 } , -- Drive
} ,
}
local dual_drill_nodebox = {
type = " fixed " ,
fixed = {
{ - 0.25 , - 0.25 , 0.5 , 0.25 , 0.25 , 0.8125 } , -- Drill
{ - 0.25 , - 0.5 , - 0.25 , 0.25 , - 0.8125 , 0.25 } , -- Drill Down
{ - 0.5 , - 0.5 , 0 , 0.5 , 0.5 , 0.5 } , -- Block
{ - 0.5 , - 0.5 , - 0.5 , 0.5 , 0 , 0 } , -- Block Down
{ - 0.25 , 0 , - 0.5 , 0.25 , 0.25 , 0 } , -- Drive
{ - 0.25 , 0.25 , - 0.25 , 0.25 , 0.5 , 0 } , -- Drive Up
} ,
}
2019-08-23 05:16:08 +02:00
minetest.register_node ( " digtron:digger " , {
description = S ( " Digtron Digger " ) ,
_doc_items_longdesc = nil ,
_doc_items_usagehelp = nil ,
_digtron_disassembled_node = " digtron:digger_static " ,
drops = " digtron:digger_static " ,
drawtype = " mesh " ,
mesh = " digtron_digger.obj " ,
tiles = {
{ name = " digtron_plate.png^digtron_digger_yb_frame.png " , backface_culling = true } ,
{ name = " digtron_plate.png " , backface_culling = true } ,
{ name = " digtron_drill_head_animated.png " , backface_culling = true , animation =
{
type = " vertical_frames " ,
aspect_w = 48 ,
aspect_h = 12 ,
length = 1.0 ,
}
2019-08-21 09:21:03 +02:00
} ,
2019-08-23 05:16:08 +02:00
{ name = " digtron_plate.png^digtron_motor.png " , backface_culling = true } ,
} ,
2019-09-01 20:49:15 +02:00
collision_box = single_drill_nodebox ,
selection_box = single_drill_nodebox ,
2019-08-23 05:16:08 +02:00
paramtype2 = " facedir " ,
paramtype = " light " ,
2019-09-01 22:25:46 +02:00
groups = { cracky = 3 , oddly_breakable_by_hand = 3 , digtron = 3 , not_in_creative_inventory = 1 } ,
2019-08-23 05:16:08 +02:00
is_ground_content = false ,
sounds = default.node_sound_metal_defaults ( ) ,
can_dig = digtron.can_dig ,
on_blast = digtron.on_blast ,
} )
2019-08-22 09:13:59 +02:00
2019-08-23 05:16:08 +02:00
minetest.register_node ( " digtron:digger_static " , {
description = S ( " Digtron Digger " ) ,
_doc_items_longdesc = nil ,
_doc_items_usagehelp = nil ,
_digtron_assembled_node = " digtron:digger " ,
drawtype = " mesh " ,
mesh = " digtron_digger_static.obj " ,
tiles = {
{ name = " digtron_plate.png^digtron_digger_yb_frame.png " , backface_culling = true } ,
{ name = " digtron_plate.png " , backface_culling = true } ,
{ name = " digtron_drill_head_animated.png " , backface_culling = true } ,
{ name = " digtron_plate.png^digtron_motor.png " , backface_culling = true } ,
} ,
2019-09-01 20:49:15 +02:00
collision_box = single_drill_nodebox ,
selection_box = single_drill_nodebox ,
paramtype2 = " facedir " ,
paramtype = " light " ,
groups = { cracky = 3 , oddly_breakable_by_hand = 3 , digtron = 3 } ,
is_ground_content = false ,
sounds = default.node_sound_metal_defaults ( ) ,
can_dig = digtron.can_dig ,
on_blast = digtron.on_blast ,
on_rightclick = function ( pos , node , clicker , itemstack , pointed_thing )
local returnstack , success = digtron.on_rightclick ( pos , node , clicker , itemstack , pointed_thing )
if returnstack then
return returnstack , success
end
if clicker == nil then return end
local player_name = clicker : get_player_name ( )
player_interacting_with_digtron_pos [ player_name ] = pos
minetest.show_formspec ( player_name , " digtron:digger " , get_formspec ( pos , player_name ) )
end ,
} )
minetest.register_node ( " digtron:dual_digger " , {
description = S ( " Digtron Dual Digger " ) ,
_doc_items_longdesc = nil ,
_doc_items_usagehelp = nil ,
2019-09-01 22:25:46 +02:00
_digtron_disassembled_node = " digtron:dual_digger_static " ,
2019-09-01 20:49:15 +02:00
drops = " digtron:dual_digger_static " ,
drawtype = " mesh " ,
mesh = " digtron_dual_digger.obj " ,
tiles = {
{ name = " digtron_plate.png^digtron_digger_yb_frame.png " , backface_culling = true } ,
{ name = " digtron_plate.png^digtron_motor.png " , backface_culling = true } ,
{ name = " digtron_drill_head_animated.png " , backface_culling = true , animation =
{
type = " vertical_frames " ,
aspect_w = 48 ,
aspect_h = 12 ,
length = 1.0 ,
}
2019-08-22 09:13:59 +02:00
} ,
2019-09-01 20:49:15 +02:00
{ name = " digtron_plate.png " , backface_culling = true } ,
2019-08-23 05:16:08 +02:00
} ,
2019-09-01 20:49:15 +02:00
collision_box = dual_drill_nodebox ,
selection_box = dual_drill_nodebox ,
paramtype2 = " facedir " ,
paramtype = " light " ,
2019-09-01 22:25:46 +02:00
groups = { cracky = 3 , oddly_breakable_by_hand = 3 , digtron = 10 , not_in_creative_inventory = 1 } ,
2019-09-01 20:49:15 +02:00
is_ground_content = false ,
sounds = default.node_sound_metal_defaults ( ) ,
can_dig = digtron.can_dig ,
on_blast = digtron.on_blast ,
} )
minetest.register_node ( " digtron:dual_digger_static " , {
description = S ( " Digtron Dual Digger " ) ,
_doc_items_longdesc = nil ,
_doc_items_usagehelp = nil ,
_digtron_assembled_node = " digtron:dual_digger " ,
drawtype = " mesh " ,
mesh = " digtron_dual_digger_static.obj " ,
tiles = {
{ name = " digtron_plate.png^digtron_digger_yb_frame.png " , backface_culling = true } ,
{ name = " digtron_plate.png^digtron_motor.png " , backface_culling = true } ,
{ name = " digtron_drill_head_animated.png " , backface_culling = true } ,
{ name = " digtron_plate.png " , backface_culling = true } ,
2019-08-23 05:16:08 +02:00
} ,
2019-09-01 20:49:15 +02:00
collision_box = dual_drill_nodebox ,
selection_box = dual_drill_nodebox ,
2019-08-23 05:16:08 +02:00
paramtype2 = " facedir " ,
paramtype = " light " ,
2019-09-01 22:25:46 +02:00
groups = { cracky = 3 , oddly_breakable_by_hand = 3 , digtron = 10 } ,
2019-08-23 05:16:08 +02:00
is_ground_content = false ,
sounds = default.node_sound_metal_defaults ( ) ,
can_dig = digtron.can_dig ,
on_blast = digtron.on_blast ,
2019-08-25 06:52:02 +02:00
on_rightclick = function ( pos , node , clicker , itemstack , pointed_thing )
2019-08-27 03:36:27 +02:00
local returnstack , success = digtron.on_rightclick ( pos , node , clicker , itemstack , pointed_thing )
if returnstack then
return returnstack , success
end
2019-08-25 06:52:02 +02:00
if clicker == nil then return end
local player_name = clicker : get_player_name ( )
player_interacting_with_digtron_pos [ player_name ] = pos
minetest.show_formspec ( player_name , " digtron:digger " , get_formspec ( pos , player_name ) )
end ,
2019-08-23 05:16:08 +02:00
} )
2019-08-25 06:52:02 +02:00
minetest.register_on_player_receive_fields ( function ( player , formname , fields )
if formname ~= " digtron:digger " then
return
end
local player_name = player : get_player_name ( )
local pos = player_interacting_with_digtron_pos [ player_name ]
if pos == nil then return end
local meta = minetest.get_meta ( pos )
--TODO: this isn't recording the field when using ESC to exit the formspec
if fields.key_enter_field == " offset " or fields.offset then
local val = tonumber ( fields.offset )
if val ~= nil and val >= 0 then
meta : set_int ( " offset " , val )
end
end
if fields.key_enter_field == " period " or fields.period then
local val = tonumber ( fields.period )
if val ~= nil and val >= 1 then
meta : set_int ( " period " , val )
end
end
update_infotext ( meta )
end )