mirror of
https://github.com/APercy/airutils.git
synced 2025-03-15 00:01:20 +00:00
improved plane destruction, added plane recover under certain circunstances, aded uuid mamager for future inventory management
This commit is contained in:
parent
690d3db901
commit
e344bf136b
4 changed files with 78 additions and 0 deletions
1
init.lua
1
init.lua
|
@ -65,6 +65,7 @@ if not minetest.get_modpath("signs_lib") then airutils._use_signs_api = false en
|
|||
if minetest.settings:get_bool('airutils_disable_signs_api') then airutils._use_signs_api = false end
|
||||
|
||||
airutils.get_wind = dofile(minetest.get_modpath("airutils") .. DIR_DELIM ..'/wind.lua')
|
||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "uuid_manager.lua")
|
||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "common_entities.lua")
|
||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_wind.lua")
|
||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "inventory_management.lua")
|
||||
|
|
|
@ -800,6 +800,55 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage)
|
|||
end
|
||||
end
|
||||
|
||||
--returns the vehicle to inventory if it is registered as a tool
|
||||
local function get_vehicle(self, player)
|
||||
if not player then return false end
|
||||
|
||||
local itmstck=player:get_wielded_item()
|
||||
local item_name = ""
|
||||
if itmstck then item_name = itmstck:get_name() end
|
||||
--remove
|
||||
if (item_name == "airutils:repair_tool") and self._engine_running == false then
|
||||
|
||||
local lua_ent = self.object:get_luaentity()
|
||||
local staticdata = lua_ent:get_staticdata(self)
|
||||
local obj_name = lua_ent.name
|
||||
|
||||
local stack = ItemStack(obj_name)
|
||||
local max = stack:get_stack_max()
|
||||
local tool = false
|
||||
if stack:get_stack_max() == 1 then tool = true end
|
||||
|
||||
if tool == false then return false end
|
||||
|
||||
local stack_meta = stack:get_meta()
|
||||
stack_meta:set_string("staticdata", staticdata)
|
||||
|
||||
local inv = player:get_inventory()
|
||||
if inv then
|
||||
if inv:room_for_item("main", stack) then
|
||||
inv:add_item("main", stack)
|
||||
else
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack)
|
||||
end
|
||||
else
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack)
|
||||
end
|
||||
|
||||
airutils.seats_destroy(self)
|
||||
local obj_children = self.object:get_children()
|
||||
for _, child in ipairs(obj_children) do
|
||||
child:remove()
|
||||
end
|
||||
airutils.destroy_inventory(self)
|
||||
self.object:remove()
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function airutils.on_rightclick(self, clicker)
|
||||
local message = ""
|
||||
if not clicker or not clicker:is_player() then
|
||||
|
@ -886,6 +935,9 @@ function airutils.on_rightclick(self, clicker)
|
|||
if airutils.set_param_paint(self, clicker, itmstck, 2) == true then
|
||||
return
|
||||
end
|
||||
if get_vehicle(self, clicker) then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if clicker:get_player_control().aux1 == true then --lets see the inventory
|
||||
|
|
|
@ -363,6 +363,10 @@ function airutils.destroy(self, by_name, by_automation)
|
|||
if self._destroy_parts_method then
|
||||
self._destroy_parts_method(self)
|
||||
end
|
||||
local obj_children = self.object:get_children()
|
||||
for _, child in ipairs(obj_children) do
|
||||
child:remove()
|
||||
end
|
||||
|
||||
if by_automation == false then
|
||||
local destroyed_ent = nil
|
||||
|
|
21
uuid_manager.lua
Normal file
21
uuid_manager.lua
Normal file
|
@ -0,0 +1,21 @@
|
|||
--function from yl_scheduler
|
||||
--[[
|
||||
Copyright (c) 2024 AliasAlreadyTaken
|
||||
|
||||
MIT License
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]--
|
||||
|
||||
local function generate_uuid()
|
||||
local template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
|
||||
return string.gsub(template, '[xy]', function(c)
|
||||
local v = (c == 'x') and math.random(0, 15) or math.random(8, 11)
|
||||
return string.format('%x', v)
|
||||
end)
|
||||
end
|
||||
|
||||
--exporter for airutils
|
||||
function airutils.generate_uuid() return generate_uuid() end
|
||||
|
Loading…
Add table
Reference in a new issue