Skip to content

Commit 7ad8885

Browse files
committed
Add compatibility code
1 parent ef5a3d7 commit 7ad8885

File tree

2 files changed

+64
-43
lines changed

2 files changed

+64
-43
lines changed

mods/default/init.lua

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@ LIGHT_MAX = 14
1111
-- Definitions made by this mod that other mods can use too
1212
default = {}
1313

14+
-- Compatibility code for minetest_game
15+
default.gui_bg = "bgcolor[#111C;]"
16+
default.gui_bg_img = ""
17+
-- slot BG ; slot hover ; slot border ; tooltip BG ; tooltip font color]
18+
default.gui_slots = "listcolors[#555;#999;#444;#444;#FFF]"
19+
20+
function default.get_hotbar_bg(x,y)
21+
return ""
22+
end
23+
24+
default.gui_suvival_form = "size[8,8.5]"..
25+
default.gui_bg..
26+
default.gui_bg_img..
27+
default.gui_slots..
28+
"list[current_player;main;0,4.25;8,1;]"..
29+
"list[current_player;main;0,5.5;8,3;8]"..
30+
"list[current_player;craft;1.5,0.5;3,3;]"..
31+
"list[current_player;craftpreview;5.5,1.5;1,1;]"
32+
1433
-- Load files
1534
local modpath = minetest.get_modpath("default")
1635
dofile(modpath.."/functions.lua")
@@ -46,4 +65,8 @@ default.flags = {
4665
["t_jungle"] = true,
4766
["t_papyrus"] = true,
4867
["t_cactus"] = true,
49-
}
68+
}
69+
70+
minetest.register_on_joinplayer(function(player)
71+
player:set_inventory_formspec(default.gui_suvival_form)
72+
end)

mods/default/nodes.lua

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -600,17 +600,21 @@ minetest.register_node("default:sign_wall", {
600600
})
601601

602602
default.chest_formspec =
603-
"size[8,9]"..
604-
"list[current_name;main;0,0;8,4;]"..
605-
"list[current_player;main;0,5;8,4;]"
606-
607-
function default.get_locked_chest_formspec(pos)
608-
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
609-
local formspec =
610603
"size[8,9]"..
611-
"list[nodemeta:".. spos .. ";main;0,0;8,4;]"..
604+
default.gui_bg..
605+
default.gui_bg_img..
606+
default.gui_slots..
607+
"list[current_name;main;0,0;8,4;]"..
612608
"list[current_player;main;0,5;8,4;]"
613-
return formspec
609+
610+
function default.get_locked_chest_formspec(pos)
611+
local spos = pos.x ..",".. pos.y ..",".. pos.z
612+
return "size[8,9]"..
613+
default.gui_bg..
614+
default.gui_bg_img..
615+
default.gui_slots..
616+
"list[nodemeta:".. spos ..";main;0,0;8,4;]"..
617+
"list[current_player;main;0,5;8,4;]"
614618
end
615619

616620

@@ -705,25 +709,25 @@ minetest.register_node("default:chest_locked", {
705709
end,
706710
})
707711

708-
function default.get_furnace_active_formspec(pos, percent)
709-
local formspec =
712+
default.furnace_basic_formspec =
710713
"size[8,9]"..
711-
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
712-
(100-percent)..":default_furnace_fire_fg.png]"..
714+
default.gui_bg..
715+
default.gui_bg_img..
716+
default.gui_slots..
713717
"list[current_name;fuel;2,3;1,1;]"..
714718
"list[current_name;src;2,1;1,1;]"..
715719
"list[current_name;dst;5,1;2,2;]"..
716720
"list[current_player;main;0,5;8,4;]"
717-
return formspec
721+
722+
function default.get_furnace_active_formspec(pos, percent)
723+
return default.furnace_basic_formspec..
724+
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
725+
(100-percent)..":default_furnace_fire_fg.png]"
718726
end
719727

720728
default.furnace_inactive_formspec =
721-
"size[8,9]"..
722-
"image[2,2;1,1;default_furnace_fire_bg.png]"..
723-
"list[current_name;fuel;2,3;1,1;]"..
724-
"list[current_name;src;2,1;1,1;]"..
725-
"list[current_name;dst;5,1;2,2;]"..
726-
"list[current_player;main;0,5;8,4;]"
729+
default.furnace_basic_formspec..
730+
"image[2,2;1,1;default_furnace_fire_bg.png]"
727731

