Version 0.4 update

This commit is contained in:
hasanalsamra 2016-09-12 19:33:59 +03:00
parent 6fbe0449c4
commit 4669071b52
16 changed files with 346 additions and 8 deletions

View File

@ -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.

View File

@ -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.

View File

@ -1 +1 @@
0.3-beta
0.4

View File

@ -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

View File

@ -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

245
mchud/mchud.api.lua Normal file
View File

@ -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)

53
mchud/mchud.builtin.lua Normal file
View File

@ -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

23
mchud/mchud.functions.lua Normal file
View File

@ -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)

8
mchud/mchud.init.lua Normal file
View File

@ -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")

View File

@ -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"},

View File

@ -1,3 +1,4 @@
--Normal chest
if ChangeChest == '1' then
local chest_formspec =
"size[8,9]" ..

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB