-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
Code simplification by combining the on_place functions.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
SmallJoker
Author
Member
|
||
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", | ||
|
@@ -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"}) | ||
|
@@ -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"}) | ||
|
@@ -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"}) | ||
|
2 comments
on commit 95aaec6
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
The "protection_bypass" priv is ignored. (Builtin causes confusion.)