728732
minetest.register_node("default:furnace", {
729733
description = "Furnace",
@@ -759,14 +763,13 @@ minetest.register_node("default:furnace", {
759763
local meta = minetest.get_meta(pos)
760764
local inv = meta:get_inventory()
761765
if listname == "fuel" then
762-
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
766+
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
763767
if inv:is_empty("src") then
764-
meta:set_string("infotext","Furnace is empty")
768+
meta:set_string("infotext", "Furnace is empty")
765769
end
766770
return stack:get_count()
767-
else
768-
return 0
769771
end
772+
return 0
770773
elseif listname == "src" then
771774
return stack:get_count()
772775
elseif listname == "dst" then
@@ -781,9 +784,9 @@ minetest.register_node("default:furnace", {
781784
local inv = meta:get_inventory()
782785
local stack = inv:get_stack(from_list, from_index)
783786
if to_list == "fuel" then
784-
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
787+
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
785788
if inv:is_empty("src") then
786-
meta:set_string("infotext","Furnace is empty")
789+
meta:set_string("infotext", "Furnace is empty")
787790
end
788791
return count
789792
else
@@ -854,9 +857,9 @@ minetest.register_node("default:furnace_active", {
854857
local meta = minetest.get_meta(pos)
855858
local inv = meta:get_inventory()
856859
if listname == "fuel" then
857-
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
860+
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
858861
if inv:is_empty("src") then
859-
meta:set_string("infotext","Furnace is empty")
862+
meta:set_string("infotext", "Furnace is empty")
860863
end
861864
return stack:get_count()
862865
else
@@ -876,9 +879,9 @@ minetest.register_node("default:furnace_active", {
876879
local inv = meta:get_inventory()
877880
local stack = inv:get_stack(from_list, from_index)
878881
if to_list == "fuel" then
879-
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
882+
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
880883
if inv:is_empty("src") then
881-
meta:set_string("infotext","Furnace is empty")
884+
meta:set_string("infotext", "Furnace is empty")
882885
end
883886
return count
884887
else
@@ -908,7 +911,7 @@ local function swap_node(pos,name)
908911
end
909912

910913
minetest.register_abm({
911-
nodenames = {"default:furnace","default:furnace_active"},
914+
nodenames = {"default:furnace", "default:furnace_active"},
912915
interval = 2,
913916
chance = 1,
914917
action = function(pos, node, active_object_count, active_object_count_wider)
@@ -941,14 +944,9 @@ minetest.register_abm({
941944
meta:set_float("fuel_time", meta:get_float("fuel_time") + 2)
942945
meta:set_float("src_time", meta:get_float("src_time") + 2)
943946
if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
944-
-- check if there's room for output in "dst" list
945-
if inv:room_for_item("dst",cooked.item) then
946-
-- Put result in "dst" list
947+
if inv:room_for_item("dst", cooked.item) then
947948
inv:add_item("dst", cooked.item)
948-
-- take stuff from "src" list
949949
inv:set_stack("src", 1, aftercooked.items[1])
950-
else
951-
--print("Could not insert '"..cooked.item:to_string().."'")
952950
end
953951
meta:set_string("src_time", 0)
954952
end
@@ -957,9 +955,9 @@ minetest.register_abm({
957955
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
958956
local percent = math.floor(meta:get_float("fuel_time") /
959957
meta:get_float("fuel_totaltime") * 100)
960-
meta:set_string("infotext","Furnace active: "..percent.."%")
958+
meta:set_string("infotext", "Furnace active: "..percent.."%")
961959
swap_node(pos,"default:furnace_active")
962-
meta:set_string("formspec",default.get_furnace_active_formspec(pos, percent))
960+
meta:set_string("formspec", default.get_furnace_active_formspec(pos, percent))
963961
return
964962
end
965963

@@ -977,15 +975,15 @@ minetest.register_abm({
977975
end
978976

979977
if not fuel or fuel.time <= 0 then
980-
meta:set_string("infotext","Furnace out of fuel")
981-
swap_node(pos,"default:furnace")
978+
meta:set_string("infotext", "Furnace out of fuel")
979+
swap_node(pos, "default:furnace")
982980
meta:set_string("formspec", default.furnace_inactive_formspec)
983981
return
984982
end
985983

986984
if cooked.item:is_empty() then
987985
if was_active then
988-
meta:set_string("infotext","Furnace is empty")
986+
meta:set_string("infotext", "Furnace is empty")
989987
swap_node(pos,"default:furnace")
990988
meta:set_string("formspec", default.furnace_inactive_formspec)
991989
end

0 commit comments

Comments
 (0)