Fix broken rightclick for tallgrass and cotton_4

This commit is contained in:
Wuzzy 2019-10-24 22:28:44 +02:00
parent 06e7c02e54
commit fa168eb747
3 changed files with 35 additions and 33 deletions

View File

@ -1046,28 +1046,19 @@ minetest.register_node(
floodable = true,
groups = {snappy = 2, dig_immediate = 3, attached_node = 1, grass = 1, normal_grass = 1, green_grass = 1},
sounds = default.node_sound_leaves_defaults(),
on_rightclick = function(pos, node, player, itemstack)
if minetest.is_protected(pos, player:get_player_name()) and
not minetest.check_player_privs(player, "protection_bypass") then
minetest.record_protection_violation(pos, player:get_player_name())
return itemstack
-- Trim tall grass with shears
_on_trim = function(pos, node, player, itemstack)
-- This turns it to a normal grass clump and drops one bonus grass clump
minetest.sound_play({name = "default_shears_cut", gain = 0.5}, {pos = player:get_pos(), max_hear_distance = 8})
minetest.set_node(pos, {name = "default:grass"})
item_drop.drop_item(pos, "default:grass")
-- Add wear
if not minetest.settings:get_bool("creative_mode") then
local def = itemstack:get_definition()
itemstack:add_wear(math.ceil(65536 / def.tool_capabilities.groupcaps.snappy.uses))
end
-- Trim tall grass clump when rightclicked by shears
local name = itemstack:get_name()
if minetest.get_item_group(name, "shears") == 1 then
-- This turns it to a normal grass clump and drops one bonus grass clump
minetest.sound_play({name = "default_shears_cut", gain = 0.5}, {pos = player:get_pos(), max_hear_distance = 8})
minetest.set_node(pos, {name = "default:grass"})
item_drop.drop_item(pos, "default:grass")
-- Add wear
if not minetest.settings:get_bool("creative_mode") then
local def = itemstack:get_definition()
itemstack:add_wear(math.ceil(65536 / def.tool_capabilities.groupcaps.snappy.uses))
end
end
return itemstack
end,
})

View File

@ -672,6 +672,22 @@ minetest.register_tool(
-- Other
local trim = function(itemstack, player, pointed_thing)
if pointed_thing.type == "node" then
local pos = pointed_thing.under
local node = minetest.get_node(pos)
local def = minetest.registered_nodes[node.name]
if def and def._on_trim then
if minetest.is_protected(pos, player:get_player_name()) and
not minetest.check_player_privs(player, "protection_bypass") then
minetest.record_protection_violation(pos, player:get_player_name())
return
end
return def._on_trim(pos, node, player, itemstack, pointed_thing)
end
end
end
minetest.register_tool(
"default:shears",
{
@ -687,6 +703,7 @@ minetest.register_tool(
snappy={times=tool_levels.wrought_iron.snappy, uses=15, maxlevel=1},
},
},
on_place = trim,
})
minetest.register_tool(
"default:shears_steel",
@ -703,6 +720,7 @@ minetest.register_tool(
snappy={times=tool_levels.steel.snappy, uses=30, maxlevel=1},
},
},
on_place = trim,
})
minetest.register_tool(
"default:shears_carbon_steel",
@ -719,6 +737,7 @@ minetest.register_tool(
snappy={times=tool_levels.carbon_steel.snappy, uses=40, maxlevel=1},
},
},
on_place = trim,
})
minetest.register_tool(
"default:shears_bronze",
@ -735,6 +754,7 @@ minetest.register_tool(
snappy={times=tool_levels.bronze.snappy, uses=30, maxlevel=1},
},
},
on_place = trim,
})
minetest.register_tool(

View File

@ -260,18 +260,9 @@ minetest.register_node(
},
groups = {snappy=3, handy=2, attached_node=1, not_in_craft_guide = 1, not_in_creative_inventory = 1},
sounds = default.node_sound_leaves_defaults(),
on_rightclick = function(pos, node, player, itemstack)
if minetest.is_protected(pos, player:get_player_name()) and
not minetest.check_player_privs(player, "protection_bypass") then
minetest.record_protection_violation(pos, player:get_player_name())
return itemstack
end
-- Trim cotton when rightclicking with shears
if minetest.get_item_group(itemstack:get_name(), "shears") == 1 then
itemstack = trim_cotton(pos, node, player, itemstack)
end
return itemstack
end,
-- Trim cotton with shears
_on_trim = trim_cotton,
}
)