diff --git a/api.lua b/api.lua index 317e25d..c3d082e 100644 --- a/api.lua +++ b/api.lua @@ -113,12 +113,18 @@ end -- \returns true if value was successfully added, false otherwise industrialtest.api.prepareToolItem=function(itemstack) local def=minetest.registered_tools[itemstack:get_name()] - if not def or not def._industrialtest_tool or not def.tool_capabilities or not def.tool_capabilities.uses then + if not def then return false end - local meta=itemstack:get_meta() - meta:set_int("industrialtest.uses",def.tool_capabilities.uses) - return true + if def._industrialtest_tool and def.tool_capabilities and def.tool_capabilities.uses then + local meta=itemstack:get_meta() + meta:set_int("industrialtest.uses",def.tool_capabilities.uses) + return true + elseif def.groups and def.groups._industrialtest_emptyOnConstruct and itemstack:get_wear()==0 then + itemstack:set_wear(65534) + return true + end + return false end -- \brief Adds wear to item after it's use -- \param itemstack ItemStack to which wear should be added diff --git a/craftitems.lua b/craftitems.lua index 27062c5..d76afa0 100644 --- a/craftitems.lua +++ b/craftitems.lua @@ -445,6 +445,13 @@ industrialtest.api.registerPlate("carbon_plate",S("Carbon Plate"),{ } },"#272725ff",true) +industrialtest.api.registerPlate("tin_plate",S("Tin Plate"),{ + { + resource=industrialtest.elementKeys.tinIngot, + count=1 + } +},"#e0e0e0ff",true) + -- Cells minetest.register_craftitem("industrialtest:empty_cell",{ description=S("Empty Cell"), @@ -678,6 +685,24 @@ industrialtest.api.registerCompressorRecipe({ time=5 }) +minetest.register_tool("industrialtest:fuel_can",{ + description=S("Fuel Can"), + inventory_image="industrialtest_fuel_can.png", + groups={ + _industrialtest_fueled=1, + _industrialtest_emptyOnConstruct=1 + } +}) +minetest.register_craft({ + type="shaped", + output="industrialtest:fuel_can", + recipe={ + {"","industrialtest:tin_plate","industrialtest:tin_plate"}, + {"industrialtest:tin_plate","","industrialtest:tin_plate"}, + {"industrialtest:tin_plate","industrialtest:tin_plate","industrialtest:tin_plate"} + } +}) + -- Item callbacks minetest.register_on_player_inventory_action(function(player,action,inventory,info) if action=="put" then diff --git a/init.lua b/init.lua index 32b77ae..027a1ff 100644 --- a/init.lua +++ b/init.lua @@ -55,6 +55,7 @@ dofile(modpath.."/tools/electric_chainsaw.lua") dofile(modpath.."/tools/electric_drill.lua") dofile(modpath.."/tools/electric_hoe.lua") dofile(modpath.."/tools/electric_saber.lua") +dofile(modpath.."/tools/jetpack.lua") dofile(modpath.."/tools/treetap.lua") dofile(modpath.."/tools/wrench.lua") diff --git a/tools/jetpack.lua b/tools/jetpack.lua new file mode 100644 index 0000000..e99beb8 --- /dev/null +++ b/tools/jetpack.lua @@ -0,0 +1,142 @@ +-- IndustrialTest +-- Copyright (C) 2024 mrkubax10 + +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +local S=minetest.get_translator("industrialtest") + +local jetpack={} + +local function registerJetpack(config) + if industrialtest.mclAvailable then + local groups={ + armor=1, + non_combat_armor=1, + armor_torso=1, + non_combat_torso=1, + _industrialtest_jetpack=1 + } + for key,value in pairs(config.groups) do + groups[key]=value + end + minetest.register_tool("industrialtest:"..config.name,{ + description=config.displayName, + inventory_image="industrialtest_"..config.name.."_inv.png", + groups=groups, + 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="torso", + _mcl_armor_texture="industrialtest_"..config.name..".png", + _industrialtest_tryFly=config.tryFly + }) + elseif industrialtest.mtgAvailable then + local groups={ + armor_torso=1, + armor_heal=0, + _industrialtest_jetpack=1 + } + for key,value in pairs(config.groups) do + groups[key]=value + end + armor:register_armor("industrialtest:"..config.name, { + description=config.displayName, + inventory_image="industrialtest_"..config.name.."_inv.png", + groups=groups, + _industrialtest_tryFly=config.tryFly + }) + end +end + +local function addYVelocityClamped(player,vel,max) + local playerVel=player:get_velocity() + if playerVel.y+vel>max then + player:add_velocity(vector.new(0,math.max(max-playerVel.y,0),0)) + else + player:add_velocity(vector.new(0,vel,0)) + end +end + +local function onGlobalStep(player,inv,itemstack,index,def) + if def.groups and def.groups._industrialtest_jetpack then + local result=def._industrialtest_tryFly(player,itemstack) + if result then + addYVelocityClamped(player,1,10) + inv:set_stack("armor",index,result) + end + return true + end + return false +end + +jetpack.tryFly=function(player,itemstack) + if itemstack:get_wear()>=65533 then + return false + end + itemstack:set_wear(itemstack:get_wear()+2) + minetest.debug(itemstack:get_wear()) + return itemstack +end + +-- _v is hack to suppress "Registered armor doesn't have material at the end of registration name" warning from 3D Armor. +registerJetpack({ + name="jetpack_v", + displayName=S("Jetpack"), + groups={ + _industrialtest_fueled=1, + _industrialtest_emptyOnConstruct=1 + }, + tryFly=jetpack.tryFly +}) +minetest.register_craft({ + type="shaped", + output="industrialtest:jetpack_v", + recipe={ + {"industrialtest:refined_iron_ingot","industrialtest:electronic_circuit","industrialtest:refined_iron_ingot"}, + {"industrialtest:refined_iron_ingot","industrialtest:fuel_can","industrialtest:refined_iron_ingot"}, + {industrialtest.elementKeys.powerCarrier,"",industrialtest.elementKeys.powerCarrier} + } +}) + +minetest.register_globalstep(function(dtime) + -- FIXME: Maybe this can be optimized? + local players=minetest.get_connected_players() + for _,player in ipairs(players) do + local control=player:get_player_control() + if control.jump then + if industrialtest.mclAvailable then + local inv=player:get_inventory() + local stack=inv:get_stack("armor",3) + local def=stack:get_definition() + onGlobalStep(player,inv,stack,3,def) + elseif 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] + local def=stack:get_definition() + if onGlobalStep(player,inv,stack,i,def) then + break + end + end + end + end + end + end +end)