Skip to content

Commit

Permalink
Allow opening chests when wielding corals
Browse files Browse the repository at this point in the history
Code simplification by combining the on_place functions.
  • Loading branch information
SmallJoker authored and paramat committed Jul 12, 2019
1 parent 5b1d581 commit 95aaec6
Showing 1 changed file with 43 additions and 84 deletions.
127 changes: 43 additions & 84 deletions mods/default/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1996,6 +1996,46 @@ minetest.register_node("default:sand_with_kelp", {
-- Corals
--

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.name,
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

This comment has been minimized.

Copy link
@Desour

Desour Jul 13, 2019

Member

The "protection_bypass" priv is ignored. (Builtin causes confusion.)

This comment has been minimized.

Copy link
@paramat

paramat Jul 13, 2019

Contributor

@SmallJoker this might need a quick fix.

This comment has been minimized.

Copy link
@SmallJoker

SmallJoker Jul 13, 2019

Author Member

aaaaghh builtin why do you do this to me
🤦‍♂️

This comment has been minimized.

Copy link
@SmallJoker

SmallJoker Jul 13, 2019

Author Member

Update: MTG usually only checks for is_protected, but not for the privilege. On the other side: 4 out of 4 checked protection check for the privilege, so that's why it's never been an issue. Either MTG and many mods will need to be updated or we just rely on that protection mods respect that privilege.

This comment has been minimized.

Copy link
@Desour

This comment has been minimized.

Copy link
@paramat

paramat Jul 13, 2019

Contributor

we just rely on that protection mods respect that privilege.

I prefer this.
I didn't like that priv when it was added, so i don't care if MTG never checks it.

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)
if not (creative and creative.is_enabled_for(player_name)) then
itemstack:take_item()
end

return itemstack
end

minetest.register_node("default:coral_green", {
description = "Green Coral",
drawtype = "plantlike_rooted",
Expand All @@ -2019,34 +2059,7 @@ minetest.register_node("default:coral_green", {
dug = {name = "default_grass_footstep", gain = 0.25},
}),

on_place = function(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

if minetest.get_node(pos_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.chat_send_player(player_name, "Node is protected")
minetest.record_protection_violation(pos_under, player_name)
return itemstack
end

minetest.set_node(pos_under, {name = "default:coral_green"})
if not (creative and creative.is_enabled_for(player_name)) then
itemstack:take_item()
end

return itemstack
end,
on_place = coral_on_place,

after_destruct = function(pos, oldnode)
minetest.set_node(pos, {name = "default:coral_skeleton"})
Expand Down Expand Up @@ -2076,34 +2089,7 @@ minetest.register_node("default:coral_pink", {
dug = {name = "default_grass_footstep", gain = 0.25},
}),

on_place = function(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

if minetest.get_node(pos_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.chat_send_player(player_name, "Node is protected")
minetest.record_protection_violation(pos_under, player_name)
return itemstack
end

minetest.set_node(pos_under, {name = "default:coral_pink"})
if not (creative and creative.is_enabled_for(player_name)) then
itemstack:take_item()
end

return itemstack
end,
on_place = coral_on_place,

after_destruct = function(pos, oldnode)
minetest.set_node(pos, {name = "default:coral_skeleton"})
Expand Down Expand Up @@ -2133,34 +2119,7 @@ minetest.register_node("default:coral_cyan", {
dug = {name = "default_grass_footstep", gain = 0.25},
}),

on_place = function(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

if minetest.get_node(pos_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.chat_send_player(player_name, "Node is protected")
minetest.record_protection_violation(pos_under, player_name)
return itemstack
end

minetest.set_node(pos_under, {name = "default:coral_cyan"})
if not (creative and creative.is_enabled_for(player_name)) then
itemstack:take_item()
end

return itemstack
end,
on_place = coral_on_place,

after_destruct = function(pos, oldnode)
minetest.set_node(pos, {name = "default:coral_skeleton"})
Expand Down

2 comments on commit 95aaec6

@Enrikoo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I open a chest with coral in my hand, it rotates. It happens on certain directions for chest.

@paramat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, please could you open an issue for this so that it doesn't get forgotten.

Please sign in to comment.