Issues with Porting Rope Mod
Trying to port the Rope mod to work with ItemDef. Although it is functional now, I'm having trouble removing the rope from the player's inventory after placing a rope. Here is the code:
Does anyone know what I'm doing wrong?
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
-- Rope mod. By Mirko K.
--
-- Three tree block in a vertical row = 9 meter of rope.
-- Placement automatically adds rope downwards until it runs out or some
-- non-air block is in the way.
-- Push (single left-click) cuts the rope at that position. Digging removes
-- the whole rope.
--
-- Licence:
-- Code: GPL
-- Texture: CC-BY-SA
minetest.register_on_placenode(function(pos, newnode, placer)
if newnode.name == "ropes:rope" then
place_rope(pos, newnode, placer)
end
end
)
minetest.register_on_dignode(function(pos, oldnode, digger)
if oldnode.name == "ropes:rope" then
remove_rope(pos, oldnode, digger, true)
end
end
)
minetest.register_on_punchnode(function(pos, oldnode, digger)
if oldnode.name == "ropes:rope" then
remove_rope(pos, oldnode, digger, false)
end
end
)
place_rope = function (pos, newnode, placer)
while placer:get_inventory():contains_item("main", "ropes:rope") do
pos.y = pos.y - 1
if minetest.env:get_node(pos).name ~= "air" then
break
end
placer:get_inventory():remove_item("main", "ropes:rope") --remove rope
minetest.env:add_node(pos, {name="ropes:rope", param2=newnode.param2})
end
end
remove_rope = function(pos, oldnode, digger, completely)
local num = 0
local above = {x=pos.x,y=pos.y+1,z=pos.z}
if completely == true then
while minetest.env:get_node(above).name == "ropes:rope" do
minetest.env:remove_node(above)
above.y = above.y + 1
num = num + 1
end
end
local below = {x=pos.x,y=pos.y-1,z=pos.z}
while minetest.env:get_node(below).name == "ropes:rope" do
minetest.env:remove_node(below)
below.y = below.y -1
num = num + 1
end
if num ~= 0 then
digger:get_inventory():add_item("main", '"ropes:rope" '..num)
end
return true
end
minetest.register_craft({
output = '"ropes:rope" 9',
recipe = {
{'', 'tree', ''},
{'', 'tree', ''},
{'', 'tree', ''},
}
})
minetest.register_node("ropes:rope", {
description = "Rope",
drawtype = "signlike",
tile_images = {"rope.png"},
inventory_image = "rope.png",
light_propagates = true,
paramtype = "light",
paramtype2 = "wallmounted",
legacy_wall_mounted = true,
is_ground_content = true,
walkable = false,
climbable = true,
selection_box = {
type = "wallmounted",
--wall_top = = <default>
--wall_bottom = = <default>
--wall_side = = <default>
},
furnace_burntime = 5,
material = {
diggablity = "normal",
cuttability = 1.5,
},
})
Does anyone know what I'm doing wrong?