First version

master
Lars Mueller 2020-06-12 21:02:13 +02:00
commit 936086fe26
3 changed files with 71 additions and 0 deletions

8
Readme.md Normal file
View File

@ -0,0 +1,8 @@
# Online Craftguide CSM
The clientside mod part of the online craftguide mod. Written by Lars Mueller aka appguru(eu) and licensed under the MIT license.
## Usage
Enable the mod like any other CSM using a Minetest 5.3 client with [`minetest#10003`](https://github.com/minetest/minetest/pull/10003).
On server join, it will show a "Rendering" bar and write inventory images to the `images` folder inside it's mod directory, given that it has sufficient permissions.

58
init.lua Normal file
View File

@ -0,0 +1,58 @@
online_craftguide = {}
setfenv(1, setmetatable(online_craftguide, {__index = _G}))
if minetest.get_csm_restrictions().read_itemdefs then
minetest.log("Unable to render inventory images as read_itemdefs is restricted")
return
end
if not minetest.get_item_defs or not minetest.store_texture then
minetest.log("The online_craftguide CSM requires Minetest 5.3 with PR#10003 merged")
return
end
function render(per_step)
if not minetest.localplayer then
minetest.after(0, render)
return
end
per_step = per_step or 10
text_id = minetest.localplayer:hud_add{
hud_elem_type = "text",
name = "online_craftguide:rendering_progress",
position = {x=0.5, y=0.5},
text = "Rendering... 0%",
number = 0xffffff,
z_index = 1000
}
statbar_id = minetest.localplayer:hud_add{
hud_elem_type = "image",
text = "progress_bar_bg.png",
position = {x = 0.5, y = 0.5},
scale = {x=1, y=1},
z_index = 900
}
local itemdefs = minetest.get_item_defs()
itemdefs[""] = nil
local total = 0
for _ in pairs(itemdefs) do total = total + 1 end
local done = 0
minetest.register_globalstep(function()
for name, def in pairs(itemdefs) do
if not minetest.store_texture("[item:"..def.name, "images/"..name:gsub("%:", "_")..".png") then
minetest.log("Storing texture for "..def.name.." failed")
end
itemdefs[name] = nil
done = done + 1
local proportion = done/total
minetest.localplayer:hud_change(text_id, "text", "Rendering... "..math.floor(proportion * 100).."%")
minetest.localplayer:hud_change(statbar_id, "text", "progress_bar_bg.png^(progress_bar.png^([combine:256x48:"..math.floor(proportion * 256)..",0=(progress_bar.png^[noalpha)^[colorize:#4A412A:255)^[makealpha:74,65,42)")
if done >= per_step then
break
end
end
if done == total then
minetest.localplayer:hud_remove(text_id)
minetest.localplayer:hud_remove(statbar_id)
end
end)
end
minetest.after(0, render)
setfenv(1, _G)

5
mod.conf Normal file
View File

@ -0,0 +1,5 @@
name = online_craftguide
title = Online Craftguide
author = LMD aka appguru(eu)
description = Stores inventory images on server join for online craftguides