write something there

This commit is contained in:
N-Nachtigal 2025-05-04 16:01:41 +02:00
commit b4b6c08f4f
8546 changed files with 309825 additions and 0 deletions

View file

@ -0,0 +1,27 @@
[mod] visible wielded items [wieldview]
=======================================
Depends on: 3d_armor
Makes hand wielded items visible to other players.
default settings: [minetest.conf]
# Set number of seconds between visible wielded item updates.
wieldview_update_time = 2
# Show nodes as tiles, disabled by default
wieldview_node_tiles = false
Info for modders
################
Wield image transformation: To apply a simple transformation to the item in
hand, add the group “wieldview_transform” to the item definition. The group
rating equals one of the numbers used for the [transform texture modifier
of the Lua API.
Disabling the feature in-game: If you want to hide the wielded item
you can add an INT metadata to the player called "show_wielded_item" and set
it to 2 (any other value will show the wielded item again).

View file

@ -0,0 +1,215 @@
local f = string.format
local node_tiles = minetest.settings:get_bool("wieldview_node_tiles")
if not node_tiles then
node_tiles = false
minetest.settings:set("wieldview_node_tiles", "false")
end
-- https://github.com/minetest/minetest/blob/9fc018ded10225589d2559d24a5db739e891fb31/doc/lua_api.txt#L453-L462
local function escape_texture(texturestring)
-- store in a variable so we don't return both rvs of gsub
local v = texturestring:gsub("%^", "\\^"):gsub(":", "\\:")
return v
end
local function memoize(func)
local memo = {}
return function(arg)
if arg == nil then
return func(arg)
end
local rv = memo[arg]
if not rv then
rv = func(arg)
memo[arg] = rv
end
return rv
end
end
local function is_vertical_frames(animation)
return (
animation.type == "vertical_frames" and
animation.aspect_w and
animation.aspect_h
)
end
local function get_single_frame(animation, image_name)
return ("[combine:%ix%i^[noalpha^[colorize:#FFF:255^[mask:%s"):format(
animation.aspect_w,
animation.aspect_h,
image_name
)
end
local function is_sheet_2d(animation)
return (
animation.type == "sheet_2d" and
animation.frames_w and
animation.frames_h
)
end
local function get_sheet_2d(animation, image_name)
return ("%s^[sheet:%ix%i:0,0"):format(
image_name,
animation.frames_w,
animation.frames_h
)
end
local get_image_from_tile = memoize(function(tile)
if type(tile) == "string" then
return tile
elseif type(tile) == "table" then
local image_name
if type(tile.image) == "string" then
image_name = tile.image
elseif type(tile.name) == "string" then
image_name = tile.name
end
if image_name then
local animation = tile.animation
if animation then
if is_vertical_frames(animation) then
return get_single_frame(animation, image_name)
elseif is_sheet_2d(animation) then
return get_sheet_2d(animation, image_name)
end
end
return image_name
end
end
return "blank.png"
end)
local function get_image_cube(tiles)
if #tiles >= 6 then
return minetest.inventorycube(
get_image_from_tile(tiles[1] or "no_texture.png"),
get_image_from_tile(tiles[6] or "no_texture.png"),
get_image_from_tile(tiles[3] or "no_texture.png")
)
elseif #tiles == 5 then
return minetest.inventorycube(
get_image_from_tile(tiles[1] or "no_texture.png"),
get_image_from_tile(tiles[5] or "no_texture.png"),
get_image_from_tile(tiles[3] or "no_texture.png")
)
elseif #tiles == 4 then
return minetest.inventorycube(
get_image_from_tile(tiles[1] or "no_texture.png"),
get_image_from_tile(tiles[4] or "no_texture.png"),
get_image_from_tile(tiles[3] or "no_texture.png")
)
elseif #tiles == 3 then
return minetest.inventorycube(
get_image_from_tile(tiles[1] or "no_texture.png"),
get_image_from_tile(tiles[3] or "no_texture.png"),
get_image_from_tile(tiles[3] or "no_texture.png")
)
elseif #tiles == 2 then
return minetest.inventorycube(
get_image_from_tile(tiles[1] or "no_texture.png"),
get_image_from_tile(tiles[2] or "no_texture.png"),
get_image_from_tile(tiles[2] or "no_texture.png")
)
elseif #tiles == 1 then
return minetest.inventorycube(
get_image_from_tile(tiles[1] or "no_texture.png"),
get_image_from_tile(tiles[1] or "no_texture.png"),
get_image_from_tile(tiles[1] or "no_texture.png")
)
end
return "blank.png"
end
local function is_normal_node(drawtype)
return (
drawtype == "normal" or
drawtype == "allfaces" or
drawtype == "allfaces_optional" or
drawtype == "glasslike" or
drawtype == "glasslike_framed" or
drawtype == "glasslike_framed_optional" or
drawtype == "liquid"
)
end
armor.get_wield_image = memoize(function(item)
item = ItemStack(item)
if item:is_empty() then
return "blank.png"
end
local def = item:get_definition()
if not def then
return "unknown_item.png"
end
local meta = item:get_meta()
local color = meta:get("color") or def.color
local image = "blank.png"
if def.wield_image and def.wield_image ~= "" then
local parts = {def.wield_image}
if color then
parts[#parts + 1] = f("[colorize:%s:alpha", escape_texture(color))
end
if def.wield_overlay then
parts[#parts + 1] = def.wield_overlay
end
image = table.concat(parts, "^")
elseif def.inventory_image and def.inventory_image ~= "" then
local parts = {def.inventory_image}
if color then
parts[#parts + 1] = f("[colorize:%s:alpha", escape_texture(color))
end
if def.inventory_overlay then
parts[#parts + 1] = def.inventory_overlay
end
image = table.concat(parts, "^")
elseif def.type == "node" then
if def.drawtype == "nodebox" or def.drawtype == "mesh" then
image = "blank.png"
else
local tiles = def.tiles
if type(tiles) == "string" then
image = get_image_from_tile(tiles)
elseif type(tiles) == "table" then
if is_normal_node(def.drawtype) and node_tiles then
image = get_image_cube(tiles)
else
image = get_image_from_tile(tiles[1])
end
end
end
end
return image
end)

View file

@ -0,0 +1,77 @@
local time = 0
local update_time = tonumber(minetest.settings:get("wieldview_update_time"))
if not update_time then
update_time = 2
minetest.settings:set("wieldview_update_time", tostring(update_time))
end
wieldview = {
wielded_item = {},
transform = {},
}
dofile(minetest.get_modpath(minetest.get_current_modname()).."/get_texture.lua")
dofile(minetest.get_modpath(minetest.get_current_modname()).."/transform.lua")
wieldview.get_item_texture = function(self, item)
local texture = "blank.png"
if item ~= "" then
texture = armor.get_wield_image(item)
-- Get item image transformation, first from group, then from transform.lua
local transform = minetest.get_item_group(item, "wieldview_transform")
if transform == 0 then
transform = wieldview.transform[item]
end
if transform then
-- This actually works with groups ratings because transform1, transform2, etc.
-- have meaning and transform0 is used for identidy, so it can be ignored
texture = texture.."^[transform"..tostring(transform)
end
end
return texture
end
wieldview.update_wielded_item = function(self, player)
if not player then
return
end
local name = player:get_player_name()
local stack = player:get_wielded_item()
local item = stack:get_name()
if not item then
return
end
if self.wielded_item[name] then
if player:get_meta():get_int("show_wielded_item") == 2 then
item = ""
end
if self.wielded_item[name] == item then
return
end
armor.textures[name].wielditem = self:get_item_texture(item)
armor:update_player_visuals(player)
end
self.wielded_item[name] = item
end
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
wieldview.wielded_item[name] = ""
minetest.after(0, function(pname)
local pplayer = minetest.get_player_by_name(pname)
if pplayer then
wieldview:update_wielded_item(pplayer)
end
end, name)
end)
minetest.register_globalstep(function(dtime)
time = time + dtime
if time > update_time then
for _,player in ipairs(minetest.get_connected_players()) do
wieldview:update_wielded_item(player)
end
time = 0
end
end)

View file

@ -0,0 +1,3 @@
name = wieldview
depends = 3d_armor
description = Makes hand wielded items visible to other players.

View file

@ -0,0 +1,24 @@
-- Wielded Item Transformations - http://dev.minetest.net/texture
wieldview.transform = {
["default:torch"]="R270",
["default:sapling"]="R270",
["flowers:dandelion_white"]="R270",
["flowers:dandelion_yellow"]="R270",
["flowers:geranium"]="R270",
["flowers:rose"]="R270",
["flowers:tulip"]="R270",
["flowers:viola"]="R270",
["bucket:bucket_empty"]="R270",
["bucket:bucket_water"]="R270",
["bucket:bucket_lava"]="R270",
["screwdriver:screwdriver"]="R270",
["screwdriver:screwdriver1"]="R270",
["screwdriver:screwdriver2"]="R270",
["screwdriver:screwdriver3"]="R270",
["screwdriver:screwdriver4"]="R270",
["vessels:glass_bottle"]="R270",
["vessels:drinking_glass"]="R270",
["vessels:steel_bottle"]="R270",
}