Add the player name to dropped items
authorRobert Zenz <Robert.Zenz@bonsaimind.org>
Thu, 5 Nov 2015 18:56:19 +0000 (19:56 +0100)
committerest31 <MTest31@outlook.com>
Wed, 11 Nov 2015 23:47:11 +0000 (00:47 +0100)
The player name is now added in the field "dropped_by" on the created
entity.

builtin/game/item.lua
builtin/game/item_entity.lua

index df5bb070de9977e1adf0b2ba1befdd0a5b99b617..44ec35cc9d8f394b109e55722b1e5cbee1943e3a 100644 (file)
@@ -348,7 +348,7 @@ function core.item_place(itemstack, placer, pointed_thing, param2)
 end
 
 function core.item_drop(itemstack, dropper, pos)
-       if dropper.is_player then
+       if dropper and dropper:is_player() then
                local v = dropper:get_look_dir()
                local p = {x=pos.x, y=pos.y+1.2, z=pos.z}
                local cs = itemstack:get_count()
@@ -362,6 +362,7 @@ function core.item_drop(itemstack, dropper, pos)
                        v.y = v.y*2 + 2
                        v.z = v.z*2
                        obj:setvelocity(v)
+                       obj:get_luaentity().dropped_by = dropper:get_player_name()
                        return itemstack
                end
 
index a8d7a186361759d95c90ffb42b8ef64956d284fa..be158c119b24ccdf5df6e27fc4fefaf412fb7e5a 100644 (file)
@@ -74,7 +74,8 @@ core.register_entity(":__builtin:item", {
                return core.serialize({
                        itemstring = self.itemstring,
                        always_collect = self.always_collect,
-                       age = self.age
+                       age = self.age,
+                       dropped_by = self.dropped_by
                })
        end,
 
@@ -89,6 +90,7 @@ core.register_entity(":__builtin:item", {
                                else
                                        self.age = dtime_s
                                end
+                               self.dropped_by = data.dropped_by
                        end
                else
                        self.itemstring = staticdata