Merge branch 'lantern' into dev

This commit is contained in:
Aaron Suen 2022-10-19 22:37:00 -04:00
commit 29e1b82506
12 changed files with 212 additions and 24 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 KiB

After

Width:  |  Height:  |  Size: 276 KiB

View File

@ -9,20 +9,12 @@ ISSUES-DOCS: Issues related to documentation
# # # # # # # # # # # #
#### # #### # ###### ###### # # ####
- Official screenshot missing:
- Thatch
- Wicker
- Raked sand/dirt/gravel/humus
- Add a credits file with more extensive/specific credits, including
non-copyrightable contributions to core project...?
- Need to clean out issues in wishlist.
- Put some issues unlikely to be resolved on ice.
- Consider migrating NC's Weblate into the hosted instance that
Minetest Engine uses?
- Documentation about accessibility
- Accessibility features
- All significant actions have sounds

View File

@ -9,11 +9,6 @@ ISSUES-DOCS: Issues related to media/assets, or visuals/effects
# # # # # # # # # # # #
#### # #### # ###### ###### # # ####
- Publish "base" texturepack to CDB
- Allows servers to use "server texturepacks" with impunity
without breaking the basic principle of players having
access to all texture options.
- Sound check
- add some kind of falling sound (very low pitched dig noise)
to falling nodes, to give players a chance to jump away from

Binary file not shown.

View File

