Skip to content

Commit b9ded9a

Browse files
committed
Add basic support for mcl_ games
1 parent 4e6cab0 commit b9ded9a

File tree

8 files changed

+85
-42
lines changed

8 files changed

+85
-42
lines changed

.luacheckrc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ ignore = {
77
max_line_length = 250
88

99
read_globals = {
10-
"default",
10+
"core",
1111
"ItemStack",
12-
"lucky_block",
1312
"minetest",
14-
"screwdriver",
1513
"vector",
14+
-- (Soft) sependencies
15+
"default",
16+
"lucky_block",
17+
"mcl_formspec",
18+
"mcl_sounds",
1619
}
1720

1821
globals = {"hopper"}

gamecompat.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
-- Default values
3+
hopper.formspec_bg = "bgcolor[#080808BB;true]" .. "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]"
4+
hopper.metal_sounds = nil
5+
hopper.node_fire_flame = nil
6+
7+
local formspec_list_template = "list[%s;%s;%f,%f;%f,%f;%s]"
8+
hopper.formspec_add_list = function(location, listname, x, y, w, h, offset)
9+
return formspec_list_template:format(location, listname, x, y, w, h, tostring(offset) or "")
10+
end
11+
12+
-- Minetest Game
13+
if core.get_modpath("default") then
14+
hopper.formspec_bg = "" -- Use formspec prepend
15+
hopper.metal_sounds = default.node_sound_metal_defaults()
16+
17+
if core.get_modpath("fire") then
18+
hopper.node_fire_flame = "fire:basic_flame"
19+
end
20+
end
21+
22+
-- VoxeLibre, Mineclonia
23+
if core.get_modpath("mcl_init") then
24+
hopper.formspec_bg = "" -- Use formspec prepend
25+
26+
if core.get_modpath("mcl_sounds") then
27+
hopper.metal_sounds = mcl_sounds.node_sound_metal_defaults()
28+
end
29+
if core.get_modpath("mcl_fire") then
30+
hopper.node_fire_flame = "mcl_fire:fire"
31+
end
32+
if core.get_modpath("mcl_formspec") then
33+
hopper.formspec_add_list = function(location, listname, x, y, w, h, offset)
34+
return mcl_formspec.get_itemslot_bg_v4(x, y, w, h) ..
35+
formspec_list_template:format(location, listname, x, y, w, h, tostring(offset) or "")
36+
end
37+
end
38+
end

init.lua

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ hopper.translator_escaped = function(...)
99
return minetest.formspec_escape(S(...))
1010
end
1111

12-
if minetest.get_modpath("default") then
13-
hopper.formspec_bg = default.gui_bg .. default.gui_bg_img .. default.gui_slots
14-
else
15-
hopper.formspec_bg = "bgcolor[#080808BB;true]" .. "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]"
16-
end
12+
dofile(MP.."/gamecompat.lua")
1713

1814
dofile(MP.."/config.lua")
1915
dofile(MP.."/api.lua")
@@ -47,20 +43,33 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
4743
end
4844
end)
4945

50-
46+
function hopper._formspec_add_player_lists(y)
47+
return hopper.formspec_add_list("current_player", "main", 0.4, y, 8, 1) ..
48+
hopper.formspec_add_list("current_player", "main", 0.4, y + 1.4, 8, 3, 8)
49+
end
5150

5251
-- add lucky blocks
5352
if minetest.get_modpath("lucky_block") then
5453
lucky_block:add_blocks({
5554
{"dro", {"hopper:hopper"}, 3},
56-
{"nod", "default:lava_source", 1},
5755
})
56+
if hopper.node_fire_flame then
57+
lucky_block:add_blocks({
58+
{"nod", hopper.node_fire_flame, 1},
59+
})
60+
end
5861
end
5962

6063
-- Utility function for inventory movement logs
6164
function hopper.log_inventory(...)
6265
minetest.log(hopper.config.inv_log_level, ...)
6366
end
6467

68+
-- Test whether the functions work
69+
core.register_on_mods_loaded(function()
70+
hopper.formspec_add_list("player:foo", "bar", 0, 1, 8, 4)
71+
hopper.formspec_add_list("player:foo", "bar", 0, 1, 8, 4, 4)
72+
hopper._formspec_add_player_lists(1)
73+
end)
6574

6675
minetest.log("action", "[hopper] Hopper mod loaded")

mod.conf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
name = hopper
2-
description = Adds hoppers to transport items between chests/furnace etc. Forum: https://forum.minetest.net/viewtopic.php?f=9&t=20058
3-
depends = default
4-
optional_depends = lucky_block, doc, protector, wine
2+
description = Adds hoppers to transport items between chests/furnace etc.
3+
optional_depends = lucky_block, doc, protector, wine, default, mcl_sounds

nodes/chute.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
local S = minetest.get_translator("hopper")
22
local FS = hopper.translator_escaped
33

