summaryrefslogtreecommitdiff
path: root/builtin/game
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2015-09-29 17:26:07 +0200
committerest31 <MTest31@outlook.com>2015-09-29 23:06:15 +0200
commit2a7d01b833da7b93125ad31e787f3e2145a22ec5 (patch)
tree6935cfd49760e6ef09723ab9471f23261efc2d95 /builtin/game
parent0cde03254a6564eaec21603e9add4f14e6c2fe52 (diff)
downloadminetest-2a7d01b833da7b93125ad31e787f3e2145a22ec5.tar.gz
minetest-2a7d01b833da7b93125ad31e787f3e2145a22ec5.tar.bz2
minetest-2a7d01b833da7b93125ad31e787f3e2145a22ec5.zip
Some map border related fixes
1. Check for entity addition success in spawn_item implementation 2. Check for success in item_drop callback, so that the player doesn't lose the item if they are outside bounds and try to drop it. 3. When existing player joins game, check that their position is inside map bounds. If not, set their position to the return value of findSpawnPos(). 4. Make findSpawnPos() respect the border 2 fixes a lua crash if a player drops an item outside map bounds. 3 fixes an assertion crash if a player leaves when being outside map bounds, and then rejoins.
Diffstat (limited to 'builtin/game')
-rw-r--r--builtin/game/item.lua8
-rw-r--r--builtin/game/item_entity.lua9
2 files changed, 12 insertions, 5 deletions
diff --git a/builtin/game/item.lua b/builtin/game/item.lua
index 6628a4081..0f10af8ee 100644
--- a/builtin/game/item.lua
+++ b/builtin/game/item.lua
@@ -349,12 +349,16 @@ function core.item_drop(itemstack, dropper, pos)
v.y = v.y*2 + 2
v.z = v.z*2
obj:setvelocity(v)
+ return itemstack
end
else
- core.add_item(pos, itemstack)
+ if core.add_item(pos, itemstack) then
+ return itemstack
+ end
end
- return itemstack
+ -- If we reach this, adding the object to the
+ -- environment failed
end
function core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
diff --git a/builtin/game/item_entity.lua b/builtin/game/item_entity.lua
index 6425a10aa..190473ceb 100644
--- a/builtin/game/item_entity.lua
+++ b/builtin/game/item_entity.lua
@@ -4,11 +4,14 @@ function core.spawn_item(pos, item)
-- Take item in any format
local stack = ItemStack(item)
local obj = core.add_entity(pos, "__builtin:item")
- obj:get_luaentity():set_item(stack:to_string())
+ -- Don't use obj if it couldn't be added to the map.
+ if obj then
+ obj:get_luaentity():set_item(stack:to_string())
+ end
return obj
end
--- If item_entity_ttl is not set, enity will have default life time
+-- If item_entity_ttl is not set, enity will have default life time
-- Setting it to -1 disables the feature
local time_to_live = tonumber(core.setting_get("item_entity_ttl"))
@@ -81,7 +84,7 @@ core.register_entity(":__builtin:item", {
if data and type(data) == "table" then
self.itemstring = data.itemstring
self.always_collect = data.always_collect
- if data.age then
+ if data.age then
self.age = data.age + dtime_s
else
self.age = dtime_s