diff options
author | ShadowNinja <shadowninja@minetest.net> | 2014-04-27 17:55:49 -0400 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2014-05-07 17:14:23 -0400 |
commit | 1cd512913e4d4ad1fb43d4b6e3d7971bb6c67528 (patch) | |
tree | 8c1e2c708f567656684e89faee4f7c8e6c5ec673 /builtin/item_entity.lua | |
parent | fef2729fd0945601e6772780514ee55fec35b068 (diff) | |
download | minetest-1cd512913e4d4ad1fb43d4b6e3d7971bb6c67528.tar.gz minetest-1cd512913e4d4ad1fb43d4b6e3d7971bb6c67528.tar.bz2 minetest-1cd512913e4d4ad1fb43d4b6e3d7971bb6c67528.zip |
Organize builtin into subdirectories
Diffstat (limited to 'builtin/item_entity.lua')
-rw-r--r-- | builtin/item_entity.lua | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/builtin/item_entity.lua b/builtin/item_entity.lua deleted file mode 100644 index 0dcc2dc2d..000000000 --- a/builtin/item_entity.lua +++ /dev/null @@ -1,123 +0,0 @@ --- Minetest: builtin/item_entity.lua - -function minetest.spawn_item(pos, item) - -- Take item in any format - local stack = ItemStack(item) - local obj = minetest.add_entity(pos, "__builtin:item") - obj:get_luaentity():set_item(stack:to_string()) - return obj -end - -minetest.register_entity("__builtin:item", { - initial_properties = { - hp_max = 1, - physical = true, - collide_with_objects = false, - collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17}, - visual = "sprite", - visual_size = {x=0.5, y=0.5}, - textures = {""}, - spritediv = {x=1, y=1}, - initial_sprite_basepos = {x=0, y=0}, - is_visible = false, - }, - - itemstring = '', - physical_state = true, - - set_item = function(self, itemstring) - self.itemstring = itemstring - local stack = ItemStack(itemstring) - local itemtable = stack:to_table() - local itemname = nil - if itemtable then - itemname = stack:to_table().name - end - local item_texture = nil - local item_type = "" - if minetest.registered_items[itemname] then - item_texture = minetest.registered_items[itemname].inventory_image - item_type = minetest.registered_items[itemname].type - end - prop = { - is_visible = true, - visual = "sprite", - textures = {"unknown_item.png"} - } - if item_texture and item_texture ~= "" then - prop.visual = "sprite" - prop.textures = {item_texture} - prop.visual_size = {x=0.50, y=0.50} - else - prop.visual = "wielditem" - prop.textures = {itemname} - prop.visual_size = {x=0.20, y=0.20} - prop.automatic_rotate = math.pi * 0.25 - end - self.object:set_properties(prop) - end, - - get_staticdata = function(self) - --return self.itemstring - return minetest.serialize({ - itemstring = self.itemstring, - always_collect = self.always_collect, - }) - end, - - on_activate = function(self, staticdata) - if string.sub(staticdata, 1, string.len("return")) == "return" then - local data = minetest.deserialize(staticdata) - if data and type(data) == "table" then - self.itemstring = data.itemstring - self.always_collect = data.always_collect - end - else - self.itemstring = staticdata - end - self.object:set_armor_groups({immortal=1}) - self.object:setvelocity({x=0, y=2, z=0}) - self.object:setacceleration({x=0, y=-10, z=0}) - self:set_item(self.itemstring) - end, - - on_step = function(self, dtime) - local p = self.object:getpos() - p.y = p.y - 0.3 - local nn = minetest.get_node(p).name - -- If node is not registered or node is walkably solid and resting on nodebox - local v = self.object:getvelocity() - if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable and v.y == 0 then - if self.physical_state then - self.object:setvelocity({x=0,y=0,z=0}) - self.object:setacceleration({x=0, y=0, z=0}) - self.physical_state = false - self.object:set_properties({ - physical = false - }) - end - else - if not self.physical_state then - self.object:setvelocity({x=0,y=0,z=0}) - self.object:setacceleration({x=0, y=-10, z=0}) - self.physical_state = true - self.object:set_properties({ - physical = true - }) - end - end - end, - - on_punch = function(self, hitter) - if self.itemstring ~= '' then - local left = hitter:get_inventory():add_item("main", self.itemstring) - if not left:is_empty() then - self.itemstring = left:to_string() - return - end - end - self.itemstring = '' - self.object:remove() - end, -}) - |