Improvement wieldview and other minor changes

This commit is contained in:
MoNTE48 2019-07-10 19:04:17 +02:00
parent dfa7d2df23
commit b40d176021
5 changed files with 32 additions and 78 deletions

View File

@ -118,10 +118,9 @@ core.builtin_auth_handler = {
} }
end, end,
create_auth = function(name, password) create_auth = function(name, password)
core.log("action", "Adding password entry for player " .. name) core.log("action", "[AUTH] Adding password entry for player " .. name)
assert(type(name) == "string") assert(type(name) == "string")
assert(type(password) == "string") assert(type(password) == "string")
core.log('info', "Built-in authentication handler adding player '"..name.."'")
core.auth_table[name] = { core.auth_table[name] = {
password = password, password = password,
privileges = core.string_to_privs(core.settings:get("default_privs")), privileges = core.string_to_privs(core.settings:get("default_privs")),
@ -132,17 +131,16 @@ core.builtin_auth_handler = {
assert(type(name) == "string") assert(type(name) == "string")
assert(type(password) == "string") assert(type(password) == "string")
if not core.auth_table[name] then if not core.auth_table[name] then
core.log("action", "Setting password for new player " .. name) core.log("action", "[AUTH] Setting password for new player " .. name)
core.builtin_auth_handler.create_auth(name, password) core.builtin_auth_handler.create_auth(name, password)
else else
core.log("action", "Setting password for existing player " .. name ) core.log("action", "[AUTH] Setting password for existing player " .. name)
core.log('info', "Built-in authentication handler setting password of player '"..name.."'")
core.auth_table[name].password = password core.auth_table[name].password = password
end end
return true return true
end, end,
set_privileges = function(name, privileges) set_privileges = function(name, privileges)
core.log("action", "Setting privileges for player " .. name ) core.log("action", "[AUTH] Setting privileges for player " .. name)
assert(type(name) == "string") assert(type(name) == "string")
assert(type(privileges) == "table") assert(type(privileges) == "table")
if not core.auth_table[name] then if not core.auth_table[name] then
@ -154,17 +152,16 @@ core.builtin_auth_handler = {
core.notify_authentication_modified(name) core.notify_authentication_modified(name)
end, end,
reload = function() reload = function()
core.log("action", "Reading authentication data from disk") core.log("action", "[AUTH] Writing authentication data to disk")
read_auth_file() read_auth_file()
return true return true
end, end,
commit = function() commit = function()
core.log("action", "Writing authentication data to disk") core.log("action", "[AUTH] Writing authentication data to disk")
save_auth_file() save_auth_file()
return true return true
end, end,
record_login = function(name) record_login = function(name)
core.log("action", "Recording login time for player " .. name )
assert(type(name) == "string") assert(type(name) == "string")
assert(core.auth_table[name]).last_login = os.time() assert(core.auth_table[name]).last_login = os.time()
end, end,
@ -219,21 +216,21 @@ core.register_on_prejoinplayer(function(name, ip)
local name_lower = name:lower() local name_lower = name:lower()
for k in pairs(auth) do for k in pairs(auth) do
if k:lower() == name_lower then if k:lower() == name_lower then
return string.format("\nCannot create new player called '%s'. ".. return string.format("\nYou can not register as '%s'! "..
"Another account called '%s' is already registered. ".. "Another player called '%s' is already registered. "..
"Please check the spelling if it's your account ".. "Please check the spelling if it's your account "..
"or use a different nickname.", name, k) "or use a different name.", name, k)
end end
end end
end) end)
-- Autosave -- Autosave
if not core.is_singleplayer() then if not core.is_singleplayer() then
local save_interval = tonumber(core.settings:get("server_map_save_interval")) local save_interval = 600
local function auto_save() local function auto_save()
core.auth_commit() core.auth_commit()
core.after(save_interval * 3, auto_save) core.after(save_interval, auto_save)
end end
core.after(60, auto_save) core.after(save_interval, auto_save)
end end

View File

@ -592,27 +592,27 @@ function core.item_eat(hp_change, replace_with_item)
return function(itemstack, user, pointed_thing) -- closure return function(itemstack, user, pointed_thing) -- closure
if user then if user then
local pos = user:get_pos() local pos = user:get_pos()
pos.y = pos.y + 1.5 pos.y = pos.y + 1.3
local itemname = itemstack:get_name() local itemname = itemstack:get_name()
local texture = core.registered_items[itemname].inventory_image local texture = core.registered_items[itemname].inventory_image
core.sound_play("player_eat", {pos = pos, max_hear_distance = 10, gain = 0.3}) local dir = user:get_look_dir()
core.add_particlespawner({ core.add_particlespawner({
amount = 20, amount = 20,
time = 0.1, time = 0.1,
minpos = {x = pos.x, y = pos.y, z = pos.z}, minpos = pos,
maxpos = {x = pos.x, y = pos.y, z = pos.z}, maxpos = pos,
minvel = {x = -1, y = 1, z = -1}, minvel = {x = dir.x - 1, y = 2, z = dir.z - 1},
maxvel = {x = 1, y = 2, z = 1}, maxvel = {x = dir.x + 1, y = 2, z = dir.z + 1},
minacc = {x = 0, y = -5, z = 0}, minacc = {x = 0, y = -5, z = 0},
maxacc = {x = 0, y = -9, z = 0}, maxacc = {x = 0, y = -9, z = 0},
minexptime = 1, minexptime = 1,
maxexptime = 1, maxexptime = 1,
minsize = 1, minsize = 1,
maxsize = 1, maxsize = 1,
collisiondetection = true,
vertical = false, vertical = false,
texture = texture, texture = texture,
}) })
core.sound_play("player_eat", {pos = pos, max_hear_distance = 10, gain = 0.3})
return core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing) return core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
end end
end end

View File

@ -1,14 +1,8 @@
MultiCraft Game mod: wieldview MultiCraft Game mod: wieldview
=========================== ===========================
Makes hand wielded items visible to other players.
Authors of source code Authors of source code
---------------------- ----------------------
Copyright (C) 2013-2019 Stuart Jones - LGPLv3.0+ (with the permission of the author) Copyright (C) 2013-2019 Stuart Jones - LGPLv3.0+ (with the permission of the author)
Makes hand wielded items visible to other players.
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.

View File

@ -7,21 +7,19 @@ local wield_cubes = {}
local wield_items = {} local wield_items = {}
local wield_cycle = {} local wield_cycle = {}
wieldview = {
transform = {},
}
dofile(minetest.get_modpath(minetest.get_current_modname()).."/transform.lua")
local function init_wield_items() local function init_wield_items()
for name, def in pairs(minetest.registered_items) do for name, def in pairs(minetest.registered_items) do
if def.inventory_image and def.inventory_image ~= "" then if def.inventory_image and def.inventory_image ~= "" then
wield_tiles[name] = def.inventory_image wield_tiles[name] = def.inventory_image
elseif def.tiles and type(def.tiles[1]) == "string" and elseif def.tiles and type(def.tiles[1]) == "string" and
def.tiles[1] ~= "" and def.drawtype and def.tiles[1] ~= "" and def.drawtype and
(def.drawtype == "normal" or def.drawtype == "allfaces" or (def.drawtype == "normal" or def.drawtype:sub(1,8) == "allfaces" or
def.drawtype == "glasslike" or def.drawtype == "liquid") then def.drawtype:sub(1,5) == "glass" or def.drawtype == "liquid") then
wield_cubes[name] = def.tiles[1] if not (def.tiles[3] ~= "" and type(def.tiles[3]) == "string") then
wield_cubes[name] = def.tiles[1]
else
wield_cubes[name] = def.tiles[3]
end
end end
end end
end end
@ -31,20 +29,9 @@ local function update_player_visuals(player, item)
local animation = player_api.get_animation(player) or {} local animation = player_api.get_animation(player) or {}
local textures = animation.textures or {} local textures = animation.textures or {}
local skin = textures[1] and textures[1] or "character.png" local skin = textures[1] and textures[1] or "character.png"
local wield_tile = wield_tiles[item] local wield_tile = wield_tiles[item] or "blank.png"
if wield_tile then if not minetest.registered_tools[item] then
-- Get item image transformation, first from group, then from transform.lua wield_tile = wield_tile.."^[transformR270"
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
wield_tile = wield_tile.."^[transform"..tostring(transform)
end
else
wield_tile = "blank.png"
end end
local wield_cube = wield_cubes[item] or "blank.png" local wield_cube = wield_cubes[item] or "blank.png"
if has_armor then if has_armor then
@ -80,7 +67,7 @@ local function update_wielded_item(dtime, name)
wield_cycle[name] = 0 wield_cycle[name] = 0
end end
if not minetest.is_singleplayer() then if PLATFORM ~= "Android" or PLATFORM ~= "iOS" then
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
if name then if name then

View File

@ -1,24 +0,0 @@
-- Wielded Item Transformations - http://dev.minetest.net/texture
wieldview.transform = {
["default:torch"]="R270",
["mesecons_torch:mesecon_torch_on"]="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",
}