forked from ChimneySwift/fancy_vend
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdisplay_item.lua
More file actions
71 lines (67 loc) · 1.87 KB
/
display_item.lua
File metadata and controls
71 lines (67 loc) · 1.87 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local tmp = {}
core.register_entity("fancy_vend:display_item", {
hp_max = 1,
visual = "wielditem",
visual_size = {x = 0.33, y = 0.33},
collisionbox = {0, 0, 0, 0, 0, 0},
physical = false,
textures = {"air"},
on_activate = function(self, staticdata)
if tmp.nodename ~= nil and tmp.texture ~= nil then
self.nodename = tmp.nodename
tmp.nodename = nil
self.texture = tmp.texture
tmp.texture = nil
else
if staticdata ~= nil and staticdata ~= "" then
local data = staticdata:split(";")
if data and data[1] and data[2] then
self.nodename = data[1]
self.texture = data[2]
end
end
end
if self.texture ~= nil then
self.object:set_properties({textures = {self.texture}})
end
self.object:set_properties({automatic_rotate = fancy_vend.autorotate_speed})
end,
get_staticdata = function(self)
if self.nodename ~= nil and self.texture ~= nil then
return self.nodename..";"..self.texture
end
return ""
end,
})
function fancy_vend.remove_item(pos)
local objs = core.get_objects_inside_radius(pos, .5)
if objs then
for _, obj in ipairs(objs) do
if obj and obj:get_luaentity() and obj:get_luaentity().name == "fancy_vend:display_item" then
obj:remove()
end
end
end
end
function fancy_vend.update_item(pos, node)
pos.y = pos.y + 1
fancy_vend.remove_item(pos)
if core.get_node(pos).name ~= "fancy_vend:display_node" then
core.log("warning",
"[fancy_vend]: Placing display item inside "..
core.get_node(pos).name.." at "..core.pos_to_string(pos)..
" is not permitted, aborting"
)
pos.y = pos.y - 1
return
end
pos.y = pos.y - 1
local meta = core.get_meta(pos)
if meta:get_string("item") ~= "" then
pos.y = pos.y + (12 / 16 + 0.11)
tmp.nodename = node.name
tmp.texture = ItemStack(meta:get_string("item")):get_name()
core.add_entity(pos, "fancy_vend:display_item")
pos.y = pos.y - (12 / 16 + 0.11)
end
end