4+
45
local function get_chute_formspec(pos)
56
local spos = hopper.get_string_pos(pos)
67
local formspec =
7-
"size[8,7]"
8+
"formspec_version[3]"
9+
.. "size[10.6,9]"
810
.. hopper.formspec_bg
9-
.. "label[3,-0.1;" .. FS("Hopper Chute") .."]"
10-
.. "list[nodemeta:" .. spos .. ";main;3,0.4;2,2;]"
11-
.. hopper.get_eject_button_texts(pos, 6, 0.8)
12-
.. "list[current_player;main;0,2.85;8,1;]"
13-
.. "list[current_player;main;0,4.08;8,3;8]"
11+
.. "label[4.15,0.35;" .. FS("Hopper Chute") .."]"
12+
.. hopper.formspec_add_list("nodemeta:" .. spos, "main", 4.15, 0.8, 2, 2)
13+
.. hopper.get_eject_button_texts(pos, 7.3, 1.4)
14+
.. hopper._formspec_add_player_lists(3.7)
1415
.. "listring[nodemeta:" .. spos .. ";main]"
1516
.. "listring[current_player;main]"
1617
return formspec

nodes/hoppers.lua

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ local S = minetest.get_translator("hopper")
22
local FS = hopper.translator_escaped
33
local ALPHA_CLIP = minetest.features.use_texture_alpha_string_modes and "clip" or true
44

5-
-- formspec
65
local function get_hopper_formspec(pos)
76
local spos = hopper.get_string_pos(pos)
87
local formspec =
9-
"size[8,9]"
8+
"formspec_version[3]"
9+
.. "size[10.6,11.3]"
1010
.. hopper.formspec_bg
11-
.. "label[3.5,-0.1;" .. FS("Hopper") .."]"
12-
.. "list[nodemeta:" .. spos .. ";main;2,0.4;4,4;]"
13-
.. hopper.get_eject_button_texts(pos, 6.5, 2)
14-
.. "list[current_player;main;0,4.85;8,1;]"
15-
.. "list[current_player;main;0,6.08;8,3;8]"
11+
.. "label[4.6,0.35;" .. FS("Hopper") .."]"
12+
.. hopper.formspec_add_list("nodemeta:" .. spos, "main", 2.9, 0.8, 4, 4)
13+
.. hopper.get_eject_button_texts(pos, 8.5, 2.6)
14+
.. hopper._formspec_add_player_lists(6)
1615
.. "listring[nodemeta:" .. spos .. ";main]"
1716
.. "listring[current_player;main]"
1817
return formspec

nodes/sorter.lua

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,30 @@ local function get_sorter_formspec(pos)
1818
local spos = hopper.get_string_pos(pos)
1919

2020
local filter_all = minetest.get_meta(pos):get_string("filter_all") == "true"
21-
local y_displace = 0
21+
local y_displace = 0.4
2222
local filter_texture, filter_button_tooltip, filter_body
2323
if filter_all then
2424
filter_body = ""
2525
filter_texture = "hopper_mode_off.png"
2626
filter_button_tooltip = FS("This sorter is currently set to try sending all items\nin the direction of the arrow. Click this button\nto enable an item-type-specific filter.")
2727
else
28-
filter_body = "label[3.7,0;"..FS("Filter").."]list[nodemeta:" .. spos .. ";filter;0,0.5;8,1;]"
28+
filter_body = "label[4.8,0.35;"..FS("Filter").."]"
29+
.. hopper.formspec_add_list("nodemeta:" .. spos, "filter", 0.4, 0.8, 8, 1)
2930
filter_texture = "hopper_mode_on.png"
3031
filter_button_tooltip = FS("This sorter is currently set to only send items listed\nin the filter list in the direction of the arrow.\nClick this button to set it to try sending all\nitems that way first.")
31-
y_displace = 1.6
32+
y_displace = 2.2
3233
end
3334

3435
local formspec =
35-
"size[8," .. 7 + y_displace .. "]"
36+
"formspec_version[3]"
37+
.. "size[10.6," .. (8.3 + y_displace) .. "]"
3638
.. hopper.formspec_bg
3739
.. filter_body
38-
.. "list[nodemeta:" .. spos .. ";main;3,".. tostring(0.3 + y_displace) .. ";2,2;]"
39-
.. ("image_button_exit[0,%g;1,1;%s;filter_all;]"):format(y_displace, filter_texture)
40+
.. hopper.formspec_add_list("nodemeta:" .. spos, "main", 4.15, 0.1 + y_displace, 2, 2)
41+
.. ("image_button_exit[0.4,%g;1,1;%s;filter_all;]"):format(y_displace, filter_texture)
4042
.. "tooltip[filter_all;" .. filter_button_tooltip.. "]"
41-
.. hopper.get_eject_button_texts(pos, 6, 0.8 + y_displace)
42-
.. "list[current_player;main;0,".. tostring(2.85 + y_displace) .. ";8,1;]"
43-
.. "list[current_player;main;0,".. tostring(4.08 + y_displace) .. ";8,3;8]"
43+
.. hopper.get_eject_button_texts(pos, 7.3, 0.7 + y_displace)
44+
.. hopper._formspec_add_player_lists(3 + y_displace)
4445
.. "listring[nodemeta:" .. spos .. ";main]"
4546
.. "listring[current_player;main]"
4647
return formspec

utility.lua

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ hopper.get_string_pos = function(pos)
4242
return pos.x .. "," .. pos.y .. "," ..pos.z
4343
end
4444

45-
-- Apparently node_sound_metal_defaults is a newer thing, I ran into games using an older version of the default mod without it.
46-
if default.node_sound_metal_defaults ~= nil then
47-
hopper.metal_sounds = default.node_sound_metal_defaults()
48-
else
49-
hopper.metal_sounds = default.node_sound_stone_defaults()
50-
end
51-
5245
-------------------------------------------------------------------------------------------
5346
-- Inventory transfer functions
5447

0 commit comments

Comments
 (0)