From 2f25bc5277427dcbb48d4c01dca37d9c2e1669d5 Mon Sep 17 00:00:00 2001 From: William Goodspeed Date: Wed, 21 Aug 2024 22:03:39 +0000 Subject: [PATCH] Refactor head's `param2' to degrotate --- mods/ITEMS/mcl_heads/init.lua | 129 ++++++++---------- .../mcl_heads/models/mcl_heads_floor.obj | 41 ++++++ .../mcl_heads/models/mcl_heads_floor22_5.obj | 42 ------ .../mcl_heads/models/mcl_heads_floor45.obj | 42 ------ .../mcl_heads/models/mcl_heads_floor67_5.obj | 42 ------ 5 files changed, 96 insertions(+), 200 deletions(-) create mode 100644 mods/ITEMS/mcl_heads/models/mcl_heads_floor.obj delete mode 100644 mods/ITEMS/mcl_heads/models/mcl_heads_floor22_5.obj delete mode 100644 mods/ITEMS/mcl_heads/models/mcl_heads_floor45.obj delete mode 100644 mods/ITEMS/mcl_heads/models/mcl_heads_floor67_5.obj diff --git a/mods/ITEMS/mcl_heads/init.lua b/mods/ITEMS/mcl_heads/init.lua index 1407bac6c..ad690b60d 100644 --- a/mods/ITEMS/mcl_heads/init.lua +++ b/mods/ITEMS/mcl_heads/init.lua @@ -21,8 +21,13 @@ mcl_heads.FLOOR_BOX = { -0.25, -0.5, -0.25, 0.25, 0.0, 0.25, } --- node definition template for floor mod heads mcl_heads.deftemplate_floor = { - drawtype = "nodebox", - node_box = { + drawtype = "mesh", + mesh = "mcl_heads_floor.obj", + selection_box = { + type = "fixed", + fixed = mcl_heads.FLOOR_BOX, + }, + collision_box = { type = "fixed", fixed = mcl_heads.FLOOR_BOX, }, @@ -38,7 +43,7 @@ mcl_heads.deftemplate_floor = { }, use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, paramtype = "light", - paramtype2 = "facedir", + paramtype2 = "degrotate", stack_max = 64, sunlight_propagates = true, sounds = mcl_sounds.node_sound_defaults{ @@ -53,39 +58,8 @@ mcl_heads.deftemplate_floor = { on_secondary_use = equip_armor, } -mcl_heads.deftemplate_floor_angled = { - drawtype = "mesh", - selection_box = { - type = "fixed", - fixed = mcl_heads.FLOOR_BOX, - }, - collision_box = { - type = "fixed", - fixed = mcl_heads.FLOOR_BOX, - }, - groups = { - handy = 1, - head = 1, - deco_block = 1, - dig_by_piston = 1, - not_in_creative_inventory = 1, - }, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, - paramtype = "light", - paramtype2 = "facedir", - stack_max = 64, - sunlight_propagates = true, - sounds = mcl_sounds.node_sound_defaults{ - footstep = {name="default_hard_footstep", gain=0.3}, - }, - is_ground_content = false, - - _doc_items_create_entry = false, - _mcl_blast_resistance = 1, - _mcl_hardness = 1, -} - function mcl_heads.deftemplate_floor.on_rotate(pos, node, user, mode, new_param2) + if not (user and user:is_player()) then return end if mode == screwdriver.ROTATE_AXIS then node.name = node.name .. "_wall" node.param2 = minetest.dir_to_wallmounted(minetest.facedir_to_dir(node.param2)) @@ -125,19 +99,9 @@ function mcl_heads.deftemplate_floor.on_place(itemstack, placer, pointed_thing) -- place floor head node (floor and ceiling) else - local fdir = minetest.dir_to_facedir(dir) - -- determine the head node rotation based on player's yaw (in cw direction from North/Z+) - local yaw = placer:get_look_horizontal() - yaw = wdir == 1 and math.pi*2 - yaw or yaw - - local rotation_level = math.min(math.max(math.round((yaw / (math.pi*2)) * 16), 0), 15) - placestack:set_name(itemstring ..mcl_heads.FLOOR_DEGREES[rotation_level % 4]) - - -- determine the head node face direction based on rotation level - fdir = math.floor(rotation_level / 4) + (wdir == 1 and 0 or 20) - - itemstack = minetest.item_place(placestack, placer, pointed_thing, fdir) + local rotate_level = math.round(placer:get_look_horizontal() * 8/math.pi) + itemstack = minetest.item_place(placestack, placer, pointed_thing, rotate_level*15) end -- restore item from angled and wall head nodes @@ -179,6 +143,7 @@ mcl_heads.deftemplate_wall = { } function mcl_heads.deftemplate_wall.on_rotate(pos, node, user, mode, new_param2) + if not (user and user:is_player()) then return end 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)) @@ -207,33 +172,13 @@ function mcl_heads.register_head(head_def) description = head_def.description, _doc_items_longdesc = head_def.longdesc, - -- The head textures are based off the textures of an actual mob. - tiles = { - -- Note: bottom texture is overlaid over top texture to get rid of possible transparency. - -- This is required for skeleton skull and wither skeleton skull. - -- Note: -x coords go right per-pixel, -y coords go down per-pixel - "[combine:16x16:-36,4=" ..head_def.texture, -- top - "([combine:16x16:-36,4=" ..head_def.texture..")^([combine:16x16:-44,4="..head_def.texture..")", -- bottom - "[combine:16x16:-28,0=" ..head_def.texture, -- left - "[combine:16x16:-44,0=" ..head_def.texture, -- right - "[combine:16x16:-52,0=" ..head_def.texture, -- back - "[combine:16x16:-36,0=" ..head_def.texture, -- front - }, + tiles = { head_def.texture }, _mcl_armor_mob_range_mob = head_def.range_mob, _mcl_armor_mob_range_factor = head_def.range_factor, _mcl_armor_texture = head_def.texture })) - -- register the angled floor head nodes - for i, d in ipairs(mcl_heads.FLOOR_DEGREES) do - minetest.register_node(name ..d, table.update(table.copy(mcl_heads.deftemplate_floor_angled), { - mesh = "mcl_heads_floor" ..d ..".obj", - tiles = { head_def.texture }, - drop = name, - })) - end - -- register the wall head node minetest.register_node(name .."_wall", table.update(table.copy(mcl_heads.deftemplate_wall), { -- The head textures are based off the textures of an actual mob. @@ -272,12 +217,6 @@ mcl_heads.register_head{ range_factor = 0.5, } --- Alias old creeper heads -minetest.register_alias("mcl_heads:creeper_wall", "mcl_heads:stalker_wall") -for i, d in pairs(mcl_heads.FLOOR_DEGREES) do - minetest.register_alias("mcl_heads:creeper"..d, "mcl_heads:stalker"..d) -end - -- Original Minecraft name: “Head” mcl_heads.register_head{ name = "steve", @@ -301,3 +240,45 @@ mcl_heads.register_head{ description = S("Wither Skeleton Skull"), longdesc = 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."), } + +-- Alias old creeper heads +minetest.register_alias("mcl_heads:creeper_wall", "mcl_heads:stalker_wall") +minetest.register_alias("mcl_heads:creeper", "mcl_heads:stalker") + +-- Register LBM updates for old floor heads +local old_heads_all = {"mcl_heads:zombie", "mcl_heads:creeper", "mcl_heads:stalker", "mcl_heads:steve", "mcl_heads:skeleton", "mcl_heads:wither_skeleton"} +local old_heads_angled = {} +for i=1,#old_heads_all do + for j=1,#mcl_heads.FLOOR_DEGREES do + old_heads_angled[#old_heads_angled+1] = old_heads_all[i]..mcl_heads.FLOOR_DEGREES[j] + end +end + +local facedir_to_degrotate = {0, 180, 120, 60} +minetest.register_lbm({ + name = "mcl_heads:heads_update_angled", + nodenames = old_heads_all, + action = function(pos, node) + local degrotate = 0 + + if node.name:sub(-4) == "22_5" then + node.name = node.name:sub(1, #node.name-4) + degrotate = ((4 - node.param2) * 90 - 22.5) / 1.5 + elseif node.name:sub(-4) == "67_5" then + node.name = node.name:sub(1, #node.name-4) + degrotate = ((4 - node.param2) * 90 - 67.5) / 1.5 + elseif node.name:sub(-2) == "45" then + node.name = node.name:sub(1, #node.name-2) + degrotate = ((4 - node.param2) * 90 - 45) / 1.5 + else + degrotate = facedir_to_degrotate[node.param2+1] + end + + if not degrotate then + return + end + + node.param2 = degrotate + minetest.set_node(pos, node) + end, +}) diff --git a/mods/ITEMS/mcl_heads/models/mcl_heads_floor.obj b/mods/ITEMS/mcl_heads/models/mcl_heads_floor.obj new file mode 100644 index 000000000..53bb522d4 --- /dev/null +++ b/mods/ITEMS/mcl_heads/models/mcl_heads_floor.obj @@ -0,0 +1,41 @@ +# Blender 4.2.1 LTS +# www.blender.org +mtllib mcl_head.mtl +g Cube.002_Cube.002 +v -0.250000 -0.500000 0.250000 +v -0.250000 0.000000 0.250000 +v -0.250000 -0.500000 -0.250000 +v -0.250000 -0.000000 -0.250000 +v 0.250000 -0.500000 0.250000 +v 0.250000 0.000000 0.250000 +v 0.250000 -0.500000 -0.250000 +v 0.250000 0.000000 -0.250000 +vn -1.0000 -0.0000 -0.0000 +vn -0.0000 -0.0000 -1.0000 +vn 1.0000 -0.0000 -0.0000 +vn -0.0000 -0.0000 1.0000 +vn -0.0000 -1.0000 -0.0000 +vn -0.0000 1.0000 -0.0000 +vt 0.875000 0.500000 +vt 0.875000 0.750000 +vt 0.750000 0.750000 +vt 0.750000 0.500000 +vt 0.625000 0.750000 +vt 0.625000 0.500000 +vt 0.500000 0.750000 +vt 0.500000 0.500000 +vt 1.000000 0.500000 +vt 1.000000 0.750000 +vt 0.875000 1.000000 +vt 0.750000 1.000000 +vt 0.625000 1.000000 +s 0 +g off +g Cube.002_Material.002 +usemtl Material.002 +f 1/1/1 2/2/1 4/3/1 3/4/1 +f 3/4/2 4/3/2 8/5/2 7/6/2 +f 7/6/3 8/5/3 6/7/3 5/8/3 +f 5/9/4 6/10/4 2/2/4 1/1/4 +f 3/2/5 7/11/5 5/12/5 1/3/5 +f 8/5/6 4/3/6 2/12/6 6/13/6 diff --git a/mods/ITEMS/mcl_heads/models/mcl_heads_floor22_5.obj b/mods/ITEMS/mcl_heads/models/mcl_heads_floor22_5.obj deleted file mode 100644 index 8e48015fc..000000000 --- a/mods/ITEMS/mcl_heads/models/mcl_heads_floor22_5.obj +++ /dev/null @@ -1,42 +0,0 @@ -# Blender v2.93.9 OBJ File: 'mcl_heads_floor_0.blend' -# www.blender.org -mtllib mcl_heads_floor22_5.mtl -o Cube.001 -v -0.326641 -0.500000 0.135299 -v -0.326641 0.000000 0.135299 -v -0.135299 -0.500000 -0.326641 -v -0.135299 0.000000 -0.326641 -v 0.135299 -0.500000 0.326641 -v 0.135299 0.000000 0.326641 -v 0.326641 -0.500000 -0.135299 -v 0.326641 0.000000 -0.135299 -vt 0.875000 0.500000 -vt 0.875000 0.750000 -vt 0.750000 0.750000 -vt 0.750000 0.500000 -vt 0.625000 0.750000 -vt 0.625000 0.500000 -vt 0.500000 0.750000 -vt 0.500000 0.500000 -vt 1.000000 0.500000 -vt 1.000000 0.750000 -vt 0.875000 0.750000 -vt 0.875000 1.000000 -vt 0.750000 1.000000 -vt 0.750000 0.750000 -vt 0.750000 1.000000 -vt 0.625000 1.000000 -vn -0.9239 0.0000 -0.3827 -vn 0.3827 0.0000 -0.9239 -vn 0.9239 0.0000 0.3827 -vn -0.3827 0.0000 0.9239 -vn 0.0000 -1.0000 0.0000 -vn 0.0000 1.0000 0.0000 -usemtl Material.001 -s off -f 1/1/1 2/2/1 4/3/1 3/4/1 -f 3/4/2 4/3/2 8/5/2 7/6/2 -f 7/6/3 8/5/3 6/7/3 5/8/3 -f 5/9/4 6/10/4 2/2/4 1/1/4 -f 3/11/5 7/12/5 5/13/5 1/14/5 -f 8/5/6 4/3/6 2/15/6 6/16/6 diff --git a/mods/ITEMS/mcl_heads/models/mcl_heads_floor45.obj b/mods/ITEMS/mcl_heads/models/mcl_heads_floor45.obj deleted file mode 100644 index 6300d4484..000000000 --- a/mods/ITEMS/mcl_heads/models/mcl_heads_floor45.obj +++ /dev/null @@ -1,42 +0,0 @@ -# Blender v2.93.9 OBJ File: 'mcl_heads_floor_0.blend' -# www.blender.org -mtllib mcl_heads_floor45.mtl -o Cube.002 -v -0.353553 -0.500000 0.000000 -v -0.353553 0.000000 0.000000 -v 0.000000 -0.500000 -0.353553 -v 0.000000 0.000000 -0.353553 -v 0.000000 -0.500000 0.353553 -v 0.000000 0.000000 0.353553 -v 0.353553 -0.500000 0.000000 -v 0.353553 0.000000 0.000000 -vt 0.875000 0.500000 -vt 0.875000 0.750000 -vt 0.750000 0.750000 -vt 0.750000 0.500000 -vt 0.625000 0.750000 -vt 0.625000 0.500000 -vt 0.500000 0.750000 -vt 0.500000 0.500000 -vt 1.000000 0.500000 -vt 1.000000 0.750000 -vt 0.875000 0.750000 -vt 0.875000 1.000000 -vt 0.750000 1.000000 -vt 0.750000 0.750000 -vt 0.750000 1.000000 -vt 0.625000 1.000000 -vn -0.7071 0.0000 -0.7071 -vn 0.7071 0.0000 -0.7071 -vn 0.7071 0.0000 0.7071 -vn -0.7071 0.0000 0.7071 -vn 0.0000 -1.0000 0.0000 -vn 0.0000 1.0000 0.0000 -usemtl Material.002 -s off -f 1/1/1 2/2/1 4/3/1 3/4/1 -f 3/4/2 4/3/2 8/5/2 7/6/2 -f 7/6/3 8/5/3 6/7/3 5/8/3 -f 5/9/4 6/10/4 2/2/4 1/1/4 -f 3/11/5 7/12/5 5/13/5 1/14/5 -f 8/5/6 4/3/6 2/15/6 6/16/6 diff --git a/mods/ITEMS/mcl_heads/models/mcl_heads_floor67_5.obj b/mods/ITEMS/mcl_heads/models/mcl_heads_floor67_5.obj deleted file mode 100644 index 0fe5567e3..000000000 --- a/mods/ITEMS/mcl_heads/models/mcl_heads_floor67_5.obj +++ /dev/null @@ -1,42 +0,0 @@ -# Blender v2.93.9 OBJ File: 'mcl_heads_floor_0.blend' -# www.blender.org -mtllib mcl_heads_floor67_5.mtl -o Cube.003 -v -0.326641 -0.500000 -0.135299 -v -0.326641 0.000000 -0.135299 -v 0.135299 -0.500000 -0.326641 -v 0.135299 0.000000 -0.326641 -v -0.135299 -0.500000 0.326641 -v -0.135299 0.000000 0.326641 -v 0.326641 -0.500000 0.135299 -v 0.326641 0.000000 0.135299 -vt 0.875000 0.500000 -vt 0.875000 0.750000 -vt 0.750000 0.750000 -vt 0.750000 0.500000 -vt 0.625000 0.750000 -vt 0.625000 0.500000 -vt 0.500000 0.750000 -vt 0.500000 0.500000 -vt 1.000000 0.500000 -vt 1.000000 0.750000 -vt 0.875000 0.750000 -vt 0.875000 1.000000 -vt 0.750000 1.000000 -vt 0.750000 0.750000 -vt 0.750000 1.000000 -vt 0.625000 1.000000 -vn -0.3827 0.0000 -0.9239 -vn 0.9239 0.0000 -0.3827 -vn 0.3827 0.0000 0.9239 -vn -0.9239 0.0000 0.3827 -vn 0.0000 -1.0000 0.0000 -vn 0.0000 1.0000 0.0000 -usemtl Material.003 -s off -f 1/1/1 2/2/1 4/3/1 3/4/1 -f 3/4/2 4/3/2 8/5/2 7/6/2 -f 7/6/3 8/5/3 6/7/3 5/8/3 -f 5/9/4 6/10/4 2/2/4 1/1/4 -f 3/11/5 7/12/5 5/13/5 1/14/5 -f 8/5/6 4/3/6 2/15/6 6/16/6