From d3e8f7134aacacca5c5980ff108f576f7b1f4bd0 Mon Sep 17 00:00:00 2001 From: BlockMen Date: Fri, 28 Jun 2013 22:58:06 +0200 Subject: [PATCH] Initial commit --- .gitattributes | 22 ++++ .gitignore | 215 ++++++++++++++++++++++++++++++++++++ README.txt | 37 +++++++ depends.txt | 1 + hunger.lua | 34 ++++++ init.lua | 155 ++++++++++++++++++++++++++ no_drowning.lua | 15 +++ textures/hud_cross.png | Bin 0 -> 663 bytes textures/hud_heart_bg.png | Bin 0 -> 302 bytes textures/hud_heart_fg.png | Bin 0 -> 369 bytes textures/hud_hunger_bg.png | Bin 0 -> 417 bytes textures/hud_hunger_fg.png | Bin 0 -> 522 bytes textures/hud_inv_border.png | Bin 0 -> 163 bytes textures/wieldhand.png | Bin 0 -> 369 bytes 14 files changed, 479 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 README.txt create mode 100644 depends.txt create mode 100644 hunger.lua create mode 100644 init.lua create mode 100644 no_drowning.lua create mode 100644 textures/hud_cross.png create mode 100644 textures/hud_heart_bg.png create mode 100644 textures/hud_heart_fg.png create mode 100644 textures/hud_hunger_bg.png create mode 100644 textures/hud_hunger_fg.png create mode 100644 textures/hud_inv_border.png create mode 100644 textures/wieldhand.png diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9d6bd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,215 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..fcfd25f --- /dev/null +++ b/README.txt @@ -0,0 +1,37 @@ +Minetest mod "Better HUD" +========================= +version: 0.1 Beta + +License of source code: WTFPL +----------------------------- +- "Disable Drowning" [no_drowning], PilzAdam + +everything else: +(c) Copyright BlockMen (2013) + + +License of textures: +-------------------- +hud_heart_fg.png - celeron55 (CC BY-SA 3.0), modified by BlockMen +hud_heart_bg.png - celeron55 (CC BY-SA 3.0), modified by BlockMen +hud_hunger_fg.png - PilzAdam(WTFPL), modified by BlockMen +hud_hunger_bg.png - PilzAdam(WTFPL), modified by BlockMen +wieldhand.png (from character.png) - Jordach (CC BY-SA 3.0), modified by BlockMen + +everything else is WTFPL: +(c) Copyright BlockMen (2013) + +This program is free software. It comes without any warranty, to +the extent permitted by applicable law. You can redistribute it +and/or modify it under the terms of the Do What The Fuck You Want +To Public License, Version 2, as published by Sam Hocevar. See +http://sam.zoy.org/wtfpl/COPYING for more details. + + +Using the mod: +-------------- + +This mod changes the HUD of Minetest. It adds a costum crosshair, a improved health bar. +Also it adds hunger to the game and and hunger bar to the HUD. + +Furthermore it disables the current way of drowning (credits go to PilzAdam) and it will have an LUA-based drowing next versions. diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..331d858 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default \ No newline at end of file diff --git a/hunger.lua b/hunger.lua new file mode 100644 index 0000000..9e0f7ff --- /dev/null +++ b/hunger.lua @@ -0,0 +1,34 @@ +function hud.item_eat(hunger_change, replace_with_item) + return function(itemstack, user, pointed_thing) + if itemstack:take_item() ~= nil then + local h = tonumber(hud.hunger[user:get_player_name()]) + h=h+hunger_change + if h>20 then h=20 end + hud.hunger[user:get_player_name()]=h + itemstack:add_item(replace_with_item) -- note: replace_with_item is optional + --sound:eat + end + return itemstack + end +end + +local function overwrite(name, hunger_change, as_node) + local tab = minetest.registered_items[name] + if tab == nil then return end + local tab2 = {} + for i,v in pairs(tab) do + tab2[i] = v + end + tab2.on_use = hud.item_eat(hunger_change) + + if as_node then + minetest.register_node(":"..name, tab2) + else + minetest.register_craftitem(":"..name, tab2) + end +end + +overwrite("default:apple", 2, true) +if minetest.get_modpath("farming") ~= nil then + overwrite("farming:bread", 6, false) +end diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..d4a7506 --- /dev/null +++ b/init.lua @@ -0,0 +1,155 @@ +hud = {} + +local health_hud = {} +hud.hunger = {} +local hunger_hud = {} +hud.air = {} +local air_hud = {} + +local SAVE_INTERVAL = 0.5*60--currently useless + +local ENABLE_HUNGER = minetest.setting_getbool("enable_damage") -- set to false if no hunger wanted +local NO_HUNGER_TIME = 300 --=5min (so 1h playing == hunger) + +--minetest.after(SAVE_INTERVAL, timer, SAVE_INTERVAL) + +local function hide_builtin(player) + player:hud_set_flags({crosshair = false, hotbar = true, healthbar = false, wielditem = true, breathbar = false}) +end + +local function costum_hud(player) +--crosshair + player:hud_add({ + hud_elem_type = "image", + text = "hud_cross.png", + position = {x=0.5, y=0.5}, + scale = {x=1, y=1}, + }) +if minetest.setting_getbool("enable_damage") then +--hunger + player:hud_add({ + hud_elem_type = "statbar", + position = {x=0.5,y=1}, + scale = {x=1, y=1}, + text = "hud_hunger_bg.png", + number = 20, + alignment = {x=-1,y=-1}, + offset = {x=15,y=-60}, + }) + + hunger_hud[player:get_player_name()] = player:hud_add({ + hud_elem_type = "statbar", + position = {x=0.5,y=1}, + scale = {x=1, y=1}, + text = "hud_hunger_fg.png", + number = 20, + alignment = {x=-1,y=-1}, + offset = {x=15,y=-60}, + }) +--health + player:hud_add({ + hud_elem_type = "statbar", + position = {x=0.5,y=1}, + scale = {x=1, y=1}, + text = "hud_heart_bg.png", + number = 20, + alignment = {x=-1,y=-1}, + offset = {x=-175,y=-60}, + }) + + health_hud[player:get_player_name()] = player:hud_add({ + hud_elem_type = "statbar", + position = {x=0.5,y=1}, + scale = {x=1, y=1}, + text = "hud_heart_fg.png", + number = player:get_hp(), + alignment = {x=-1,y=-1}, + offset = {x=-175,y=-60}, + }) +end + +end + + +local function update_hud(player) +--health + player:hud_change(health_hud[player:get_player_name()], "number", player:get_hp()) +--hunger + player:hud_change(hunger_hud[player:get_player_name()], "number", hud.hunger[player:get_player_name()]) +end + + +local function save_hunger(player) + local file = io.open(minetest.get_worldpath().."/hud_"..player:get_player_name().."_hunger", "w+") + if file then + file:write(hud.hunger[player:get_player_name()]) + file:close() + end +end + +local function timer(interval, player) + if interval > 0 then + save_hunger(player) + minetest.after(interval, timer, interval, player) + end +end + +local function load_hunger(player) + local file = io.open(minetest.get_worldpath().."/hud_"..player:get_player_name().."_hunger", "r") + if file then + hud.hunger[player:get_player_name()] = file:read("*all") + file:close() + return hud.hunger[player:get_player_name()] + else + return + end + +end + + +minetest.register_on_joinplayer(function(player) + hud.hunger[player:get_player_name()] = load_hunger(player) + if hud.hunger[player:get_player_name()] == nil then + hud.hunger[player:get_player_name()] = 20 + end + minetest.after(0.5, function() + save_hunger(player) + hide_builtin(player) + costum_hud(player) + end) +end) + +local timer = 0 +local timer2 = 0 +minetest.after(2.5, function() +if minetest.setting_getbool("enable_damage") then + minetest.register_globalstep(function(dtime) + timer = timer + dtime + timer2 = timer2 + dtime + for _,player in ipairs(minetest.get_connected_players()) do + local h = tonumber(hud.hunger[player:get_player_name()]) + if ENABLE_HUNGER and timer > 4 then + if h>=18 then + player:set_hp(player:get_hp()+1) + elseif h==1 and minetest.setting_getbool("enable_damage") then + if player:get_hp()-1 >= 1 then player:set_hp(player:get_hp()-1) end + end + end + if ENABLE_HUNGER and timer2>NO_HUNGER_TIME then + --local h = tonumber(hunger[player:get_player_name()]) + if h>1 then + h=h-1 + hud.hunger[player:get_player_name()]=h + save_hunger(player) + end + end + update_hud(player) + end + if timer>4 then timer=0 end + if timer2>NO_HUNGER_TIME then timer2=0 end + end) +end +end) + +if ENABLE_HUNGER then dofile(minetest.get_modpath("hud").."/hunger.lua") end +dofile(minetest.get_modpath("hud").."/no_drowning.lua") diff --git a/no_drowning.lua b/no_drowning.lua new file mode 100644 index 0000000..f7b3149 --- /dev/null +++ b/no_drowning.lua @@ -0,0 +1,15 @@ +local function drwn_overwrite(name) + local table = minetest.registered_nodes[name] + local table2 = {} + for i,v in pairs(table) do + table2[i] = v + end + table2.drowning = false + table2.hud_drowning = true + minetest.register_node(":"..name, table2) +end + +drwn_overwrite("default:water_source") +drwn_overwrite("default:water_flowing") +drwn_overwrite("default:lava_source") +drwn_overwrite("default:lava_flowing") diff --git a/textures/hud_cross.png b/textures/hud_cross.png new file mode 100644 index 0000000000000000000000000000000000000000..5822e713910b2692183093cf7c97b5ec4afca350 GIT binary patch literal 663 zcmeAS@N?(olHy`uVBq!ia0vp^HXzKw1|+Ti+$;i8oCO|{#S9F3${@^GvDChdfq}`> z)5S5QV$Rze{vNjjWY`N7r*8~Ck=WkS-t2X>QGE86E~DfB?zG&w|nz z|E{R={^RS~YrzJb%Pab1+?p3rE zP5c@%<>eR4SZ2LvLOGk$MEPDxAFJEz6!vk;o(VDu&fIE04NGp>Wya2#Z#nOERds0h zio|Dnun5=fs$PBrOhrYHE$J^%U;xADk!i$<7KVSUmef;!uPtVJrdwARYY5L~LSETmKH8xH+7P`MCvi0&e&()Eexgw+=W*%10 zSKfECBDCmMeAL_Z$JgF{b$XJOsR!8j8)uHqOwv0z>5qigGodvz#a7xcSSfM*&fe1A zYJ(ctlbzBp9?q?MckwUB)?@446CTX7p2h%*A&CQtOox@^#6BuAA6D9TTkPZA83))I lpwTCBVDDro?}6VZcJ}MPU$_S>w+E&)22WQ%mvv4FO#su$E3*Iq literal 0 HcmV?d00001 diff --git a/textures/hud_heart_bg.png b/textures/hud_heart_bg.png new file mode 100644 index 0000000000000000000000000000000000000000..e2be2768e569748d3d19bc3fd02e8bf36f5bfa03 GIT binary patch literal 302 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9F5he4R}c>anMpx^^f z7srr_IY%!Wt~#P1z?SfSf|H6XhjMUF(nP1G4)!fyTJAl$uhp1yZF~OBr0&d?|HUb8 ztPZuo@vZs}>wN_UXGosmQF2=E`}Nk9O*$K{HO*YO)ouM-J^{g`9*w07rZh*az&zt8kNnXyH@^QZnikZw^;`Xc6*GSF+1Ni!UT}Sx6G#5x+uIUj zuU|i4bH2W8VsTr?o_U81jRYl`&h7jt!GA!4`TbwrH+$O+pWW$IEKpEtnqypauHank yq5Q_U*_Wc6T@;kkZ_6{ftDiULZ=C=482iEurpGBS}O-RCt`llc8?HP!xv$ph*=1L2?5Ls&##X>MQmJBQ--VO&?%# zu4)-(;Sq{sj*9s`!US$&leqg$^g>#oAqxWWo0I#0=RY~;3eYvW%G?4}VXi`A=~YNn zVXi97^(67?>-WBX0w^TDBnSeWF>I$(-i+ZT2-rycNFcG1xRW>mEWMd1f+PWJc~26) zqX-uS^;3yopXNNknA)7CkY%_u#U%;Om;(Sm%GnXN<1ttZSq6(m4Y3y2?_UN~VXlwC z0M|%Bn&RRZ*Xte3pAyeqfJce#WKzer78l2@&O3>+YYY38l@e|^#EnL+&Pc2zW|sgD z66=O(ueHRyaT}e0D$F(aQFmUeBlAT-73P|GNZE+}FTj4BpGQ%OWYRCt`Nlf7=jFcd~Z)s4q-V#j}S9N(Bo9uNaUNQ_8GOc{AB z-maBG`8vgdma0hS*v&hyhZwANsZfiVWoIXLI2s_N})-8TUd zjUfaO5kd%1O2HU|rfFcUg;ENPvG<1pBD&Od4Jjq8wTLldwOXO?dsu5Bgg{xAQ?fA& z_WS*8yWNh)7?foR&N5y3eJB7(IRbzSGHX|2bcfQT;6IdIP5z0X~xln_Ed zN(t{hy!V*u7-N@P!PPkj=Nw{;xm#6LIh9fhA%u(&0=I$>BFd4Sb1=q0YmKI9Af<#c z2Gf8i02IYA470=GaOt`(Prq&3%x%}(!$fqwdxhO@hZrMbjOe-!lkg`V?!kF}D%R^Y zQc6fEVX;^s#)y;>Hk%FlzQ@Bw8iwKJ(MJBpU4rBB`1&Wov!Ce`d<6U`HGiA|00000 LNkvXXu0mjf5NEV} literal 0 HcmV?d00001 diff --git a/textures/hud_hunger_fg.png b/textures/hud_hunger_fg.png new file mode 100644 index 0000000000000000000000000000000000000000..a5cc2a12339c1fcba9e605fb5cae51aabcefb60c GIT binary patch literal 522 zcmV+l0`>igP)pGyh%hsRCt`NlfP?IVHAd+ivNL21xFVL|C0n#xP+i^QAlWqIyfi| zNJ(|Dv}V%5Hsp#oVkM*!2m~Z0v~q__BmSVxu^J9O+YXXFK0RD zIWOP$9wae|CK~=f0DpR6MD-+cW1&hnQ0XQr+Wh>pZvIwADLRAaxBv4?74{TPENeux5e{O2973m*1$T%o?iuPB~-Xhx1 zqUJJcrcv`2GHc-ylSjtk_{=X1%2(7bphE|J$)kh(urY^PIn>IBGQ&kc_nDm%_0}w4oO^A8-asU7T M07*qoM6N<$g3~bIZML z;uumf=j{bUK?VhZBL{*TmA5pg#yos6kwLWHK=aaj7eU46ml%&bT$S_N%RMJm!?=Ng zk!cT8&O3+S%|I3lhk$|uNQi~wL+}Fc_l&XL>~ErC-uYh*-5(tXw1C0W)z4*}Q$iB} Dk&rMV literal 0 HcmV?d00001 diff --git a/textures/wieldhand.png b/textures/wieldhand.png new file mode 100644 index 0000000000000000000000000000000000000000..5f7f4909cfd2d7837ebbd59abec914db333b2d16 GIT binary patch literal 369 zcmV-%0gnEOP)pGBS}O-RCt{2%*#pw0T@8x|1pfvj2@!Wc5Pck^dN17B%CR%G`d)$ zqv&We6+s53LMb&~z!udaq)k}R^+iq#lNJ#pxNUKk=Mz8%X`uNZ_yZ{E3dO`v<)q4a zO2tkqTxUZ#0{4YDy>3oo)XfOh%nEi!p^;v420ojI^y*X$Zu2qf<{C9a#ZCpCf%nD% zZ*_}T+vKTg@K8!}m*1gfhPl!g`vhuT;Q2Dg<3*ZwL8E1@Qqcna0UzJJ*e0EdLHjID zGq*x&cM`>;I{<-zTnFWK0}zy2oot`JR#1& zm?ezrf_FpkMg(tE7>Np=u;5Yp06do9)&=*bFuX1dg$38L;0g(@;BVjys*KwP**^Yl P00000NkvXXu0mjfxagjU literal 0 HcmV?d00001