Refactor Static Boots

This commit is contained in:
mrkubax10 2025-04-24 13:46:45 +02:00
parent 30c67390b2
commit 5b32382422

View File

@ -15,65 +15,45 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
local S=minetest.get_translator("industrialtest") local S=minetest.get_translator("industrialtest")
industrialtest.StaticBoots=table.copy(industrialtest.GearTool)
local image=(industrialtest.mtgAvailable and "industrialtest_static_boots.png" or "industrialtest_mcl_static_boots.png")
industrialtest.internal.unpackTableInto(industrialtest.StaticBoots,{
name="industrialtest:static_boots",
description=S("Static Boots"),
inventoryImage="industrialtest_static_boots_inv.png",
part="feet",
modelImage=image
})
local updateDelta=0 local updateDelta=0
local playerPositions={} local playerPositions={}
function industrialtest.StaticBoots.update(self,player,inv,itemstack,dtime)
local function onGlobalStep(player,inv,stack)
if stack:get_name()~="industrialtest:static_boots" then
return false
end
local playerPos=player:get_pos() local playerPos=player:get_pos()
playerPos.y=0 playerPos.y=0
if not playerPositions[player:get_player_name()] then if not playerPositions[player:get_player_name()] then
playerPositions[player:get_player_name()]=playerPos playerPositions[player:get_player_name()]=playerPos
return true return false
end end
if vector.distance(playerPos,playerPositions[player:get_player_name()])<5 then if vector.distance(playerPos,playerPositions[player:get_player_name()])<5 then
return true return false
end end
playerPositions[player:get_player_name()]=playerPos playerPositions[player:get_player_name()]=playerPos
local armorList=inv:get_list("armor") local armorList=inv:get_list("armor")
for i=1,#armorList do for i,armorItemstack in ipairs(armorList) do
local meta=armorList[i]:get_meta() local meta=armorItemstack:get_meta()
if industrialtest.api.hasPowerStorage(meta) and not industrialtest.api.isFullyCharged(meta) then if industrialtest.api.hasPowerStorage(meta) and not industrialtest.api.isFullyCharged(meta) then
industrialtest.api.addPowerToItem(armorList[i],1) industrialtest.api.addPowerToItem(armorItemstack,1)
inv:set_stack("armor",i,armorList[i]) inv:set_stack("armor",i,armorItemstack)
break break
end end
end end
return true return false
end end
if industrialtest.mtgAvailable then industrialtest.StaticBoots:register()
armor:register_armor("industrialtest:static_boots",{
description=S("Static Boots"),
inventory_image="industrialtest_static_boots_inv.png",
groups={
armor_feet=1,
armor_heal=0
}
})
elseif industrialtest.mclAvailable then
minetest.register_tool("industrialtest:static_boots",{
description=S("Static Boots"),
inventory_image="industrialtest_static_boots_inv.png",
groups={
armor=1,
non_combat_armor=1,
armor_feet=1,
non_combat_feet=1
},
sounds={
_mcl_armor_equip="mcl_armor_equip_iron",
_mcl_armor_unequip="mcl_armor_unequip_iron"
},
on_place=mcl_armor.equip_on_use,
on_secondary_use=mcl_armor.equip_on_use,
_mcl_armor_element="feet",
_mcl_armor_texture="industrialtest_mcl_static_boots.png"
})
end
minetest.register_craft({ minetest.register_craft({
type="shaped", type="shaped",
output="industrialtest:static_boots", output="industrialtest:static_boots",
@ -83,6 +63,7 @@ minetest.register_craft({
{"industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable"} {"industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable"}
} }
}) })
minetest.register_craft({ minetest.register_craft({
type="shaped", type="shaped",
output="industrialtest:static_boots", output="industrialtest:static_boots",
@ -96,31 +77,3 @@ minetest.register_craft({
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)
playerPositions[player:get_player_name()]=nil playerPositions[player:get_player_name()]=nil
end) end)
minetest.register_globalstep(function(dtime)
updateDelta=updateDelta+dtime
if updateDelta<industrialtest.updateDelay then
return
end
updateDelta=0
local players=minetest.get_connected_players()
for _,player in ipairs(players) do
if industrialtest.mtgAvailable then
local _,inv=armor:get_valid_player(player,"")
if inv then
local armorList=inv:get_list("armor")
assert(armorList)
for i=1,#armorList do
local stack=armorList[i]
if onGlobalStep(player,inv,stack) then
break
end
end
end
elseif industrialtest.mclAvailable then
local inv=player:get_inventory()
local stack=inv:get_stack("armor",5)
onGlobalStep(player,inv,stack)
end
end
end)