-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjuke.lua
More file actions
139 lines (130 loc) · 3.6 KB
/
juke.lua
File metadata and controls
139 lines (130 loc) · 3.6 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
jukebox_list={
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16"
}
jukeboxloop={}
minetest.register_node("jukeloopbox:juke", {
description = "Jukebox loop",
alpha=50,
drawtype = "mesh",
mesh= "juke.obj",
tiles = {"juke_on.png"},
paramtype = "light",
paramtype2 = "facedir",
automatic_rotate = true,
sunlight_propagates = true,
walkable = true,
pointable = true,
collision_box = {
type = "fixed",
fixed = { -0.4, -0.5, -0.2, 0.4,1.19,0.4}},
selection_box = {
type = "fixed",
fixed = { -0.4, -0.5, -0.2, 0.4,1.19,0.4}
--fixed = { -0.5, 0.35, -0.5, 0.5,1.5, 0.5},
},-- largdx h
groups = {mesecon=1,snappy=2,cracky=3,oddly_breakable_by_hand=3, not_in_creative_inventory=0},
sounds = default.node_sound_defaults(),
after_place_node = function(pos, placer, itemstack)
local meta = minetest.get_meta(pos)
local but="button[2,0.1;4,1;stop;STOP!] button[3,2.2;2,1.5;loop;Loop] button_exit[2,4.5;4,2;exit;EXIT]"
local x=-0
local y=1
meta:set_string("infotext", "Jukebox")
meta:set_int("loop", 0)
for i, list in pairs(jukebox_list) do
but=but.. "button[" .. x .. "," .. y ..";1,1.2;play"..i..";"..i.."]"
x=x+1
if x==8 then
x=0
y=y+2.5
end
end
meta:set_string("formspec",
"size[8.0,6.5]" .. but ..
"background[-0,-0;8,6.5;juke_bag.png]"
)
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
local id=minetest.pos_to_string(pos)
local sound={}
if fields.loop then
if meta:get_int("loop")==0 then
meta:set_int("loop",1)
minetest.chat_send_player(sender:get_player_name(), "Looping: on")
else
meta:set_int("loop",0)
minetest.chat_send_player(sender:get_player_name(), "Looping: off")
if jukeboxloop[id] then
minetest.sound_stop(jukeboxloop[id])
jukeboxloop[id]=nil
end
end
return true
end
if fields.stop then
if jukeboxloop[id] then
minetest.sound_stop(jukeboxloop[id])
jukeboxloop[id]=nil
end
return true
end
for i, list in pairs(jukebox_list) do
if fields["play" ..i] then
if jukeboxloop[id] then
minetest.sound_stop(jukeboxloop[id])
jukeboxloop[id]=nil
end
meta:set_int("last",i)
if meta:get_int("loop")==0 then
jukeboxloop[id]=minetest.sound_play(jukebox_list[i], {pos=pos, gain = 1.0, max_hear_distance = 15,})
else
jukeboxloop[id]=minetest.sound_play(jukebox_list[i], {pos=pos, gain = 1.0, max_hear_distance = 15,loop=true})
end
return true
end
end
end,
mesecons = {effector = {
action_on = function(pos, node)
local meta = minetest.get_meta(pos)
local last=meta:get_int("last")
local id=minetest.pos_to_string(pos)
meta:set_int("playing",1)
if jukeboxloop[id] then
minetest.sound_stop(jukeboxloop[id])
jukeboxloop[id]=nil
end
if meta:get_int("loop")==0 then
jukeboxloop[id]=minetest.sound_play(jukebox_list[last], {pos=pos, gain = 1.0, max_hear_distance = 15,})
else
jukeboxloop[id]=minetest.sound_play(jukebox_list[last], {pos=pos, gain = 1.0, max_hear_distance = 15,loop=true})
end
end
,
action_off = function(pos, node)
local meta = minetest.get_meta(pos)
local id=minetest.pos_to_string(pos)
if meta:get_int("playing")==1 and jukeboxloop[id] then
minetest.sound_stop(jukeboxloop[id])
meta:set_int("playing",0)
return true
end
end
}},
})