summaryrefslogtreecommitdiff
path: root/mods/vzxv_itemstacks/loose.lua
blob: 58952f8d462b9b68b4493031958588490144ea3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
minetest.register_entity("vzxv_itemstacks:loose_itemstack",{
    initial_properties = {
		physical = true,
		pointable = false,
        visual = "wielditem",
		visual_size = {x = 0.4, y = 0.4},
	},
	on_activate = function(self,staticdata)
		local luaent = self
		staticdata = staticdata~="" and staticdata or "vzxv:apioform"
		luaent._stack = staticdata
		self.object:set_properties {
			wield_item=ItemStack(luaent._stack):get_name()
		}
	end,
	on_step = function(self,dt)
		local npos = vzxv.round_pos(self.object:get_pos())
		npos.y = npos.y - 1
		if minetest.get_node(npos).name ~= "air" then
			npos.y = npos.y + 1
			if minetest.get_node(npos).name == "air" then
				vzxv.drop(npos, ItemStack(self._stack))
				self.object:remove()
			end
		end
	end,
	get_staticdata = function(self)
		local luaent = self
		return luaent._stack
	end
})

vzxv.register_gravity("vzxv_itemstacks:loose_itemstack")