Add infinite placement in level editor

master
Wuzzy 2022-02-10 19:42:45 +01:00
parent a93da1f623
commit 1a41881a4f
2 changed files with 28 additions and 1 deletions

View File

@ -134,7 +134,29 @@ minetest.register_chatcommand("editor_load", {
end,
})
-- Unlimited node placement in editor mode
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
if placer and placer:is_player() then
return lzr_gamestate.get_state() == lzr_gamestate.EDITOR
end
end)
-- Don't pick node up if the item is already in the inventory
local old_handle_node_drops = minetest.handle_node_drops
function minetest.handle_node_drops(pos, drops, digger)
if not digger or not digger:is_player() or
lzr_gamestate.get_state() ~= lzr_gamestate.EDITOR then
return old_handle_node_drops(pos, drops, digger)
end
local inv = digger:get_inventory()
if inv then
for _, item in ipairs(drops) do
if not inv:contains_item("main", item, true) then
inv:add_item("main", item)
end
end
end
end
lzr_gamestate.register_on_enter_state(function(state)
if state == lzr_gamestate.EDITOR then

View File

@ -35,5 +35,10 @@ end)
-- Can't drop items
function minetest.item_drop(itemstack, dropper, pos)
return itemstack
if lzr_gamestate.get_state() == lzr_gamestate.EDITOR then
-- Destroy item in editor mode
return ""
else
return itemstack
end
end