Skip to content

Commit

Permalink
override coral "on_place" with fixed function until next mt_game release
Browse files Browse the repository at this point in the history
  • Loading branch information
naturefreshmilk committed Dec 27, 2019
1 parent a84f987 commit 8b3738d
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions hacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,55 @@
minetest.find_path = function()
return nil
end

-- stolen from
-- https://github.com/minetest/minetest_game/blob/d2e051f1795576213f807ec0feac5f72f51c6113/mods/default/nodes.lua
-- fixes https://github.com/pandorabox-io/pandorabox.io/issues/358
-- TODO: remove after upgrade to next mt_game > 5.1.0
local function coral_on_place(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" or not placer then
return itemstack
end

local player_name = placer:get_player_name()
local pos_under = pointed_thing.under
local pos_above = pointed_thing.above
local node_under = minetest.get_node(pos_under)
local def_under = minetest.registered_nodes[node_under.name]

if def_under and def_under.on_rightclick and not placer:get_player_control().sneak then
return def_under.on_rightclick(pos_under, node_under,
placer, itemstack, pointed_thing) or itemstack
end

if node_under.name ~= "default:coral_skeleton" or
minetest.get_node(pos_above).name ~= "default:water_source" then
return itemstack
end

if minetest.is_protected(pos_under, player_name) or
minetest.is_protected(pos_above, player_name) then
minetest.log("action", player_name
.. " tried to place " .. itemstack:get_name()
.. " at protected position "
.. minetest.pos_to_string(pos_under))
minetest.record_protection_violation(pos_under, player_name)
return itemstack
end

node_under.name = itemstack:get_name()
minetest.set_node(pos_under, node_under)
itemstack:take_item()

return itemstack
end

minetest.override_item("default:coral_green", {
on_place = coral_on_place
})
minetest.override_item("default:coral_pink", {
on_place = coral_on_place
})
minetest.override_item("default:coral_cyan", {
on_place = coral_on_place
})

0 comments on commit 8b3738d

Please sign in to comment.