2021-05-29 14:12:33 +00:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2019-03-07 23:22:28 +00:00
2020-02-18 18:30:33 +00:00
local mod_doc = minetest.get_modpath ( " doc " )
2020-02-18 19:04:15 +00:00
local mod_screwdriver = minetest.get_modpath ( " screwdriver " )
2020-02-18 18:30:33 +00:00
2020-02-18 21:17:52 +00:00
local equip_armor
if minetest.get_modpath ( " mcl_armor " ) then
2021-04-14 13:46:52 +00:00
equip_armor = mcl_armor.equip_on_use
2020-02-18 21:17:52 +00:00
end
2017-01-31 09:05:32 +00:00
-- Heads system
2015-06-29 17:55:56 +00:00
2020-02-18 17:12:51 +00:00
local function addhead ( name , texture , desc , longdesc , rangemob , rangefactor )
2020-02-18 19:04:15 +00:00
local on_rotate_floor , on_rotate_wall
if mod_screwdriver then
on_rotate_floor = function ( pos , node , user , mode , new_param2 )
if mode == screwdriver.ROTATE_AXIS then
node.name = node.name .. " _wall "
node.param2 = minetest.dir_to_wallmounted ( minetest.facedir_to_dir ( node.param2 ) )
minetest.set_node ( pos , node )
return true
end
end
on_rotate_wall = function ( pos , node , user , mode , new_param2 )
if mode == screwdriver.ROTATE_AXIS then
node.name = string.sub ( node.name , 1 , string.len ( node.name ) - 5 )
node.param2 = minetest.dir_to_facedir ( minetest.wallmounted_to_dir ( node.param2 ) )
minetest.set_node ( pos , node )
return true
end
end
2017-12-05 13:09:39 +00:00
end
2017-07-05 23:13:57 +00:00
minetest.register_node ( " mcl_heads: " .. name , {
2017-01-31 09:05:32 +00:00
description = desc ,
2017-03-11 17:56:01 +00:00
_doc_items_longdesc = longdesc ,
2020-02-18 18:30:33 +00:00
drawtype = " nodebox " ,
2017-01-10 04:35:44 +00:00
is_ground_content = false ,
node_box = {
type = " fixed " ,
2020-02-18 17:13:45 +00:00
fixed = {
{ - 0.25 , - 0.5 , - 0.25 , 0.25 , 0.0 , 0.25 , } ,
2015-06-29 17:55:56 +00:00
} ,
2017-01-10 04:35:44 +00:00
} ,
2021-04-17 12:07:47 +00:00
groups = { handy = 1 , armor = 1 , armor_head = 1 , non_combat_armor = 1 , non_combat_armor_head = 1 , head = 1 , deco_block = 1 , dig_by_piston = 1 } ,
2017-07-05 23:13:57 +00:00
-- The head textures are based off the textures of an actual mob.
2017-01-10 04:35:44 +00:00
tiles = {
2017-07-05 23:13:57 +00:00
-- Note: bottom texture is overlaid over top texture to get rid of possible transparency.
-- This is required for skeleton skull and wither skeleton skull.
" [combine:16x16:-4,4= " .. texture , -- top
" ([combine:16x16:-4,4= " .. texture .. " )^([combine:16x16:-12,4= " .. texture .. " ) " , -- bottom
" [combine:16x16:-12,0= " .. texture , -- left
" [combine:16x16:4,0= " .. texture , -- right
" [combine:16x16:-20,0= " .. texture , -- back
" [combine:16x16:-4,0= " .. texture , -- front
2020-02-18 17:13:45 +00:00
} ,
2021-02-18 13:00:17 +00:00
use_texture_alpha = minetest.features . use_texture_alpha_string_modes and " opaque " or false ,
2017-01-10 04:35:44 +00:00
paramtype = " light " ,
2017-02-01 22:18:09 +00:00
stack_max = 64 ,
2017-01-10 04:35:44 +00:00
paramtype2 = " facedir " ,
sunlight_propagates = true ,
walkable = true ,
selection_box = {
type = " fixed " ,
fixed = { - 0.25 , - 0.5 , - 0.25 , 0.25 , 0.0 , 0.25 , } ,
} ,
2017-02-11 17:46:23 +00:00
sounds = mcl_sounds.node_sound_defaults ( {
2017-01-10 04:35:44 +00:00
footstep = { name = " default_hard_footstep " , gain = 0.3 }
} ) ,
2020-02-18 18:51:10 +00:00
on_place = function ( itemstack , placer , pointed_thing )
if pointed_thing.type ~= " node " then
-- no interaction possible with entities, for now.
return itemstack
end
local under = pointed_thing.under
local node = minetest.get_node ( under )
local def = minetest.registered_nodes [ node.name ]
if not def then return itemstack end
-- Call on_rightclick if the pointed node defines it
if placer and not placer : get_player_control ( ) . sneak then
if minetest.registered_nodes [ node.name ] and minetest.registered_nodes [ node.name ] . on_rightclick then
return minetest.registered_nodes [ node.name ] . on_rightclick ( under , node , placer , itemstack ) or itemstack
end
end
local above = pointed_thing.above
local diff = { x = under.x - above.x , y = under.y - above.y , z = under.z - above.z }
local wdir = minetest.dir_to_wallmounted ( diff )
local itemstring = itemstack : get_name ( )
2021-04-17 11:53:41 +00:00
local fakestack = ItemStack ( itemstack )
2021-05-22 21:25:28 +00:00
--local idef = fakestack:get_definition()
2020-02-18 18:51:10 +00:00
local retval
if wdir == 0 or wdir == 1 then
return minetest.item_place ( itemstack , placer , pointed_thing )
else
retval = fakestack : set_name ( " mcl_heads: " .. name .. " _wall " )
end
if not retval then
return itemstack
end
2021-05-22 21:25:28 +00:00
itemstack = minetest.item_place ( fakestack , placer , pointed_thing , wdir )
2020-02-18 18:51:10 +00:00
itemstack : set_name ( itemstring )
return itemstack
end ,
2020-02-18 21:17:52 +00:00
on_secondary_use = equip_armor ,
2020-02-18 19:04:15 +00:00
on_rotate = on_rotate_floor ,
2020-02-18 18:51:10 +00:00
2020-02-19 02:02:45 +00:00
_mcl_armor_mob_range_mob = rangemob ,
_mcl_armor_mob_range_factor = rangefactor ,
2021-04-17 12:07:47 +00:00
_mcl_armor_element = " head " ,
2021-05-04 07:01:53 +00:00
_mcl_armor_texture = " mcl_heads_ " .. name .. " .png " ,
_mcl_armor_preview = " mcl_heads_ " .. name .. " _preview.png " ,
2020-04-17 19:40:13 +00:00
_mcl_blast_resistance = 1 ,
2017-02-27 00:33:34 +00:00
_mcl_hardness = 1 ,
2015-06-29 17:55:56 +00:00
} )
2020-02-18 18:30:33 +00:00
minetest.register_node ( " mcl_heads: " .. name .. " _wall " , {
_doc_items_create_entry = false ,
drawtype = " nodebox " ,
is_ground_content = false ,
node_box = {
type = " wallmounted " ,
wall_bottom = { - 0.25 , - 0.5 , - 0.25 , 0.25 , 0.0 , 0.25 , } ,
wall_top = { - 0.25 , 0.0 , - 0.25 , 0.25 , 0.5 , 0.25 , } ,
wall_side = { - 0.5 , - 0.25 , - 0.25 , 0.0 , 0.25 , 0.25 , } ,
} ,
groups = { handy = 1 , head = 1 , deco_block = 1 , dig_by_piston = 1 , not_in_creative_inventory = 1 } ,
-- The head textures are based off the textures of an actual mob.
tiles = {
{ name = " [combine:16x16:-4,-4= " .. texture , align_style = " world " } , -- front
{ name = " [combine:16x16:-20,-4= " .. texture , align_style = " world " } , -- back
{ name = " [combine:16x16:-8,-4= " .. texture , align_style = " world " } , -- left
{ name = " [combine:16x16:0,-4= " .. texture , align_style = " world " } , -- right
{ name = " ([combine:16x16:-4,0= " .. texture .. " )^[transformR180 " , align_style = " node " } , -- top
{ name = " ([combine:16x16:-4,8= " .. texture .. " )^([combine:16x16:-12,8= " .. texture .. " ) " , align_style = " node " } , -- bottom
} ,
2021-02-18 13:00:17 +00:00
use_texture_alpha = minetest.features . use_texture_alpha_string_modes and " opaque " or false ,
2020-02-18 18:30:33 +00:00
paramtype = " light " ,
stack_max = 64 ,
paramtype2 = " wallmounted " ,
sunlight_propagates = true ,
walkable = true ,
sounds = mcl_sounds.node_sound_defaults ( {
footstep = { name = " default_hard_footstep " , gain = 0.3 }
} ) ,
drop = " mcl_heads: " .. name ,
2020-02-18 19:04:15 +00:00
on_rotate = on_rotate_wall ,
2020-04-17 19:40:13 +00:00
_mcl_blast_resistance = 1 ,
2020-02-18 18:30:33 +00:00
_mcl_hardness = 1 ,
} )
if mod_doc then
doc.add_entry_alias ( " nodes " , " mcl_heads: " .. name , " nodes " , " mcl_heads: " .. name .. " _wall " )
end
2015-06-29 17:55:56 +00:00
end
2017-01-31 09:05:32 +00:00
-- Add heads
2021-09-01 21:27:47 +00:00
addhead ( " zombie " , " mcl_heads_zombie_node.png " , S ( " Zombie Head " ) , S ( " A zombie head is a small decorative block which resembles the head of a zombie. It can also be worn as a helmet, which reduces the detection range of zombies by 50%. " ) , " mcl_mobs:zombie " , 0.5 )
addhead ( " creeper " , " mcl_heads_creeper_node.png " , S ( " Creeper Head " ) , S ( " A creeper head is a small decorative block which resembles the head of a creeper. It can also be worn as a helmet, which reduces the detection range of creepers by 50%. " ) , " mcl_mobs:creeper " , 0.5 )
2017-03-11 17:51:39 +00:00
-- Original Minecraft name: “Head”
2019-03-07 23:22:28 +00:00
addhead ( " steve " , " mcl_heads_steve_node.png " , S ( " Human Head " ) , S ( " A human head is a small decorative block which resembles the head of a human (i.e. a player character). It can also be worn as a helmet for fun, but does not offer any protection. " ) )
2021-09-01 21:27:47 +00:00
addhead ( " skeleton " , " mcl_heads_skeleton_node.png " , S ( " Skeleton Skull " ) , S ( " A skeleton skull is a small decorative block which resembles the skull of a skeleton. It can also be worn as a helmet, which reduces the detection range of skeletons by 50%. " ) , " mcl_mobs:skeleton " , 0.5 )
2019-03-15 05:12:03 +00:00
addhead ( " wither_skeleton " , " mcl_heads_wither_skeleton_node.png " , S ( " Wither Skeleton Skull " ) , S ( " A wither skeleton skull is a small decorative block which resembles the skull of a wither skeleton. It can also be worn as a helmet for fun, but does not offer any protection. " ) )