2025-01-25 21:22:03 +03:00
|
|
|
--[[
|
|
|
|
Copyright 2025 Andrey Stepanov
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
]]--
|
|
|
|
|
|
|
|
local storage = minetest.get_mod_storage()
|
|
|
|
|
|
|
|
local dig_penalty_storage = {}
|
|
|
|
if storage:contains("dig_penalty") then
|
|
|
|
dig_penalty_storage = minetest.deserialize(
|
|
|
|
storage:get_string("dig_penalty")
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2025-01-26 13:14:57 +03:00
|
|
|
local speed_factor_storage = {}
|
|
|
|
if storage:contains("speed_factor") then
|
|
|
|
speed_factor_storage = minetest.deserialize(
|
|
|
|
storage:get_string("speed_factor")
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2025-01-25 21:22:03 +03:00
|
|
|
|
|
|
|
---@param dig_penalty number
|
|
|
|
local function set_dig_penalty(player, dig_penalty)
|
|
|
|
local pname = player:get_player_name()
|
|
|
|
local prev_dig_penalty = dig_penalty_storage[pname] or 1
|
|
|
|
if dig_penalty == prev_dig_penalty then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
dig_penalty_storage[pname] = dig_penalty
|
|
|
|
storage:set_string(
|
|
|
|
"dig_penalty",
|
|
|
|
minetest.serialize(
|
|
|
|
dig_penalty_storage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
local inv = player:get_inventory()
|
|
|
|
local inv_size = inv:get_size("main")
|
|
|
|
for i = 1, inv_size do
|
|
|
|
local stack = inv:get_stack("main", i)
|
|
|
|
if not stack:is_empty() then
|
|
|
|
toolcap_monoids.dig_speed:del_change(stack, "medical")
|
|
|
|
if dig_penalty ~= 1 then
|
|
|
|
toolcap_monoids.dig_speed:add_change(stack, dig_penalty, "medical")
|
|
|
|
end
|
|
|
|
inv:set_stack("main", i, stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hand_monoid.monoid:del_change(player, "medical")
|
|
|
|
local hand_caps = table.copy(hand_monoid.monoid_def.identity.groupcaps)
|
|
|
|
if dig_penalty ~= 1 then
|
|
|
|
for group, cap in pairs(hand_caps) do
|
|
|
|
if cap.times then
|
|
|
|
for i, _ in pairs(cap.times) do
|
|
|
|
cap.times[i] = cap.times[i] * dig_penalty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
hand_monoid.monoid:add_change(
|
|
|
|
player,
|
|
|
|
{
|
|
|
|
groupcaps = hand_caps
|
|
|
|
},
|
|
|
|
"medical"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_on_newplayer(
|
|
|
|
function(player)
|
|
|
|
hand_monoid.monoid:add_change(
|
|
|
|
player,
|
|
|
|
{
|
|
|
|
groupcaps = table.copy(hand_monoid.monoid_def.identity.groupcaps)
|
|
|
|
},
|
|
|
|
"medical"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_on_player_inventory_action(
|
|
|
|
function(
|
|
|
|
player,
|
|
|
|
action,
|
|
|
|
inventory,
|
|
|
|
inventory_info
|
|
|
|
)
|
|
|
|
if action == "put" then
|
|
|
|
local stack = inventory_info.stack
|
|
|
|
local dig_penalty = dig_penalty_storage[player:get_player_name()] or 1
|
|
|
|
if dig_penalty ~= 1 then
|
|
|
|
toolcap_monoids.dig_speed:add_change(stack, dig_penalty, "medical")
|
|
|
|
end
|
|
|
|
elseif action == "take" then
|
|
|
|
local stack = inventory_info.stack
|
|
|
|
toolcap_monoids.dig_speed:del_change(stack, "medical")
|
|
|
|
elseif action == "move" then
|
|
|
|
if (inventory_info.to_list == "main") and (inventory_info.from_list ~= "main") then
|
|
|
|
local stack = inventory:get_stack("main", inventory_info.to_index)
|
|
|
|
toolcap_monoids.dig_speed:del_change(stack, "medical")
|
|
|
|
local dig_penalty = dig_penalty_storage[player:get_player_name()] or 1
|
|
|
|
if dig_penalty ~= 1 then
|
|
|
|
toolcap_monoids.dig_speed:add_change(stack, dig_penalty, "medical")
|
|
|
|
end
|
|
|
|
inventory:set_stack("main", inventory_info.to_index, stack)
|
|
|
|
elseif (inventory_info.from_list == "main") and (inventory_info.to_list ~= "main") then
|
|
|
|
local stack = inventory:get_stack(inventory_info.to_list, inventory_info.to_index)
|
|
|
|
toolcap_monoids.dig_speed:del_change(stack, "medical")
|
|
|
|
inventory:set_stack(inventory_info.to_list, inventory_info.to_index, stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2025-01-26 13:14:57 +03:00
|
|
|
|
|
|
|
---@param speed_factor number
|
|
|
|
local function set_speed(player, speed_factor)
|
|
|
|
local pname = player:get_player_name()
|
|
|
|
local prev_speed_factor = speed_factor_storage[pname] or 1
|
|
|
|
if speed_factor == prev_speed_factor then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if speed_factor < 0 then
|
|
|
|
speed_factor = prev_speed_factor
|
|
|
|
end
|
|
|
|
speed_factor_storage[pname] = speed_factor
|
|
|
|
storage:set_string(
|
|
|
|
"speed_factor",
|
|
|
|
minetest.serialize(
|
|
|
|
speed_factor_storage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
player_monoids.speed:del_change(player, "medical")
|
|
|
|
player_monoids.speed:add_change(player, speed_factor, "medical")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(
|
|
|
|
function(player, last_login)
|
|
|
|
set_speed(player, -1)
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|