mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-01-26 01:30:29 +01:00
Merge branch 'mgl512-devel'
This commit is contained in:
commit
a3a190f813
@ -120,7 +120,6 @@ minetest.register_craftitem(":bucket:bucket_empty", {
|
|||||||
local liquiddef = bucket.liquids[node.name]
|
local liquiddef = bucket.liquids[node.name]
|
||||||
if liquiddef ~= nil and liquiddef.itemname ~= nil and
|
if liquiddef ~= nil and liquiddef.itemname ~= nil and
|
||||||
node.name == liquiddef.source then
|
node.name == liquiddef.source then
|
||||||
minetest.setting_getbool("liquid_finite"))) then
|
|
||||||
if check_protection(pointed_thing.under,
|
if check_protection(pointed_thing.under,
|
||||||
user:get_player_name(),
|
user:get_player_name(),
|
||||||
"take ".. node.name) then
|
"take ".. node.name) then
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
local function active_formspec(fuel_percent, item_percent)
|
local function active_formspec(fuel_percent, item_percent)
|
||||||
local formspec =
|
local formspec =
|
||||||
"size[8,8.5]"..
|
"size[8,8.5]"..
|
||||||
default.gui_bg..
|
|
||||||
default.gui_bg_img..
|
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
"list[current_name;src;2.75,0.5;1,1;]"..
|
"list[current_name;src;2.75,0.5;1,1;]"..
|
||||||
"list[current_name;fuel;2.75,2.5;1,1;]"..
|
"list[current_name;fuel;2.75,2.5;1,1;]"..
|
||||||
@ -24,8 +22,6 @@ end
|
|||||||
|
|
||||||
local inactive_formspec =
|
local inactive_formspec =
|
||||||
"size[8,8.5]"..
|
"size[8,8.5]"..
|
||||||
default.gui_bg..
|
|
||||||
default.gui_bg_img..
|
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
"list[current_name;src;2.75,0.5;1,1;]"..
|
"list[current_name;src;2.75,0.5;1,1;]"..
|
||||||
"list[current_name;fuel;2.75,2.5;1,1;]"..
|
"list[current_name;fuel;2.75,2.5;1,1;]"..
|
||||||
@ -138,6 +134,182 @@ minetest.register_node("default:furnace_active", {
|
|||||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Locked Furnace thanks to kotolegokot:
|
||||||
|
|
||||||
|
local function has_locked_furnace_privilege(meta, player)
|
||||||
|
if player:get_player_name() ~= meta:get_string("owner") and player:get_player_name() ~= minetest.setting_get("name") then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_node("default:furnace_locked", {
|
||||||
|
description = "Locked Furnace",
|
||||||
|
tiles = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
|
||||||
|
"default_furnace_side.png", "default_furnace_side.png", "default_furnace_lock.png"},
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
groups = {cracky = 2},
|
||||||
|
sounds = default.node_sound_stone_defaults(),
|
||||||
|
after_place_node = function(pos, placer)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("owner", placer:get_player_name())
|
||||||
|
meta:set_string("infotext", "Locked Furnace (owned by " .. placer:get_player_name() .. ")")
|
||||||
|
end,
|
||||||
|
on_construct = function(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("formspec", inactive_formspec)
|
||||||
|
meta:set_string("infotext", "Locked Furnace")
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
inv:set_size("fuel", 1)
|
||||||
|
inv:set_size("src", 1)
|
||||||
|
inv:set_size("dst", 4)
|
||||||
|
end,
|
||||||
|
can_dig = can_dig,
|
||||||
|
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if not has_locked_furnace_privilege(meta, player) then
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" tried to access a locked furnace belonging to "..
|
||||||
|
meta:get_string("owner").." at "..
|
||||||
|
minetest.pos_to_string(pos) .. ".")
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
return count
|
||||||
|
end,
|
||||||
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if not has_locked_furnace_privilege(meta, player) then
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" tried to access a locked furnace belonging to "..
|
||||||
|
meta:get_string("owner").." at "..
|
||||||
|
minetest.pos_to_string(pos) .. ".")
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
return stack:get_count()
|
||||||
|
end,
|
||||||
|
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if not has_locked_furnace_privilege(meta, player) then
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" tried to access a locked furnace belonging to "..
|
||||||
|
meta:get_string("owner").." at "..
|
||||||
|
minetest.pos_to_string(pos) .. ".")
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
return stack:get_count()
|
||||||
|
end,
|
||||||
|
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" moves stuff in locked furnace at "..minetest.pos_to_string(pos) ..".")
|
||||||
|
end,
|
||||||
|
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" moves stuff to locked furnace at "..minetest.pos_to_string(pos) ..".")
|
||||||
|
end,
|
||||||
|
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" takes stuff from locked furnace at "..minetest.pos_to_string(pos) ..".")
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_node("default:furnace_locked_active", {
|
||||||
|
description = "Locked Furnace (active)",
|
||||||
|
tiles = {
|
||||||
|
"default_furnace_top.png",
|
||||||
|
"default_furnace_bottom.png",
|
||||||
|
"default_furnace_side.png",
|
||||||
|
"default_furnace_side.png",
|
||||||
|
"default_furnace_side.png",
|
||||||
|
{
|
||||||
|
image = "default_furnace_lock_active.png",
|
||||||
|
backface_culling = false,
|
||||||
|
animation = {
|
||||||
|
type = "vertical_frames",
|
||||||
|
aspect_w = 16,
|
||||||
|
aspect_h = 16,
|
||||||
|
length = 1
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
light_source = 9,
|
||||||
|
drop = "default:furnace_locked",
|
||||||
|
groups = {cracky = 2, not_in_creative_inventory = 1},
|
||||||
|
sounds = default.node_sound_stone_defaults(),
|
||||||
|
after_place_node = function(pos, placer)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("owner", placer:get_player_name())
|
||||||
|
meta:set_string("owner", "Locked Furnace (owned by " .. player:get_player_name() .. ")")
|
||||||
|
end,
|
||||||
|
on_construct = function(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("formspec", inactive_formspec)
|
||||||
|
meta:set_string("infotext", "Locked Furnace");
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
inv:set_size("fuel", 1)
|
||||||
|
inv:set_size("src", 1)
|
||||||
|
inv:set_size("dst", 4)
|
||||||
|
end,
|
||||||
|
can_dig = function(pos,player)
|
||||||
|
local meta = minetest.get_meta(pos);
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
if not inv:is_empty("fuel") then
|
||||||
|
return false
|
||||||
|
elseif not inv:is_empty("dst") then
|
||||||
|
return false
|
||||||
|
elseif not inv:is_empty("src") then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if not has_locked_furnace_privilege(meta, player) then
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" tried to access a locked furnace belonging to "..
|
||||||
|
meta:get_string("owner").." at "..
|
||||||
|
minetest.pos_to_string(pos) .. ".")
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
return count
|
||||||
|
end,
|
||||||
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if not has_locked_furnace_privilege(meta, player) then
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" tried to access a locked furnace belonging to "..
|
||||||
|
meta:get_string("owner").." at "..
|
||||||
|
minetest.pos_to_string(pos) .. ".")
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
return stack:get_count()
|
||||||
|
end,
|
||||||
|
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if not has_locked_furnace_privilege(meta, player) then
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" tried to access a locked furnace belonging to "..
|
||||||
|
meta:get_string("owner").." at "..
|
||||||
|
minetest.pos_to_string(pos) .. ".")
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
return stack:get_count()
|
||||||
|
end,
|
||||||
|
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" moves stuff in locked furnace at "..minetest.pos_to_string(pos) .. ".")
|
||||||
|
end,
|
||||||
|
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" moves stuff to locked furnace at "..minetest.pos_to_string(pos) .. ".")
|
||||||
|
end,
|
||||||
|
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" takes stuff from locked furnace at "..minetest.pos_to_string(pos) .. ".")
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- ABM
|
-- ABM
|
||||||
--
|
--
|
||||||
@ -281,3 +453,103 @@ minetest.register_abm({
|
|||||||
meta:set_string("infotext", infotext)
|
meta:set_string("infotext", infotext)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_abm({
|
||||||
|
nodenames = {"default:furnace_locked","default:furnace_locked_active"},
|
||||||
|
interval = 1.0,
|
||||||
|
chance = 1,
|
||||||
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
for i, name in ipairs({
|
||||||
|
"fuel_totaltime",
|
||||||
|
"fuel_time",
|
||||||
|
"src_totaltime",
|
||||||
|
"src_time"
|
||||||
|
}) do
|
||||||
|
if meta:get_string(name) == "" then
|
||||||
|
meta:set_float(name, 0.0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
|
||||||
|
local srclist = inv:get_list("src")
|
||||||
|
local cooked = nil
|
||||||
|
|
||||||
|
if srclist then
|
||||||
|
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||||
|
end
|
||||||
|
|
||||||
|
local was_active = false
|
||||||
|
|
||||||
|
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
||||||
|
was_active = true
|
||||||
|
meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
|
||||||
|
meta:set_float("src_time", meta:get_float("src_time") + 1)
|
||||||
|
if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
|
||||||
|
-- check if there's room for output in "dst" list
|
||||||
|
if inv:room_for_item("dst",cooked.item) then
|
||||||
|
-- Put result in "dst" list
|
||||||
|
inv:add_item("dst", cooked.item)
|
||||||
|
-- take stuff from "src" list
|
||||||
|
srcstack = inv:get_stack("src", 1)
|
||||||
|
srcstack:take_item()
|
||||||
|
inv:set_stack("src", 1, srcstack)
|
||||||
|
else
|
||||||
|
-- print("Could not insert " .. cooked.item .. ".")
|
||||||
|
end
|
||||||
|
meta:set_string("src_time", 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local item_percent = 0
|
||||||
|
if cooked then
|
||||||
|
item_percent = meta:get_float("src_time") * 100 / cooked.time
|
||||||
|
end
|
||||||
|
|
||||||
|
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
||||||
|
local percent = math.floor(meta:get_float("fuel_time") /
|
||||||
|
meta:get_float("fuel_totaltime") * 100)
|
||||||
|
meta:set_string("infotext","Furnace active: " .. percent .. " % (owned by "..meta:get_string("owner") .. ")")
|
||||||
|
swap_node(pos,"default:furnace_locked_active")
|
||||||
|
meta:set_string("formspec", active_formspec(percent, item_percent))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local fuel = nil
|
||||||
|
local cooked = nil
|
||||||
|
local fuellist = inv:get_list("fuel")
|
||||||
|
local srclist = inv:get_list("src")
|
||||||
|
|
||||||
|
if srclist then
|
||||||
|
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||||
|
end
|
||||||
|
if fuellist then
|
||||||
|
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
||||||
|
end
|
||||||
|
|
||||||
|
if fuel.time <= 0 then
|
||||||
|
meta:set_string("infotext","Locked Furnace is out of fuel (owned by "..meta:get_string("owner")..")")
|
||||||
|
swap_node(pos,"default:furnace_locked")
|
||||||
|
meta:set_string("formspec", inactive_formspec)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if cooked.item:is_empty() then
|
||||||
|
if was_active then
|
||||||
|
meta:set_string("infotext","Locked Furnace is empty (owned by "..meta:get_string("owner")..")")
|
||||||
|
swap_node(pos,"default:furnace_locked")
|
||||||
|
meta:set_string("formspec", inactive_formspec)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
meta:set_string("fuel_totaltime", fuel.time)
|
||||||
|
meta:set_string("fuel_time", 0)
|
||||||
|
|
||||||
|
local stack = inv:get_stack("fuel", 1)
|
||||||
|
stack:take_item()
|
||||||
|
inv:set_stack("fuel", 1, stack)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
@ -11,8 +11,9 @@ LAVA_VISC = 3 -- Slower movement in lava.
|
|||||||
LIGHT_MAX = 14 -- 15 is reserved for sunlight.
|
LIGHT_MAX = 14 -- 15 is reserved for sunlight.
|
||||||
|
|
||||||
-- GUI related stuff:
|
-- GUI related stuff:
|
||||||
|
default.gui_bg = "bgcolor[#080808BB;true]"
|
||||||
gui_slots = "listcolors[#606060AA;#808080;#101010;#202020;#FFF]"
|
default.gui_bg_img = "background[5,5;1,1;gui_formbg.png;true]"
|
||||||
|
default.gui_slots = "listcolors[#606060AA;#808080;#101010;#202020;#FFF]"
|
||||||
|
|
||||||
function default.get_hotbar_bg(x,y)
|
function default.get_hotbar_bg(x,y)
|
||||||
local out = ""
|
local out = ""
|
||||||
@ -22,8 +23,8 @@ function default.get_hotbar_bg(x,y)
|
|||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
|
||||||
gui_suvival_form = "size[8,8.5]"..
|
default.gui_suvival_form = "size[8,8.5]"..
|
||||||
gui_slots ..
|
default.gui_slots ..
|
||||||
"list[current_player;main; 0, 4.25; 8, 4; ]" ..
|
"list[current_player;main; 0, 4.25; 8, 4; ]" ..
|
||||||
"list[current_player;craft; 1.75, 0.5; 3, 3; ]" ..
|
"list[current_player;craft; 1.75, 0.5; 3, 3; ]" ..
|
||||||
"list[current_player;craftpreview; 5.75, 1.5; 1, 1; ]" ..
|
"list[current_player;craftpreview; 5.75, 1.5; 1, 1; ]" ..
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
-- mods/default/nodes.lua
|
-- mods/default/nodes.lua
|
||||||
|
|
||||||
gui_slots = "listcolors[#606060AA;#808080;#101010;#202020;#FFF]"
|
|
||||||
|
|
||||||
minetest.register_node("default:stone", {
|
minetest.register_node("default:stone", {
|
||||||
description = "Stone",
|
description = "Stone",
|
||||||
tiles = {"default_stone.png"},
|
tiles = {"default_stone.png"},
|
||||||
@ -581,7 +579,7 @@ minetest.register_node("default:papyrus", {
|
|||||||
|
|
||||||
default.bookshelf_formspec =
|
default.bookshelf_formspec =
|
||||||
"size[8,7;]" ..
|
"size[8,7;]" ..
|
||||||
gui_slots ..
|
default.gui_slots ..
|
||||||
"list[context;books;0, 0.3;8,2;]" ..
|
"list[context;books;0, 0.3;8,2;]" ..
|
||||||
"list[current_player;main;0,2.85;8,4;]" ..
|
"list[current_player;main;0,2.85;8,4;]" ..
|
||||||
default.get_hotbar_bg(0, 2.85) ..
|
default.get_hotbar_bg(0, 2.85) ..
|
||||||
@ -1189,7 +1187,7 @@ minetest.register_node("default:sign_wall", {
|
|||||||
|
|
||||||
default.chest_formspec =
|
default.chest_formspec =
|
||||||
"size[8,9]" ..
|
"size[8,9]" ..
|
||||||
gui_slots ..
|
default.gui_slots ..
|
||||||
"list[current_name;main;0,0.3;8,4;]" ..
|
"list[current_name;main;0,0.3;8,4;]" ..
|
||||||
"list[current_player;main;0,4.85;8,4;]" ..
|
"list[current_player;main;0,4.85;8,4;]" ..
|
||||||
default.get_hotbar_bg(0, 4.85) ..
|
default.get_hotbar_bg(0, 4.85) ..
|
||||||
@ -1199,7 +1197,7 @@ function default.get_locked_chest_formspec(pos)
|
|||||||
local spos = pos.x .. "," .. pos.y .. "," .. pos.z
|
local spos = pos.x .. "," .. pos.y .. "," .. pos.z
|
||||||
local formspec =
|
local formspec =
|
||||||
"size[8,9]" ..
|
"size[8,9]" ..
|
||||||
gui_slots ..
|
default.gui_slots ..
|
||||||
"list[nodemeta:".. spos .. ";main;0,0.3;8,4;]" ..
|
"list[nodemeta:".. spos .. ";main;0,0.3;8,4;]" ..
|
||||||
"list[current_player;main;0,4.85;8,4;]" ..
|
"list[current_player;main;0,4.85;8,4;]" ..
|
||||||
default.get_hotbar_bg(0, 4.85) ..
|
default.get_hotbar_bg(0, 4.85) ..
|
||||||
@ -1324,403 +1322,6 @@ minetest.register_node("default:chest_locked", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Locked Furnace thanks to kotolegokot:
|
|
||||||
|
|
||||||
local function has_locked_furnace_privilege(meta, player)
|
|
||||||
if player:get_player_name() ~= meta:get_string("owner") and player:get_player_name() ~= minetest.setting_get("name") then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_node("default:furnace_locked", {
|
|
||||||
description = "Locked Furnace",
|
|
||||||
tiles = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
|
|
||||||
"default_furnace_side.png", "default_furnace_side.png", "default_furnace_lock.png"},
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = {cracky = 2},
|
|
||||||
sounds = default.node_sound_stone_defaults(),
|
|
||||||
after_place_node = function(pos, placer)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string("owner", placer:get_player_name())
|
|
||||||
meta:set_string("infotext", "Locked Furnace (owned by " .. placer:get_player_name() .. ")")
|
|
||||||
end,
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string("formspec", default.furnace_inactive_formspec)
|
|
||||||
meta:set_string("infotext", "Locked Furnace")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("fuel", 1)
|
|
||||||
inv:set_size("src", 1)
|
|
||||||
inv:set_size("dst", 4)
|
|
||||||
end,
|
|
||||||
can_dig = function(pos,player)
|
|
||||||
local meta = minetest.get_meta(pos);
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
if not inv:is_empty("fuel") then
|
|
||||||
return false
|
|
||||||
elseif not inv:is_empty("dst") then
|
|
||||||
return false
|
|
||||||
elseif not inv:is_empty("src") then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
if not has_locked_furnace_privilege(meta, player) then
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" tried to access a locked furnace belonging to "..
|
|
||||||
meta:get_string("owner").." at "..
|
|
||||||
minetest.pos_to_string(pos) .. ".")
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return count
|
|
||||||
end,
|
|
||||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
if not has_locked_furnace_privilege(meta, player) then
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" tried to access a locked furnace belonging to "..
|
|
||||||
meta:get_string("owner").." at "..
|
|
||||||
minetest.pos_to_string(pos) .. ".")
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return stack:get_count()
|
|
||||||
end,
|
|
||||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
if not has_locked_furnace_privilege(meta, player) then
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" tried to access a locked furnace belonging to "..
|
|
||||||
meta:get_string("owner").." at "..
|
|
||||||
minetest.pos_to_string(pos) .. ".")
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return stack:get_count()
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" moves stuff in locked furnace at "..minetest.pos_to_string(pos) ..".")
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" moves stuff to locked furnace at "..minetest.pos_to_string(pos) ..".")
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" takes stuff from locked furnace at "..minetest.pos_to_string(pos) ..".")
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("default:furnace_locked_active", {
|
|
||||||
description = "Locked Furnace (active)",
|
|
||||||
tiles = {
|
|
||||||
"default_furnace_top.png",
|
|
||||||
"default_furnace_bottom.png",
|
|
||||||
"default_furnace_side.png",
|
|
||||||
"default_furnace_side.png",
|
|
||||||
"default_furnace_side.png",
|
|
||||||
{
|
|
||||||
image = "default_furnace_lock_active.png",
|
|
||||||
backface_culling = false,
|
|
||||||
animation = {
|
|
||||||
type = "vertical_frames",
|
|
||||||
aspect_w = 16,
|
|
||||||
aspect_h = 16,
|
|
||||||
length = 1
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
light_source = 9,
|
|
||||||
drop = "default:furnace_locked",
|
|
||||||
groups = {cracky = 2, not_in_creative_inventory = 1},
|
|
||||||
sounds = default.node_sound_stone_defaults(),
|
|
||||||
after_place_node = function(pos, placer)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string("owner", placer:get_player_name())
|
|
||||||
meta:set_string("owner", "Locked Furnace (owned by " .. player:get_player_name() .. ")")
|
|
||||||
end,
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string("formspec", default.furnace_inactive_formspec)
|
|
||||||
meta:set_string("infotext", "Locked Furnace");
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("fuel", 1)
|
|
||||||
inv:set_size("src", 1)
|
|
||||||
inv:set_size("dst", 4)
|
|
||||||
end,
|
|
||||||
can_dig = function(pos,player)
|
|
||||||
local meta = minetest.get_meta(pos);
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
if not inv:is_empty("fuel") then
|
|
||||||
return false
|
|
||||||
elseif not inv:is_empty("dst") then
|
|
||||||
return false
|
|
||||||
elseif not inv:is_empty("src") then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
if not has_locked_furnace_privilege(meta, player) then
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" tried to access a locked furnace belonging to "..
|
|
||||||
meta:get_string("owner").." at "..
|
|
||||||
minetest.pos_to_string(pos) .. ".")
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return count
|
|
||||||
end,
|
|
||||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
if not has_locked_furnace_privilege(meta, player) then
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" tried to access a locked furnace belonging to "..
|
|
||||||
meta:get_string("owner").." at "..
|
|
||||||
minetest.pos_to_string(pos) .. ".")
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return stack:get_count()
|
|
||||||
end,
|
|
||||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
if not has_locked_furnace_privilege(meta, player) then
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" tried to access a locked furnace belonging to "..
|
|
||||||
meta:get_string("owner").." at "..
|
|
||||||
minetest.pos_to_string(pos) .. ".")
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return stack:get_count()
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" moves stuff in locked furnace at "..minetest.pos_to_string(pos) .. ".")
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" moves stuff to locked furnace at "..minetest.pos_to_string(pos) .. ".")
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" takes stuff from locked furnace at "..minetest.pos_to_string(pos) .. ".")
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_abm({
|
|
||||||
nodenames = {"default:furnace_locked","default:furnace_locked_active"},
|
|
||||||
interval = 1.0,
|
|
||||||
chance = 1,
|
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
for i, name in ipairs({
|
|
||||||
"fuel_totaltime",
|
|
||||||
"fuel_time",
|
|
||||||
"src_totaltime",
|
|
||||||
"src_time"
|
|
||||||
}) do
|
|
||||||
if meta:get_string(name) == "" then
|
|
||||||
meta:set_float(name, 0.0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
|
|
||||||
local srclist = inv:get_list("src")
|
|
||||||
local cooked = nil
|
|
||||||
|
|
||||||
if srclist then
|
|
||||||
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
|
||||||
end
|
|
||||||
|
|
||||||
local was_active = false
|
|
||||||
|
|
||||||
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
|
||||||
was_active = true
|
|
||||||
meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
|
|
||||||
meta:set_float("src_time", meta:get_float("src_time") + 1)
|
|
||||||
if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
|
|
||||||
-- check if there's room for output in "dst" list
|
|
||||||
if inv:room_for_item("dst",cooked.item) then
|
|
||||||
-- Put result in "dst" list
|
|
||||||
inv:add_item("dst", cooked.item)
|
|
||||||
-- take stuff from "src" list
|
|
||||||
srcstack = inv:get_stack("src", 1)
|
|
||||||
srcstack:take_item()
|
|
||||||
inv:set_stack("src", 1, srcstack)
|
|
||||||
else
|
|
||||||
-- print("Could not insert " .. cooked.item .. ".")
|
|
||||||
end
|
|
||||||
meta:set_string("src_time", 0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local item_percent = 0
|
|
||||||
if cooked then
|
|
||||||
item_percent = meta:get_float("src_time")/cooked.time
|
|
||||||
end
|
|
||||||
|
|
||||||
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
|
||||||
local percent = math.floor(meta:get_float("fuel_time") /
|
|
||||||
meta:get_float("fuel_totaltime") * 100)
|
|
||||||
meta:set_string("infotext","Furnace active: " .. percent .. " % (owned by "..meta:get_string("owner") .. ")")
|
|
||||||
swap_node(pos,"default:furnace_locked_active")
|
|
||||||
meta:set_string("formspec",
|
|
||||||
"invsize[8,8.5;]" .. gui_slots ..
|
|
||||||
"image[2.75,1.5;1,1;default_furnace_fire_bg.png^[lowpart:" ..
|
|
||||||
(100-percent)..":default_furnace_fire_fg.png]" ..
|
|
||||||
"image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[lowpart:" ..
|
|
||||||
(item_percent * 100)..":gui_furnace_arrow_fg.png^[transformR270]" ..
|
|
||||||
"list[current_name;src;2.75, 0.5;1,1;]" ..
|
|
||||||
"list[current_name;fuel;2.75,2.5;1,1;]" ..
|
|
||||||
"list[current_name;dst;4.75, 0.96;2,2;]" ..
|
|
||||||
"list[current_player;main;0,4.25;8,4;]" ..
|
|
||||||
default.get_hotbar_bg(0, 4.25) ..
|
|
||||||
default.get_hotbar_bg(0, 5.25))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local fuel = nil
|
|
||||||
local cooked = nil
|
|
||||||
local fuellist = inv:get_list("fuel")
|
|
||||||
local srclist = inv:get_list("src")
|
|
||||||
|
|
||||||
if srclist then
|
|
||||||
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
|
||||||
end
|
|
||||||
if fuellist then
|
|
||||||
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
|
||||||
end
|
|
||||||
|
|
||||||
if fuel.time <= 0 then
|
|
||||||
meta:set_string("infotext","Locked Furnace is out of fuel (owned by "..meta:get_string("owner")..")")
|
|
||||||
swap_node(pos,"default:furnace_locked")
|
|
||||||
meta:set_string("formspec", default.furnace_inactive_formspec)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if cooked.item:is_empty() then
|
|
||||||
if was_active then
|
|
||||||
meta:set_string("infotext","Locked Furnace is empty (owned by "..meta:get_string("owner")..")")
|
|
||||||
swap_node(pos,"default:furnace_locked")
|
|
||||||
meta:set_string("formspec", default.furnace_inactive_formspec)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
meta:set_string("fuel_totaltime", fuel.time)
|
|
||||||
meta:set_string("fuel_time", 0)
|
|
||||||
|
|
||||||
local stack = inv:get_stack("fuel", 1)
|
|
||||||
stack:take_item()
|
|
||||||
inv:set_stack("fuel", 1, stack)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
function swap_node(pos, name)
|
|
||||||
local node = minetest.get_node(pos)
|
|
||||||
if node.name == name then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
node.name = name
|
|
||||||
minetest.swap_node(pos, node)
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_abm({
|
|
||||||
nodenames = {"default:furnace","default:furnace_active"},
|
|
||||||
interval = 1.0,
|
|
||||||
chance = 1,
|
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
for i, name in ipairs({
|
|
||||||
"fuel_totaltime",
|
|
||||||
"fuel_time",
|
|
||||||
"src_totaltime",
|
|
||||||
"src_time"
|
|
||||||
}) do
|
|
||||||
if meta:get_string(name) == "" then
|
|
||||||
meta:set_float(name, 0.0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
|
|
||||||
local srclist = inv:get_list("src")
|
|
||||||
local cooked = nil
|
|
||||||
local aftercooked
|
|
||||||
|
|
||||||
if srclist then
|
|
||||||
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
|
||||||
end
|
|
||||||
|
|
||||||
local was_active = false
|
|
||||||
|
|
||||||
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
|
||||||
was_active = true
|
|
||||||
meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
|
|
||||||
meta:set_float("src_time", meta:get_float("src_time") + 1)
|
|
||||||
if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
|
|
||||||
-- check if there"s room for output in "dst" list
|
|
||||||
if inv:room_for_item("dst",cooked.item) then
|
|
||||||
-- Put result in "dst" list
|
|
||||||
inv:add_item("dst", cooked.item)
|
|
||||||
-- take stuff from "src" list
|
|
||||||
inv:set_stack("src", 1, aftercooked.items[1])
|
|
||||||
else
|
|
||||||
--print("Could not insert ""..cooked.item:to_string()..""")
|
|
||||||
end
|
|
||||||
meta:set_string("src_time", 0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
|
||||||
local percent = math.floor(meta:get_float("fuel_time") /
|
|
||||||
meta:get_float("fuel_totaltime") * 100)
|
|
||||||
meta:set_string("infotext","Furnace active: "..percent.."%")
|
|
||||||
swap_node(pos,"default:furnace_active")
|
|
||||||
meta:set_string("formspec", default.get_furnace_active_formspec(pos, percent))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local fuel = nil
|
|
||||||
local afterfuel
|
|
||||||
local cooked = nil
|
|
||||||
local fuellist = inv:get_list("fuel")
|
|
||||||
local srclist = inv:get_list("src")
|
|
||||||
|
|
||||||
if srclist then
|
|
||||||
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
|
||||||
end
|
|
||||||
if fuellist then
|
|
||||||
fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
|
||||||
end
|
|
||||||
|
|
||||||
if not fuel or fuel.time <= 0 then
|
|
||||||
meta:set_string("infotext","Furnace is out of fuel")
|
|
||||||
swap_node(pos,"default:furnace")
|
|
||||||
meta:set_string("formspec", default.furnace_inactive_formspec)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if cooked.item:is_empty() then
|
|
||||||
if was_active then
|
|
||||||
meta:set_string("infotext","Furnace is empty")
|
|
||||||
swap_node(pos,"default:furnace")
|
|
||||||
meta:set_string("formspec", default.furnace_inactive_formspec)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
meta:set_string("fuel_totaltime", fuel.time)
|
|
||||||
meta:set_string("fuel_time", 0)
|
|
||||||
|
|
||||||
inv:set_stack("fuel", 1, afterfuel.items[1])
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("default:cobble", {
|
minetest.register_node("default:cobble", {
|
||||||
description = "Cobblestone",
|
description = "Cobblestone",
|
||||||
tiles = {"default_cobble.png"},
|
tiles = {"default_cobble.png"},
|
||||||
|
@ -147,7 +147,7 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
if minetest.setting_getbool("creative_mode") then
|
if minetest.setting_getbool("creative_mode") then
|
||||||
-- creative.set_creative_formspec(player, 0, 1)
|
-- creative.set_creative_formspec(player, 0, 1)
|
||||||
else
|
else
|
||||||
player:set_inventory_formspec(gui_suvival_form)
|
player:set_inventory_formspec(default.gui_suvival_form)
|
||||||
end
|
end
|
||||||
minetest.after(0.5,function()
|
minetest.after(0.5,function()
|
||||||
player:hud_set_hotbar_image("gui_hotbar.png")
|
player:hud_set_hotbar_image("gui_hotbar.png")
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
-- minetest/fire/init.lua
|
-- minetest/fire/init.lua
|
||||||
|
fire = {}
|
||||||
|
|
||||||
minetest.register_node("fire:basic_flame", {
|
minetest.register_node("fire:basic_flame", {
|
||||||
description = "Fire",
|
description = "Fire",
|
||||||
|
@ -1,100 +0,0 @@
|
|||||||
|
|
||||||
print (" ---- Overrider christmas_craft = true! ---- ")
|
|
||||||
|
|
||||||
minetest.after(0, function()
|
|
||||||
minetest.register_node(":default:dirt_with_grass", {
|
|
||||||
description = "Dirt with Grass",
|
|
||||||
tiles = {"snow.png", "default_dirt.png", "grass_w_snow_side.png"},
|
|
||||||
is_ground_content = true,
|
|
||||||
groups = {crumbly=3,soil=1},
|
|
||||||
drop = {
|
|
||||||
max_items = 3, items = {
|
|
||||||
{items = {'default:dirt'}, rarity = 0,},
|
|
||||||
{items = {'christmas_craft:snowball'}, rarity = 0,},
|
|
||||||
{items = {'snow:snowball_entity'}, rarity = 2,},
|
|
||||||
}},
|
|
||||||
sounds = default.node_sound_dirt_defaults({
|
|
||||||
footstep = {name="default_grass_footstep", gain=0.4},
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
|
|
||||||
-- remplace leaves (normal)
|
|
||||||
minetest.register_node(":default:leaves", {
|
|
||||||
description = "Leaves",
|
|
||||||
drawtype = "nodebox",
|
|
||||||
visual_scale = 1.3,
|
|
||||||
tiles = {"snow.png", "christmas_craft_leaves_top.png", "christmas_craft_leaves_side.png"},
|
|
||||||
paramtype = "light",
|
|
||||||
walkable = false,
|
|
||||||
groups = {snappy=3, leafdecay=3, flammable=2, leaves=1},
|
|
||||||
drop = {
|
|
||||||
max_items = 1,
|
|
||||||
items = {
|
|
||||||
{
|
|
||||||
-- player will get sapling with 1/40 chance
|
|
||||||
items = {'default:sapling'},
|
|
||||||
rarity = 40,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
-- player will get leaves only if he get no saplings,
|
|
||||||
-- this is because max_items is 1
|
|
||||||
items = {'default:leaves'},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
sounds = default.node_sound_leaves_defaults(),
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {
|
|
||||||
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
selection_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {
|
|
||||||
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
-- remplace jungleleaves
|
|
||||||
minetest.register_node(":default:jungletree_leaves", {
|
|
||||||
description = "Leaves",
|
|
||||||
drawtype = "nodebox",
|
|
||||||
visual_scale = 1.3,
|
|
||||||
tiles = {"snow.png", "christmas_craft_leaves_top.png", "christmas_craft_leaves_side.png"},
|
|
||||||
paramtype = "light",
|
|
||||||
walkable = false,
|
|
||||||
groups = {snappy=3, leafdecay=3, flammable=2, leaves=1},
|
|
||||||
drop = {
|
|
||||||
max_items = 1,
|
|
||||||
items = {
|
|
||||||
{
|
|
||||||
-- player will get sapling with 1/40 chance
|
|
||||||
items = {'moretrees:jungletree_sapling'},
|
|
||||||
rarity = 40,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
-- player will get leaves only if he get no saplings,
|
|
||||||
-- this is because max_items is 1
|
|
||||||
items = {'moretrees:jungletree_leaves_green'},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
sounds = default.node_sound_leaves_defaults(),
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {
|
|
||||||
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
selection_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {
|
|
||||||
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end)
|
|
||||||
|
|
||||||
print (" ---- Overrider christmas_craft [OK] ---- ")
|
|
||||||
|
|
@ -1,123 +0,0 @@
|
|||||||
--[[
|
|
||||||
Sprint mod for Minetest by GunshipPenguin
|
|
||||||
|
|
||||||
To the extent possible under law, the author(s)
|
|
||||||
have dedicated all copyright and related and neighboring rights
|
|
||||||
to this software to the public domain worldwide. This software is
|
|
||||||
distributed without any warranty.
|
|
||||||
]]
|
|
||||||
|
|
||||||
local players = {}
|
|
||||||
local staminaHud = {}
|
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
|
||||||
playerName = player:get_player_name()
|
|
||||||
players[playerName] = {
|
|
||||||
sprinting = false,
|
|
||||||
timeOut = 0,
|
|
||||||
stamina = SPRINT_STAMINA,
|
|
||||||
epressed = false,
|
|
||||||
hud = player:hud_add({
|
|
||||||
hud_elem_type = "statbar",
|
|
||||||
position = {x=0.5,y=1},
|
|
||||||
size = {x=24, y=24},
|
|
||||||
text = "stamina.png",
|
|
||||||
number = 20,
|
|
||||||
alignment = {x=0,y=1},
|
|
||||||
offset = {x=-320, y=-186},
|
|
||||||
}
|
|
||||||
),
|
|
||||||
}
|
|
||||||
end)
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
|
||||||
playerName = player:get_player_name()
|
|
||||||
players[playerName] = nil
|
|
||||||
end)
|
|
||||||
minetest.register_globalstep(function(dtime)
|
|
||||||
--Get the gametime
|
|
||||||
local gameTime = minetest.get_gametime()
|
|
||||||
|
|
||||||
--Loop through all connected players
|
|
||||||
for playerName,playerInfo in pairs(players) do
|
|
||||||
local player = minetest.get_player_by_name(playerName)
|
|
||||||
if player ~= nil then
|
|
||||||
--Check if they are pressing the e key
|
|
||||||
players[playerName]["epressed"] = player:get_player_control()["aux1"]
|
|
||||||
|
|
||||||
--Stop sprinting if the player is pressing the LMB or RMB
|
|
||||||
if player:get_player_control()["LMB"] or player:get_player_control()["RMB"] then
|
|
||||||
setSprinting(playerName, false)
|
|
||||||
playerInfo["timeOut"] = 3
|
|
||||||
end
|
|
||||||
|
|
||||||
--If the player is sprinting, create particles behind him/her
|
|
||||||
if playerInfo["sprinting"] == true and gameTime % 0.1 == 0 then
|
|
||||||
local numParticles = math.random(1, 2)
|
|
||||||
local playerPos = player:getpos()
|
|
||||||
local playerNode = minetest.get_node({x=playerPos["x"], y=playerPos["y"]-1, z=playerPos["z"]})
|
|
||||||
if playerNode["name"] ~= "air" then
|
|
||||||
for i=1, numParticles, 1 do
|
|
||||||
minetest.add_particle({
|
|
||||||
pos = {x=playerPos["x"]+math.random(-1,1)*math.random()/2,y=playerPos["y"]+0.1,z=playerPos["z"]+math.random(-1,1)*math.random()/2},
|
|
||||||
vel = {x=0, y=5, z=0},
|
|
||||||
acc = {x=0, y=-13, z=0},
|
|
||||||
expirationtime = math.random(),
|
|
||||||
size = math.random()+0.5,
|
|
||||||
collisiondetection = true,
|
|
||||||
vertical = false,
|
|
||||||
texture = "default_dirt.png",
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Adjust player states
|
|
||||||
if players[playerName]["epressed"] == true and playerInfo["timeOut"] == 0 then --Stopped
|
|
||||||
setSprinting(playerName, true)
|
|
||||||
elseif players[playerName]["epressed"] == false then
|
|
||||||
setSprinting(playerName, false)
|
|
||||||
end
|
|
||||||
|
|
||||||
if playerInfo["timeOut"] > 0 then
|
|
||||||
playerInfo["timeOut"] = playerInfo["timeOut"] - dtime
|
|
||||||
if playerInfo["timeOut"] < 0 then
|
|
||||||
playerInfo["timeOut"] = 0
|
|
||||||
end
|
|
||||||
else
|
|
||||||
--Lower the player's stamina by dtime if he/she is sprinting and set his/her state to 0 if stamina is zero
|
|
||||||
if playerInfo["sprinting"] == true then
|
|
||||||
playerInfo["stamina"] = playerInfo["stamina"] - dtime
|
|
||||||
if playerInfo["stamina"] <= 0 then
|
|
||||||
playerInfo["stamina"] = 0
|
|
||||||
setSprinting(playerName, false)
|
|
||||||
minetest.chat_send_player(playerName, "Your sprint stamina has run out")
|
|
||||||
playerInfo["timeOut"] = 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Increase player's stamina if he/she is not sprinting and his/her stamina is less than SPRINT_STAMINA
|
|
||||||
if playerInfo["sprinting"] == false and playerInfo["stamina"] < SPRINT_STAMINA then
|
|
||||||
playerInfo["stamina"] = playerInfo["stamina"] + dtime
|
|
||||||
end
|
|
||||||
|
|
||||||
--Update the players's hud sprint stamina bar
|
|
||||||
local numBars = (playerInfo["stamina"]/SPRINT_STAMINA)*20
|
|
||||||
player:hud_change(playerInfo["hud"], "number", numBars)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
function setSprinting(playerName, sprinting) --Sets the state of a player (0=stopped/moving, 1=sprinting)
|
|
||||||
local player = minetest.get_player_by_name(playerName)
|
|
||||||
if players[playerName] then
|
|
||||||
players[playerName]["sprinting"] = sprinting
|
|
||||||
if sprinting == true then
|
|
||||||
player:set_physics_override({speed=SPRINT_SPEED,jump=SPRINT_JUMP})
|
|
||||||
elseif sprinting == false then
|
|
||||||
player:set_physics_override({speed=1.0,jump=1.0})
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user