@ -127,17 +127,16 @@ local function lightsrc(stack)
return def.light_source or 0
end
local function player_wield_light_pos(player)
local function player_wield_light_pos(player, speed)
local pos = player:get_pos()
pos.y = pos.y + player:get_properties().eye_height
if player:get_player_control().up then
local ld = player:get_look_dir()
pos.x = pos.x + ld.x
pos.z = pos.z + ld.z
end
local ld = player:get_look_dir()
speed = player:get_player_control().up and speed or 0.5
pos.x = pos.x + ld.x * speed
pos.z = pos.z + ld.z * speed
return vector.round(pos)
end
local function player_wield_light(player)
local function player_wield_light(player, data)
local glow = 0
local srcidx, srcstack
for idx, stack in pairs(player:get_inventory():get_list("main")) do
@ -149,12 +148,13 @@ local function player_wield_light(player)
end
end
if glow < 1 then return end
local pos = player_wield_light_pos(player)
local speed = data and data.physics and data.physics.speed or 1
local pos = player_wield_light_pos(player, speed)
local pname = player:get_player_name()
return dynamic_light_add(pos, glow, function()
local pl = minetest.get_player_by_name(pname)
if not pl then return end
local pp = player_wield_light_pos(pl)
local pp = player_wield_light_pos(pl, speed)
if not vector.equals(pos, pp) then return end
return pl:get_inventory():get_stack("main", srcidx)
:get_name() == srcstack
@ -163,9 +163,9 @@ end
nodecore.register_playerstep({
label = "player wield light",
action = function(player)
action = function(player, data)
if nodecore.player_visible(player) then
return player_wield_light(player)
return player_wield_light(player, data)
end
end
})

View File

@ -0,0 +1,88 @@
-- LUALOCALS < ---------------------------------------------------------
local math, minetest, nodecore, pairs, string
= math, minetest, nodecore, pairs, string
local math_floor, string_format
= math.floor, string.format
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
local discharge_rate = 30
local charge_per_level = discharge_rate * 200
local max_charge = charge_per_level * 8 - 1
local waters = {}
minetest.after(0, function()
for k, v in pairs(minetest.registered_nodes) do
if v.groups and v.groups.water and v.groups.water > 0 then
waters[k] = true
end
end
end)
local function iswater(pos) return waters[minetest.get_node(pos).name] end
local function iswet(pos)
if iswater(pos) then return true end
local p = {x = pos.x, y = pos.y + 1, z = pos.z}
return iswater(p)
end
local function floateq(a, b)
if not (a and b) then return true end
if a == 0 and b == 0 then return a == b end
local ratio = a / b
return ratio > 0.999 and ratio < 1.001
end
local function floatrpt(a, b)
if floateq(a, b) then return string_format("%0.2f", a) end
return string.format("%0.2f -> %0.2f", a, b)
end
local function getlevel(name)
return minetest.get_item_group(name, modname) - 1
end
nodecore.register_aism({
label = "lantern charge",
interval = 2,
arealoaded = 14,
itemnames = "group:" .. modname,
action = function(stack, data)
local pos = data.pos or data.player and data.player:get_pos()
local rate = (nodecore.lux_soak_rate(pos) or 0)
- discharge_rate * (iswet(pos) and 2 or 1)
local oldname = stack:get_name()
local meta = stack:get_meta()
local oldrate = meta:get_float("rate")
local oldqty = meta:get_float("qty")
local oldtime = meta:get_float("time")
local now = nodecore.gametime
local qty = (oldtime == 0)
and (getlevel(oldname) * charge_per_level)
or (oldqty + oldrate * (now - oldtime))
if qty <= 0 then
qty = 0
if rate < 0 then rate = 0 end
end
if qty >= max_charge then
qty = max_charge
if rate > 0 then rate = 0 end
end
local level = math_floor(qty / charge_per_level)
local name = modname .. ":lamp" .. level
if name == oldname and floateq(rate, oldrate) then return end
nodecore.log("action", string_format("lantern level %s rate %s charge %s at %s",
floatrpt(getlevel(oldname), level),
floatrpt(oldrate, rate), floatrpt(oldqty, qty),
minetest.pos_to_string(pos, 0)))
stack:set_name(name)
meta:set_float("rate", rate)
meta:set_float("qty", qty)
meta:set_float("time", now)
return stack
end
})

36
mods/nc_lantern/craft.lua Normal file
View File

@ -0,0 +1,36 @@
-- LUALOCALS < ---------------------------------------------------------
local minetest, nodecore
= minetest, nodecore
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
nodecore.register_craft({
label = "assemble lantern",
normal = {x = 1},
indexkeys = {"nc_optics:glass_opaque"},
nodes = {
{match = "nc_optics:glass_opaque", replace = "air"},
{x = -1, match = "nc_tote:handle", replace = "air"},
},
items = {
{name = modname .. ":lamp0"}
}
})
nodecore.register_craft({
label = "break apart lantern",
action = "pummel",
toolgroups = {choppy = 5},
indexkeys = {"group:" .. modname},
nodes = {
{
match = {groups = {[modname] = true}},
replace = "air"
}
},
items = {
{name = "nc_lode:bar_annealed 2", count = 4, scatter = 5},
{name = "nc_optics:glass_crude", scatter = 5}
}
})

21
mods/nc_lantern/hints.lua Normal file
View File

@ -0,0 +1,21 @@
-- LUALOCALS < ---------------------------------------------------------
local minetest, nodecore
= minetest, nodecore
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
nodecore.register_hint("assemble a lantern from a tote handle",
"assemble lantern",
{"nc_tote:handle", "nc_optics:glass_opaque"}
)
nodecore.register_hint("charge a lantern",
"group:" .. modname .. "_charged",
"assemble lantern"
)
nodecore.register_hint("fully charge a lantern",
"group:" .. modname .. "_full",
"assemble lantern"
)

9
mods/nc_lantern/init.lua Normal file
View File

@ -0,0 +1,9 @@
-- LUALOCALS < ---------------------------------------------------------
local include
= include
-- LUALOCALS > ---------------------------------------------------------
include("node")
include("craft")
include("charge")
include("hints")

2
mods/nc_lantern/mod.conf Normal file
View File

@ -0,0 +1,2 @@
name = nc_lantern
depends = nc_api_all, nc_lux, nc_optics, nc_tote

45
mods/nc_lantern/node.lua Normal file
View File

@ -0,0 +1,45 @@
-- LUALOCALS < ---------------------------------------------------------
local math, minetest, nodecore
= math, minetest, nodecore
local math_ceil
= math.ceil
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
local txr_sides = "(nc_lode_annealed.png^[mask:nc_tote_sides.png)"
local txr_handle = "(nc_lode_annealed.png^nc_tote_knurl.png)"
local txr_top = txr_handle .. "^[transformFX^[mask:nc_tote_top.png^[transformR90^" .. txr_sides
local function reg(level)
return minetest.register_node(modname .. ":lamp" .. level, {
description = "Lantern",
drawtype = "mesh",
mesh = "nc_tote_handle.obj",
paramtype = "light",
tiles = {
txr_sides,
txr_sides,
txr_top,
txr_handle,
"nc_optics_glass_frost.png^(nc_lux_base.png^[opacity:"
.. (level * 36) .. ")"
},
backface_culling = true,
use_texture_alpha = "clip",
groups = {
[modname] = level + 1,
[modname .. "_charged"] = level > 0 and level or nil,
[modname .. "_full"] = level == 7 and 1 or nil,
snappy = 1,
lux_emit = math_ceil(level / 2),
},
node_placement_prediction = "nc_items:stack",
place_as_item = true,
stack_max = 1,
light_source = level * 2,
sounds = nodecore.sounds("nc_lode_annealed")
})
end
for i = 0, 7 do reg(i) end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 39 KiB