1
0
Fork 0
MineClone2/mods/PLAYER/mcl_meshhand/init.lua

107 lines
3.7 KiB
Lua
Raw Normal View History

2022-08-29 18:09:00 +00:00
local mcl_skins_enabled = minetest.global_exists("mcl_skins")
2023-01-11 18:31:56 +00:00
mcl_meshhand = { }
2019-03-05 10:43:09 +00:00
---This is a fake node that should never be placed in the world
---@type node_definition
2022-08-29 18:09:00 +00:00
local node_def = {
use_texture_alpha = "opaque",
2022-08-29 18:09:00 +00:00
paramtype = "light",
drawtype = "mesh",
node_placement_prediction = "",
on_construct = function(pos)
local name = minetest.get_node(pos).name
2022-08-29 18:09:00 +00:00
local message = "[mcl_meshhand] Trying to construct " .. name .. " at " .. minetest.pos_to_string(pos)
minetest.log("error", message)
minetest.remove_node(pos)
end,
drop = "",
on_drop = function(_, _, _) return ItemStack() end,
2023-01-11 18:31:56 +00:00
groups = {
dig_immediate = 3,
not_in_creative_inventory = 1,
dig_speed_class = 1,
},
tool_capabilities = {
full_punch_interval = 0.25,
max_drop_level = 0,
groupcaps = { },
damage_groups = { fleshy = 1 },
},
_mcl_diggroups = {
handy = { speed = 1, level = 1, uses = 0 },
axey = { speed = 1, level = 1, uses = 0 },
shovely = { speed = 1, level = 1, uses = 0 },
hoey = { speed = 1, level = 1, uses = 0 },
pickaxey = { speed = 1, level = 0, uses = 0 },
swordy = { speed = 1, level = 0, uses = 0 },
swordy_cobweb = { speed = 1, level = 0, uses = 0 },
shearsy = { speed = 1, level = 0, uses = 0 },
shearsy_wool = { speed = 1, level = 0, uses = 0 },
shearsy_cobweb = { speed = 1, level = 0, uses = 0 },
},
range = tonumber(minetest.settings:get("mcl_hand_range")) or 4.5
2022-08-29 18:09:00 +00:00
}
2023-01-11 18:31:56 +00:00
-- This is for _mcl_autogroup to know about the survival hand tool capabilites
mcl_meshhand.survival_hand_tool_caps = node_def.tool_capabilities
2023-01-19 17:30:14 +00:00
local creative_dig_speed = tonumber(minetest.settings:get("mcl_creative_dig_speed")) or 0.2
2023-01-11 18:31:56 +00:00
local creative_hand_range = tonumber(minetest.settings:get("mcl_hand_range_creative")) or 10
2022-08-29 18:09:00 +00:00
if mcl_skins_enabled then
-- Generate a node for every skin
2022-09-06 17:51:43 +00:00
local list = mcl_skins.get_skin_list()
for _, skin in pairs(list) do
2023-01-11 18:31:56 +00:00
local node_def = table.copy(node_def)
node_def._mcl_hand_id = skin.id
node_def.tiles = { skin.texture }
node_def.mesh = skin.slim_arms and "mcl_meshhand_female.b3d" or "mcl_meshhand.b3d"
if skin.creative then
node_def.range = creative_hand_range
node_def.groups.dig_speed_class = 7
2023-01-19 17:30:14 +00:00
node_def.tool_capabilities.groupcaps.creative_breakable = { times = { creative_dig_speed }, uses = 0 }
2022-08-29 18:09:00 +00:00
end
2023-01-11 18:31:56 +00:00
minetest.register_node("mcl_meshhand:" .. skin.id, node_def)
2022-08-29 18:09:00 +00:00
end
else
node_def._mcl_hand_id = "hand"
node_def.mesh = "mcl_meshhand.b3d"
node_def.tiles = { "character.png" }
2023-01-11 18:31:56 +00:00
minetest.register_node("mcl_meshhand:hand_surv", node_def)
node_def = table.copy(node_def)
node_def.range = creative_hand_range
node_def.groups.dig_speed_class = 7
2023-01-19 17:30:14 +00:00
node_def.tool_capabilities.groupcaps.creative_breakable = { times = { creative_dig_speed }, uses = 0 }
2023-01-11 18:31:56 +00:00
minetest.register_node("mcl_meshhand:hand_crea", node_def)
2019-09-19 10:20:31 +00:00
end
2019-03-05 10:43:09 +00:00
2023-01-11 18:31:56 +00:00
function mcl_meshhand.update_player(player)
if mcl_skins_enabled then
2022-09-06 17:51:43 +00:00
local node_id = mcl_skins.get_node_id_by_player(player)
2022-08-29 18:09:00 +00:00
player:get_inventory():set_stack("hand", 1, "mcl_meshhand:" .. node_id)
2023-01-11 18:31:56 +00:00
else
local creative = minetest.is_creative_enabled(player:get_player_name())
player:get_inventory():set_stack("hand", 1, "mcl_meshhand:hand" .. (creative and "_crea" or "_surv"))
end
end
2023-07-31 15:04:41 +00:00
minetest.register_on_joinplayer(function(player)
player:get_inventory():set_size("hand", 1)
end)
2023-07-28 15:15:41 +00:00
mcl_gamemode.register_on_gamemode_change(function(player)
mcl_meshhand.update_player(player)
end)
2023-01-11 18:31:56 +00:00
if mcl_skins_enabled then
mcl_player.register_on_visual_change(mcl_meshhand.update_player)
2019-09-19 10:20:31 +00:00
else
2023-01-11 18:31:56 +00:00
minetest.register_on_joinplayer(mcl_meshhand.update_player)
2019-03-05 10:43:09 +00:00
end
2023-03-10 19:24:32 +00:00
-- This is needed to deal damage when punching mobs
-- with random items in hand in survival mode
minetest.override_item("", {
tool_capabilities = mcl_meshhand.survival_hand_tool_caps
})