From 4669071b52b167f33334067b1ccd7fcc7c575583 Mon Sep 17 00:00:00 2001 From: hasanalsamra <hasanalsamra200@gmail.com> Date: Mon, 12 Sep 2016 19:33:59 +0300 Subject: [PATCH] Version 0.4 update --- Changelog.txt | 4 + README.md | 4 +- VERSION.txt | 2 +- chest.functions.lua | 2 +- init.lua | 10 +- mchud/mchud.api.lua | 245 +++++++++++++++++++++ mchud/mchud.builtin.lua | 53 +++++ mchud/mchud.functions.lua | 23 ++ mchud/mchud.init.lua | 8 + nodes.lua | 2 - replaced_nodes.lua | 1 + textures/mcnodes_hud_heart.png | Bin 0 -> 162 bytes textures/mcnodes_hud_heart_fg.png | Bin 0 -> 174 bytes textures/mcnodes_mchud_air_fg.png | Bin 0 -> 341 bytes textures/mcnodes_mchud_hotbar.png | Bin 0 -> 1142 bytes textures/mcnodes_mchud_hotbar_selected.png | Bin 0 -> 1649 bytes 16 files changed, 346 insertions(+), 8 deletions(-) create mode 100644 mchud/mchud.api.lua create mode 100644 mchud/mchud.builtin.lua create mode 100644 mchud/mchud.functions.lua create mode 100644 mchud/mchud.init.lua create mode 100644 textures/mcnodes_hud_heart.png create mode 100644 textures/mcnodes_hud_heart_fg.png create mode 100644 textures/mcnodes_mchud_air_fg.png create mode 100644 textures/mcnodes_mchud_hotbar.png create mode 100644 textures/mcnodes_mchud_hotbar_selected.png diff --git a/Changelog.txt b/Changelog.txt index 88c89e9..d9e368c 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,7 @@ +Version 0.4: + Fixed new large chest bug. + Added Mchud submod and can be disable by changing the McHud variable to 0 which is located in the init.lua file (this submod is just in testing so it is not finished). + Version 0.3-beta: Improve some textures. Fix large chest issue. diff --git a/README.md b/README.md index 2ceb915..951f64f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Mcnodes 0.3-beta +# Mcnodes 0.4 -- This mod adds a 3d chest, if you don't like it edit nodes.lua file and set the ChangeChest variable to 0 -- The large chest still have some problems will be solved in the next release. @@ -7,8 +7,6 @@ -- Auto stairs can be disabled by changing AutoStairs variable to 0 at init.lua file --- Will add a 3d mesh to locked and protected chest in the future. - # License See LICENSE.txt file. diff --git a/VERSION.txt b/VERSION.txt index b15a71a..bd73f47 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.3-beta +0.4 diff --git a/chest.functions.lua b/chest.functions.lua index c69ed43..30bc3d8 100644 --- a/chest.functions.lua +++ b/chest.functions.lua @@ -8,7 +8,7 @@ function PlaceChest(NodeOn, Pos, OldNodePos) end if NodeOn == 'ZP' then - if getNodeYaxis(Pos) == '270' and getNodeYaxis(OldNodePos) == '270' or getNodeYaxis(Pos) == '270' and getNodeYaxis(OldNodePos) == '90' or getNodeYaxis(Pos) == '90' and getNodeYaxis(OldNodePos) == '270' then + if getNodeYaxis(Pos) == '90' and getNodeYaxis(OldNodePos) == '90' or getNodeYaxis(Pos) == '270' and getNodeYaxis(OldNodePos) == '90' or getNodeYaxis(Pos) == '90' and getNodeYaxis(OldNodePos) == '270' then True = false else True = true diff --git a/init.lua b/init.lua index b22604d..aa6de48 100644 --- a/init.lua +++ b/init.lua @@ -1,11 +1,15 @@ mcnodes = {} -version = '0.3-beta' +version = '0.4' + +ChangeChest = '1' LargeChest = '1' AutoStairs = '1' +McHud = '1' + dofile(minetest.get_modpath("mcnodes").."/functions.general.lua") dofile(minetest.get_modpath("mcnodes").."/nodes.lua") @@ -38,3 +42,7 @@ if AutoStairs == '1' then dofile(minetest.get_modpath("mcnodes").."/auto_stairs_functions.lua") dofile(minetest.get_modpath("mcnodes").."/auto_stairs.lua") end + +if McHud == '1' then + dofile(minetest.get_modpath("mcnodes").."/mchud/mchud.init.lua") +end diff --git a/mchud/mchud.api.lua b/mchud/mchud.api.lua new file mode 100644 index 0000000..c8ea6ab --- /dev/null +++ b/mchud/mchud.api.lua @@ -0,0 +1,245 @@ +-- global values +mchud.registered_items = {} +mchud.damage_events = {} +mchud.breath_events = {} + +-- keep id handling internal +local hud_id = {} -- hud item ids +local sb_bg = {} -- statbar background ids + +-- localize often used table +local items = mchud.registered_items + +local function throw_error(msg) + minetest.log("error", "Better HUD[error]: " .. msg) +end + + +-- +-- API +-- + +function mchud.register(name, def) + if not name or not def then + throw_error("not enough parameters given") + return false + end + + --TODO: allow other elements + if def.hud_elem_type ~= "statbar" then + throw_error("The given HUD element is no statbar") + return false + end + if items[name] ~= nil then + throw_error("A statbar with that name already exists") + return false + end + + -- actually register + -- add background first since draworder is based on id :\ + if def.hud_elem_type == "statbar" and def.background ~= nil then + sb_bg[name] = table.copy(def) + sb_bg[name].text = def.background + if not def.autohide_bg and def.max then + sb_bg[name].number = def.max + end + end + -- add item itself + items[name] = def + + -- register events + if def.events then + for _,v in pairs(def.events) do + if v and v.type and v.func then + if v.type == "damage" then + table.insert(mchud.damage_events, v) + end + + if v.type == "breath" then + table.insert(mchud.breath_events, v) + end + end + end + end + + -- no error so far, return sucess + return true +end + +-- swaps stabar positions +function mchud.swap_statbar(player, item1, item2) + if not player or not item1 or not item2 then + throw_error("Not enough parameters given to swap statbars") + return false + end + + local def1 = items[item1] or nil + local def2 = items[item2] or nil + + if not def1 or not def2 then + throw_error("Can't swap statbars. Given statbars are not correct") + return false + end + + local pos_swap = false + local p_name = player:get_player_name() + local elem1 = hud_id[p_name.."_"..item1] + local elem2 = hud_id[p_name.."_"..item2] + + if not elem1 or not elem2 or not elem1.id or not elem2.id then + return false + end + + player:hud_change(elem2.id, "offset", def1.offset) + player:hud_change(elem1.id, "offset", def2.offset) + + if def1.position.x ~= def2.position.x or def1.position.y ~= def2.position.y then + player:hud_change(elem2.id, "position", def1.position) + player:hud_change(elem1.id, "position", def2.position) + pos_swap = true + end + + -- do the items have backgrounds? if so, swap them aswell + local bg1 = hud_id[p_name.."_"..item1.."_bg"] or nil + local bg2 = hud_id[p_name.."_"..item2.."_bg"] or nil + if bg1 ~= nil and bg1.id then + player:hud_change(bg1.id, "offset", def2.offset) + if pos_swap == true then + player:hud_change(bg1.id, "position", def2.position) + end + end + if bg2 ~= nil and bg2.id then + player:hud_change(bg2.id, "offset", def1.offset) + if pos_swap == true then + player:hud_change(bg2.id, "position", def1.position) + end + end + + return true + +end + +function mchud.change_item(player, name, def) + if not player or not player:is_player() or not name or not def then + throw_error("Not enough parameters given to change HUD item") + return false + end + local i_name = player:get_player_name().."_"..name + local elem = hud_id[i_name] + if not elem then + throw_error("Given HUD element " .. dump(name) .. " does not exist".." hääää") + return false + end + + -- Only update if values supported and value actually changed + -- update supported values (currently number and text only) + if def.number and elem.number then + if def.number ~= elem.number then + if elem.max and def.number > elem.max and not def.max then + def.number = elem.max + end + if def.max then + elem.max = def.max + end + player:hud_change(elem.id, "number", def.number) + elem.number = def.number + -- hide background when set + local bg = hud_id[i_name.."_bg"] + if elem.autohide_bg then + if def.number < 1 then + player:hud_change(bg.id, "number", 0) + else + local num = bg.number + if bg.max then + num = bg.max + end + player:hud_change(bg.id, "number", num) + end + else + if bg and bg.max and bg.max < 1 and def.max and def.max > bg.max then + player:hud_change(bg.id, "number", def.max) + bg.max = def.max + bg.number = def.max + end + end + end + end + if def.text and elem.text then + if def.text ~= elem.text then + player:hud_change(elem.id, "text", def.text) + elem.text = def.text + end + end + + if def.offset and elem.offset then + if def.item_name and def.offset == "item" then + -- for legacy reasons + if def.item_name then + mchud.swap_statbar(player, name, def.item_name) + end + else + player:hud_change(elem.id, "offset", def.offset) + elem.offset = def.offset + end + end + + return true +end + +function mchud.remove_item(player, name) + if not player or not name then + throw_error("Not enough parameters given") + return false + end + local i_name = player:get_player_name().."_"..name + if hud_id[i_name] == nil then + throw_error("Given HUD element " .. dump(name) .. " does not exist") + return false + end + player:hud_remove(hud_id[i_name].id) + hud_id[i_name] = nil + + return true +end + + +-- +-- Add registered HUD items to joining players +-- + +-- Following code is placed here to keep HUD ids internal +local function add_hud_item(player, name, def) + if not player or not name or not def then + throw_error("not enough parameters given") + return false + end + local i_name = player:get_player_name().."_"..name + hud_id[i_name] = def + hud_id[i_name].id = player:hud_add(def) +end + +minetest.register_on_joinplayer(function(player) + + -- first: hide the default statbars + local hud_flags = player:hud_get_flags() + hud_flags.healthbar = false + hud_flags.breathbar = false + player:hud_set_flags(hud_flags) + + -- now add the backgrounds for statbars + for _,item in pairs(sb_bg) do + add_hud_item(player, _.."_bg", item) + end + -- and finally the actual HUD items + for _,item in pairs(items) do + add_hud_item(player, _, item) + end + + -- fancy hotbar (only when no crafting mod present) + if minetest.get_modpath("crafting") == nil then + minetest.after(0.5, function() + player:hud_set_hotbar_image("mcnodes_mchud_hotbar.png") + player:hud_set_hotbar_selected_image("mcnodes_mchud_hotbar_selected.png") + end) + end +end) diff --git a/mchud/mchud.builtin.lua b/mchud/mchud.builtin.lua new file mode 100644 index 0000000..6ebe4cd --- /dev/null +++ b/mchud/mchud.builtin.lua @@ -0,0 +1,53 @@ +HUD_SB_SIZE = {x = 24, y = 24} + +HUD_AIR_POS = {x = 0.5, y = 1} +HUD_AIR_OFFSET = {x = 15, y = -87} + +HUD_HEALTH_POS = {x = 0.5,y = 1} +HUD_HEALTH_OFFSET = {x = -262, y = -87} + +local damage = minetest.setting_getbool("enable_damage") + +if damage then + mchud.register("health", { + hud_elem_type = "statbar", + position = HUD_HEALTH_POS, + size = HUD_SB_SIZE, + text = "mcnodes_hud_heart.png", + number = 20, + alignment = {x = -1, y = -1}, + offset = HUD_HEALTH_OFFSET, + background = "mcnodes_hud_heart_fg.png", + events = { + { + type = "damage", + func = function(player) + mchud.change_item(player, "health", {number = player:get_hp()}) + end + } + }, + }) + + mchud.register("air", { + hud_elem_type = "statbar", + position = HUD_AIR_POS, + size = HUD_SB_SIZE, + text = "mcnodes_mchud_air_fg.png", + number = 0, + alignment = {x = -1, y = -1}, + offset = HUD_AIR_OFFSET, + background = nil, + events = { + { + type = "breath", + func = function(player) + local air = player:get_breath() + if air > 10 then + air = 0 + end + mchud.change_item(player, "air", {number = air * 2}) + end + } + }, + }) +end diff --git a/mchud/mchud.functions.lua b/mchud/mchud.functions.lua new file mode 100644 index 0000000..5ad57b4 --- /dev/null +++ b/mchud/mchud.functions.lua @@ -0,0 +1,23 @@ +damage = minetest.setting_getbool("enable_damage") + +function PEvent(name, event) + minetest.after(0, function() + if event == "health_changed" then + for _,v in pairs(mchud.damage_events) do + if v.func then + v.func(name) + end + end + end + + if event == "breath_changed" then + for _,v in pairs(mchud.breath_events) do + if v.func then + v.func(name) + end + end + end + end) +end + +minetest.register_playerevent(PEvent) diff --git a/mchud/mchud.init.lua b/mchud/mchud.init.lua new file mode 100644 index 0000000..daa8f2e --- /dev/null +++ b/mchud/mchud.init.lua @@ -0,0 +1,8 @@ +-- Most of this hud sub mod structures and contents taken from blockmen's hud mod +-- https://github.com/BlockMen/hud_hunger/tree/master/hud + +mchud = {} + +dofile(minetest.get_modpath("mcnodes").."/mchud/mchud.api.lua") +dofile(minetest.get_modpath("mcnodes").."/mchud/mchud.functions.lua") +dofile(minetest.get_modpath("mcnodes").."/mchud/mchud.builtin.lua") diff --git a/nodes.lua b/nodes.lua index 90f4c7a..bdec17d 100644 --- a/nodes.lua +++ b/nodes.lua @@ -1,5 +1,3 @@ -ChangeChest = '1' - minetest.register_node("mcnodes:quartz_block", { description = "Quartz block", tiles = {"mcnodes_quartz_block_top.png", "mcnodes_quartz_block_bottom.png", "mcnodes_quartz_block.png", "mcnodes_quartz_block.png", "mcnodes_quartz_block.png", "mcnodes_quartz_block.png"}, diff --git a/replaced_nodes.lua b/replaced_nodes.lua index de0e3dd..cd2c84c 100644 --- a/replaced_nodes.lua +++ b/replaced_nodes.lua @@ -1,3 +1,4 @@ +--Normal chest if ChangeChest == '1' then local chest_formspec = "size[8,9]" .. diff --git a/textures/mcnodes_hud_heart.png b/textures/mcnodes_hud_heart.png new file mode 100644 index 0000000000000000000000000000000000000000..32f7d7c22cb1e9dcb2f9726fb5483fe468ec00fa GIT binary patch literal 162 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4>1|%O$WD@{!3Opi<85sEXgD|57Yp@DXkiEpy z*OmPNhn$GA6w{&jA3z~TPZ!4!iOXwy4{|an@G$FJ@2YL@l-CaXqA0;3Qsnz!_nle1 zYzAj`GYOt6Fm3qsd7Hw7wA+kVGy-SFI^;^4fAEyO;iT|MjA=#@&@cv1S3j3^P6<r_ Ds;n(e literal 0 HcmV?d00001 diff --git a/textures/mcnodes_hud_heart_fg.png b/textures/mcnodes_hud_heart_fg.png new file mode 100644 index 0000000000000000000000000000000000000000..a52dc1c1a87269073e0031a8d24cc759c15ed5b6 GIT binary patch literal 174 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4>1|%O$WD@{!3Opi<85sEXgD|57Yp@DXkiEpy z*OmPNhn$GA;8cOO0-%tur;B5V#O0|IE^;1l;BksSb@uVUVhjHVzb-o!?G@8%>EKxO zLHP5oslwYeI2mq-@VSH>=G$huYQoI7`;VonCHJ_?tllWKjaPMRT70m{oHk{Zf-krJ Qf?USn>FVdQ&MBb@06qRUDF6Tf literal 0 HcmV?d00001 diff --git a/textures/mcnodes_mchud_air_fg.png b/textures/mcnodes_mchud_air_fg.png new file mode 100644 index 0000000000000000000000000000000000000000..720d3a9cb339fb8b3a8e56c07836011c2c52137d GIT binary patch literal 341 zcmV-b0jmCqP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00009a7bBm000XT z000XT0n*)m`~Uy|2XskIMF-#r9}p83YlrHY0002=Nkl<ZILpnFJ#NB45QX1Fic*oD zd*lE}X*dAK;0Wd-SX{ueJBpP7X@w{#+#xG<s+GK;C`O7>`Oz4(;005lD6iX@`Q~T! zfPbseB(YI$t0=eCXp-2w!61x_)RMC;sY|{AfHI^qWDv$hE4=t3^`2v0a-jF@xOra_ zaUZiS`TT+yL<&LL>&WNj5M{`IS5DlMd$R}tB7-3F!ES9M80EIoC5O7?d)q%nxvd%- z)cOFB`5=<?#ZL`3>*enE2lL*meBXkVAvf#g&byj2%_*#Pt>)~6)ikk}1ybt>ucj@g n3c|QJ8poY_mysS~<v-T}X=tws8UicW00000NkvXXu0mjf#zB&9 literal 0 HcmV?d00001 diff --git a/textures/mcnodes_mchud_hotbar.png b/textures/mcnodes_mchud_hotbar.png new file mode 100644 index 0000000000000000000000000000000000000000..8c3df7c64c23387c21bf36ed08e75e4c2a7945ef GIT binary patch literal 1142 zcmeAS@N?(olHy`uVBq!ia0y~yU<v`Uy*Su_WbN%!uYnY2fk$L91B0G22s2hJwJ&2} zVA1e&aSW-L^Y(^eS5l&Y+r{mDag(bJ-<tZ|*l~Z>kpzjfBUw3n9&zR=aoD%(Yuqz5 zZddV~wD109c?Hi&UtZb%Wt^nqx&EGg{hvR-EYhBt7(X|E|K;b`!aH5U>V9)9mOei6 z@}Xbxd&g4O-5Gkt$tiOz3LhPLsS3mk{We>yIA>gJ+4uOmb$P4xeF+JWjzX^EotOPB zELZUK2rsVzDGxd8n3^z$38=3#*woKjoqcL!;iD=2AoEv&lm#n*w5>Xp`TWTOBLlxV zpCBqh%D9en0+n60csoZXgzZ>oupL<CGmx@IkV95VEuTBN`P2c6!c)h=DnZIL1wify zeY~Z(C_obErk`Myvp~vNfo>39o;9b;k57yF@exgVu*zbfvgHn7r}kbxcM{}Ui>Hsl zDnZIbI>1gXyk$A+snM7!Tt&y^ci(b_-*x-UXC=wNBne9Izy!-*I;)z0mHmfv`S<FN zf4zQU-rsZSki>6MSheG_&b|Q8Nh&YT&HKmTIcZ7w`<MI^R6MJ`)-hiXJG^w_-QxMc Pf`q}-)z4*}Q$iB}ed_yt literal 0 HcmV?d00001 diff --git a/textures/mcnodes_mchud_hotbar_selected.png b/textures/mcnodes_mchud_hotbar_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..40bafe6bec62d6881405a6e72d0cba0942e8490b GIT binary patch literal 1649 zcmV-%29EiOP)<h;3K|Lk000e1NJLTq002|~002}70{{R3E4ASB0001lP)t-s00000 z001;JG+SF+V`F1fR8*gzpI28`Sy@?LUS5QRglK4JM@L79h=`}Br;Ln@YinzEc6N}E zkWo=laBy%+N=jg0V0?UhPEJ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