summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
author0gb.us <0gb.us@0gb.us>2013-03-28 01:24:48 -0700
committerkwolekr <kwolekr@minetest.net>2013-03-29 14:18:51 -0400
commit02cbb5810774ec0d8eb43b6cd5796a3d43878fe1 (patch)
treef0d1c3ddea7cb8101d7211545dd912684838fa2c /builtin
parent5b854f95d2144710493520151aafc48a887ac1b3 (diff)
downloadminetest-02cbb5810774ec0d8eb43b6cd5796a3d43878fe1.tar.gz
minetest-02cbb5810774ec0d8eb43b6cd5796a3d43878fe1.tar.bz2
minetest-02cbb5810774ec0d8eb43b6cd5796a3d43878fe1.zip
Fix node replacement in not-quite-loaded chunks
When first entering an area, sometimes placing nodes replaces other nodes that are not buildable_to. This seems to be caused by the fact that nodes in unloaded map blocks are treated as ignore, a node that is buildable_to. This fixes that, by using get_node_or_nil() instead of the previously-used get_node(), then checking to see if the nodes were actually loaded before replacing.
Diffstat (limited to 'builtin')
-rw-r--r--builtin/item.lua13
1 files changed, 10 insertions, 3 deletions
diff --git a/builtin/item.lua b/builtin/item.lua
index 1349fdf63..8e2f75a1a 100644
--- a/builtin/item.lua
+++ b/builtin/item.lua
@@ -129,11 +129,18 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
end
local under = pointed_thing.under
- local oldnode_under = minetest.env:get_node(under)
+ local oldnode_under = minetest.env:get_node_or_nil(under)
+ local above = pointed_thing.above
+ local oldnode_above = minetest.env:get_node_or_nil(above)
+
+ if not oldnode_under or not oldnode_above then
+ minetest.log("info", placer:get_player_name() .. " tried to place"
+ .. " node in unloaded position " .. minetest.pos_to_string(above))
+ return itemstack
+ end
+
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
olddef_under = olddef_under or minetest.nodedef_default
- local above = pointed_thing.above
- local oldnode_above = minetest.env:get_node(above)
local olddef_above = ItemStack({name=oldnode_above.name}):get_definition()
olddef_above = olddef_above or minetest.nodedef_default