Change tab to 4 spaces

This commit is contained in:
Fabio Rodrigues Ribeiro 2023-09-05 19:50:58 -03:00
parent be966a1ed8
commit 0cd1ad2f66
18 changed files with 966 additions and 966 deletions

View File

@ -6,65 +6,65 @@ local module_name = "airutils"
if minetest.get_modpath("technic") then
if technic then
technic.register_extractor_recipe({input = {"farming:wheat 33"}, output = "biofuel:biofuel 1"})
technic.register_extractor_recipe({input = {"farming:corn 33"}, output = "biofuel:biofuel 1"})
technic.register_extractor_recipe({input = {"farming:potato 33"}, output = "biofuel:biofuel 1"})
technic.register_extractor_recipe({input = {"default:papyrus 99"}, output = "biofuel:biofuel 1"})
technic.register_extractor_recipe({input = {"farming:wheat 33"}, output = "biofuel:biofuel 1"})
technic.register_extractor_recipe({input = {"farming:corn 33"}, output = "biofuel:biofuel 1"})
technic.register_extractor_recipe({input = {"farming:potato 33"}, output = "biofuel:biofuel 1"})
technic.register_extractor_recipe({input = {"default:papyrus 99"}, output = "biofuel:biofuel 1"})
end
end
if minetest.get_modpath("basic_machines") then
if basic_machines then
basic_machines.grinder_recipes["farming:wheat"] = {50,"biofuel:biofuel",1}
basic_machines.grinder_recipes["farming:corn"] = {50,"biofuel:biofuel",1}
basic_machines.grinder_recipes["farming:potato"] = {50,"biofuel:biofuel",1}
basic_machines.grinder_recipes["default:papyrus"] = {70,"biofuel:biofuel",1}
basic_machines.grinder_recipes["farming:wheat"] = {50,"biofuel:biofuel",1}
basic_machines.grinder_recipes["farming:corn"] = {50,"biofuel:biofuel",1}
basic_machines.grinder_recipes["farming:potato"] = {50,"biofuel:biofuel",1}
basic_machines.grinder_recipes["default:papyrus"] = {70,"biofuel:biofuel",1}
end
end
if minetest.get_modpath("default") then
minetest.register_craft({
output = module_name .. ":biofuel_distiller",
recipe = {
{"default:copper_ingot", "default:copper_ingot", "default:copper_ingot"},
{"default:steel_ingot" , "", "default:steel_ingot"},
{"default:steel_ingot" , "default:steel_ingot", "default:steel_ingot"},
},
})
minetest.register_craft({
output = module_name .. ":biofuel_distiller",
recipe = {
{"default:copper_ingot", "default:copper_ingot", "default:copper_ingot"},
{"default:steel_ingot" , "", "default:steel_ingot"},
{"default:steel_ingot" , "default:steel_ingot", "default:steel_ingot"},
},
})
end
if minetest.get_modpath("mcl_core") then
minetest.register_craft({
output = module_name .. ":biofuel_distiller",
recipe = {
{"mcl_copper:copper_ingot", "mcl_copper:copper_ingot", "mcl_copper:copper_ingot"},
{"mcl_core:iron_ingot" , "", "mcl_core:iron_ingot"},
{"mcl_core:iron_ingot" , "mcl_core:iron_ingot", "mcl_core:iron_ingot"},
},
})
minetest.register_craft({
output = module_name .. ":biofuel_distiller",
recipe = {
{"mcl_copper:copper_ingot", "mcl_copper:copper_ingot", "mcl_copper:copper_ingot"},
{"mcl_core:iron_ingot" , "", "mcl_core:iron_ingot"},
{"mcl_core:iron_ingot" , "mcl_core:iron_ingot", "mcl_core:iron_ingot"},
},
})
end
-- biofuel
local new_gallon_id = "airutils:biofuel"
minetest.register_craftitem(new_gallon_id,{
description = "Bio Fuel",
inventory_image = "airutils_biofuel_inv.png",
description = "Bio Fuel",
inventory_image = "airutils_biofuel_inv.png",
})
minetest.register_craft({
type = "fuel",
recipe = new_gallon_id,
burntime = 50,
type = "fuel",
recipe = new_gallon_id,
burntime = 50,
})
minetest.register_alias("biofuel:biofuel", new_gallon_id) --for the old biofuel
local ferment = {
{"default:papyrus", new_gallon_id},
{"farming:wheat", new_gallon_id},
{"farming:corn", new_gallon_id},
{"farming:baked_potato", new_gallon_id},
{"default:papyrus", new_gallon_id},
{"farming:wheat", new_gallon_id},
{"farming:corn", new_gallon_id},
{"farming:baked_potato", new_gallon_id},
{"farming:potato", new_gallon_id}
}
@ -73,129 +73,129 @@ local ferment_groups = {'flora', 'leaves', 'flower', 'sapling', 'tree', 'wood',
-- distiller
local biofueldistiller_formspec = "size[8,9]"
.. "list[current_name;src;2,1;1,1;]" .. airutils.get_itemslot_bg(2, 1, 1, 1)
.. "list[current_name;dst;5,1;1,1;]" .. airutils.get_itemslot_bg(5, 1, 1, 1)
.. "list[current_player;main;0,5;8,4;]" .. airutils.get_itemslot_bg(0, 5, 8, 4)
.. "listring[current_name;dst]"
.. "listring[current_player;main]"
.. "listring[current_name;src]"
.. "listring[current_player;main]"
.. "image[3.5,1;1,1;gui_furnace_arrow_bg.png^[transformR270]"
.. "list[current_name;src;2,1;1,1;]" .. airutils.get_itemslot_bg(2, 1, 1, 1)
.. "list[current_name;dst;5,1;1,1;]" .. airutils.get_itemslot_bg(5, 1, 1, 1)
.. "list[current_player;main;0,5;8,4;]" .. airutils.get_itemslot_bg(0, 5, 8, 4)
.. "listring[current_name;dst]"
.. "listring[current_player;main]"
.. "listring[current_name;src]"
.. "listring[current_player;main]"
.. "image[3.5,1;1,1;gui_furnace_arrow_bg.png^[transformR270]"
minetest.register_node( module_name .. ":biofuel_distiller", {
description = "Biofuel Distiller",
tiles = {"airutils_black.png", "airutils_aluminum.png", "airutils_copper.png" },
drawtype = "mesh",
mesh = "airutils_biofuel_distiller.b3d",
paramtype = "light",
paramtype2 = "facedir",
groups = {
choppy = 2, oddly_breakable_by_hand = 1, flammable = 2
},
legacy_facedir_simple = true,
description = "Biofuel Distiller",
tiles = {"airutils_black.png", "airutils_aluminum.png", "airutils_copper.png" },
drawtype = "mesh",
mesh = "airutils_biofuel_distiller.b3d",
paramtype = "light",
paramtype2 = "facedir",
groups = {
choppy = 2, oddly_breakable_by_hand = 1, flammable = 2
},
legacy_facedir_simple = true,
on_place = minetest.rotate_node,
on_place = minetest.rotate_node,
on_construct = function(pos)
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", biofueldistiller_formspec)
meta:set_string("infotext", "Biofuel Distiller")
meta:set_float("status", 0.0)
meta:set_string("formspec", biofueldistiller_formspec)
meta:set_string("infotext", "Biofuel Distiller")
meta:set_float("status", 0.0)
local inv = meta:get_inventory()
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 1)
end,
inv:set_size("src", 1)
inv:set_size("dst", 1)
end,
can_dig = function(pos,player)
can_dig = function(pos,player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if not inv:is_empty("dst")
or not inv:is_empty("src") then
return false
end
if not inv:is_empty("dst")
or not inv:is_empty("src") then
return false
end
return true
end,
return true
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end,
return stack:get_count()
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if listname == "src" then
return stack:get_count()
elseif listname == "dst" then
return 0
end
end,
if listname == "src" then
return stack:get_count()
elseif listname == "dst" then
return 0
end
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
if to_list == "src" then
return count
elseif to_list == "dst" then
return 0
end
end,
if to_list == "src" then
return count
elseif to_list == "dst" then
return 0
end
end,
on_metadata_inventory_put = function(pos)
on_metadata_inventory_put = function(pos)
local timer = minetest.get_node_timer(pos)
local timer = minetest.get_node_timer(pos)
timer:start(5)
end,
timer:start(5)
end,
on_timer = function(pos)
on_timer = function(pos)
local meta = minetest.get_meta(pos) ; if not meta then return end
local inv = meta:get_inventory()
local meta = minetest.get_meta(pos) ; if not meta then return end
local inv = meta:get_inventory()
-- is barrel empty?
if not inv or inv:is_empty("src") then
-- is barrel empty?
if not inv or inv:is_empty("src") then
meta:set_float("status", 0.0)
meta:set_string("infotext", "Fuel Distiller")
meta:set_float("status", 0.0)
meta:set_string("infotext", "Fuel Distiller")
return false
end
return false
end
-- does it contain any of the source items on the list?
local has_item
-- does it contain any of the source items on the list?
local has_item
--normal items
for n = 1, #ferment do
if inv:contains_item("src", ItemStack(ferment[n][1])) then
has_item = n
break
end
end
for n = 1, #ferment do
if inv:contains_item("src", ItemStack(ferment[n][1])) then
has_item = n
break
end
end
--groups
local has_group
@ -206,56 +206,56 @@ minetest.register_node( module_name .. ":biofuel_distiller", {
local item_name = v:get_name()
for n = 1, #ferment_groups do
if minetest.get_item_group(item_name, ferment_groups[n]) == 1 then
has_group = n
break
has_group = n
break
end
end
end
end
end
if not has_item and not has_group then
return false
end
if not has_item and not has_group then
return false
end
-- is there room for additional fermentation?
if has_item and not inv:room_for_item("dst", ferment[has_item][2]) then
meta:set_string("infotext", "Fuel Distiller (FULL)")
return true
end
-- is there room for additional fermentation?
if has_item and not inv:room_for_item("dst", ferment[has_item][2]) then
meta:set_string("infotext", "Fuel Distiller (FULL)")
return true
end
if has_group and not inv:room_for_item("dst", new_gallon_id) then
meta:set_string("infotext", "Fuel Distiller (FULL)")
return true
end
if has_group and not inv:room_for_item("dst", new_gallon_id) then
meta:set_string("infotext", "Fuel Distiller (FULL)")
return true
end
local status = meta:get_float("status")
local status = meta:get_float("status")
-- fermenting (change status)
if status < 100 then
meta:set_string("infotext", "Fuel Distiller " .. status .. "% done")
meta:set_float("status", status + 5)
else
-- fermenting (change status)
if status < 100 then
meta:set_string("infotext", "Fuel Distiller " .. status .. "% done")
meta:set_float("status", status + 5)
else
if not has_group then
inv:remove_item("src", ferment[has_item][1])
inv:add_item("dst", ferment[has_item][2])
inv:remove_item("src", ferment[has_item][1])
inv:add_item("dst", ferment[has_item][2])
else
for i,itemstack in pairs(inv:get_list("src")) do
inv:remove_item("src", ItemStack(itemstack:get_name().." 1"))
inv:remove_item("src", ItemStack(itemstack:get_name().." 1"))
end
inv:add_item("dst", new_gallon_id)
inv:add_item("dst", new_gallon_id)
end
meta:set_float("status", 0,0)
end
meta:set_float("status", 0,0)
end
if inv:is_empty("src") then
meta:set_float("status", 0.0)
meta:set_string("infotext", "Fuel Distiller")
end
if inv:is_empty("src") then
meta:set_float("status", 0.0)
meta:set_string("infotext", "Fuel Distiller")
end
return true
end,
return true
end,
})
--lets remove the old one

View File

@ -1,14 +1,14 @@
local function check_protection(pos, name)
if minetest.is_protected(pos, name) then
minetest.log("action", name
.. " tried to place a PAPI"
.. " at protected position "
.. minetest.pos_to_string(pos)
if minetest.is_protected(pos, name) then
minetest.log("action", name
.. " tried to place a PAPI"
.. " at protected position "
.. minetest.pos_to_string(pos)
)
minetest.record_protection_violation(pos, name)
return true
end
return false
minetest.record_protection_violation(pos, name)
return true
end
return false
end
function airutils.PAPIplace(player,pos)
@ -16,51 +16,51 @@ function airutils.PAPIplace(player,pos)
return
end
local dir = minetest.dir_to_facedir(player:get_look_dir())
local pos1 = vector.new(pos)
local dir = minetest.dir_to_facedir(player:get_look_dir())
local pos1 = vector.new(pos)
local player_name = player:get_player_name()
if check_protection(pos, player_name) then
return
end
if check_protection(pos, player_name) then
return
end
core.set_node(pos, {name="airutils:papi", param2=dir})
local meta = core.get_meta(pos)
meta:set_string("infotext", "PAPI\rOwned by: "..player_name)
meta:set_string("owner", player_name)
meta:set_string("dont_destroy", "false")
return true
core.set_node(pos, {name="airutils:papi", param2=dir})
local meta = core.get_meta(pos)
meta:set_string("infotext", "PAPI\rOwned by: "..player_name)
meta:set_string("owner", player_name)
meta:set_string("dont_destroy", "false")
return true
end
function airutils.togglePapiSide(pos, node, clicker, itemstack)
local player_name = clicker:get_player_name()
local meta = core.get_meta(pos)
local player_name = clicker:get_player_name()
local meta = core.get_meta(pos)
if player_name ~= meta:get_string("owner") then
return
return
end
local dir=node.param2
if node.name == "airutils:papi_right" then
core.set_node(pos, {name="airutils:papi", param2=dir})
meta:set_string("infotext", "PAPI - left side\rOwned by: "..player_name)
meta:set_string("infotext", "PAPI - left side\rOwned by: "..player_name)
elseif node.name == "airutils:papi" then
core.set_node(pos, {name="airutils:papi_right", param2=dir})
meta:set_string("infotext", "PAPI - right side\rOwned by: "..player_name)
end
meta:set_string("owner", player_name)
meta:set_string("dont_destroy", "false")
meta:set_string("owner", player_name)
meta:set_string("dont_destroy", "false")
end
airutils.papi_collision_box = {
type = "fixed",
fixed={{-0.5,-0.5,-0.5,0.5,-0.42,0.5},},
type = "fixed",
fixed={{-0.5,-0.5,-0.5,0.5,-0.42,0.5},},
}
airutils.papi_selection_box = {
type = "fixed",
fixed={{-0.5,-0.5,-0.5,0.5,1.5,0.5},},
type = "fixed",
fixed={{-0.5,-0.5,-0.5,0.5,1.5,0.5},},
}
airutils.groups_right = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}
@ -68,43 +68,43 @@ airutils.groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}
-- PAPI node (default left)
minetest.register_node("airutils:papi",{
description = "PAPI",
--inventory_image = "papi.png",
--wield_image = "papi.png",
tiles = {"airutils_black.png", "airutils_u_black.png", "airutils_white.png",
"airutils_metal.png", {name = "airutils_red.png", backface_culling = true},},
groups = airutils.groups,
paramtype2 = "facedir",
paramtype = "light",
drawtype = "mesh",
mesh = "papi.b3d",
visual_scale = 1.0,
light_source = 13,
description = "PAPI",
--inventory_image = "papi.png",
--wield_image = "papi.png",
tiles = {"airutils_black.png", "airutils_u_black.png", "airutils_white.png",
"airutils_metal.png", {name = "airutils_red.png", backface_culling = true},},
groups = airutils.groups,
paramtype2 = "facedir",
paramtype = "light",
drawtype = "mesh",
mesh = "papi.b3d",
visual_scale = 1.0,
light_source = 13,
backface_culling = true,
selection_box = airutils.papi_selection_box,
collision_box = airutils.papi_collision_box,
can_dig = airutils.canDig,
selection_box = airutils.papi_selection_box,
collision_box = airutils.papi_collision_box,
can_dig = airutils.canDig,
_color = "",
on_destruct = airutils.remove,
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
if airutils.PAPIplace(placer,pos)==true then
itemstack:take_item(1)
return itemstack
else
return
end
end,
on_rightclick=airutils.togglePapiSide,
on_destruct = airutils.remove,
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
if airutils.PAPIplace(placer,pos)==true then
itemstack:take_item(1)
return itemstack
else
return
end
end,
on_rightclick=airutils.togglePapiSide,
on_punch = function(pos, node, puncher, pointed_thing)
local player_name = puncher:get_player_name()
local player_name = puncher:get_player_name()
local meta = core.get_meta(pos)
if player_name ~= meta:get_string("owner") then
if player_name ~= meta:get_string("owner") then
local privs = minetest.get_player_privs(player_name)
if privs.server == false then
return
return
end
end
end
local itmstck=puncher:get_wielded_item()
local item_name = ""
@ -115,50 +115,50 @@ minetest.register_node("airutils:papi",{
function airutils.remove_papi(pos)
--[[
local meta = core.get_meta(pos)
local meta = core.get_meta(pos)
local node = minetest.get_node(pos)
if node and meta then
local dir=node.param2
if node.name == "airutils:papi_right" then
core.set_node(pos, {name="airutils:papi", param2=dir})
meta:set_string("infotext", "PAPI - left side\rOwned by: "..player_name)
meta:set_string("infotext", "PAPI - left side\rOwned by: "..player_name)
end
meta:set_string("owner", player_name)
meta:set_string("dont_destroy", "false")
meta:set_string("owner", player_name)
meta:set_string("dont_destroy", "false")
if meta:get_string("dont_destroy") == "true" then
-- when swapping it
return
end
if meta:get_string("dont_destroy") == "true" then
-- when swapping it
return
end
end]]--
end
-- PAPI right node
minetest.register_node("airutils:papi_right",{
description = "PAPI_right_side",
tiles = {"airutils_black.png", "airutils_u_black.png", "airutils_white.png",
"airutils_metal.png", {name = "airutils_red.png", backface_culling = true},},
groups = airutils.groups_right,
paramtype2 = "facedir",
paramtype = "light",
drawtype = "mesh",
mesh = "papi_right.b3d",
visual_scale = 1.0,
light_source = 13,
tiles = {"airutils_black.png", "airutils_u_black.png", "airutils_white.png",
"airutils_metal.png", {name = "airutils_red.png", backface_culling = true},},
groups = airutils.groups_right,
paramtype2 = "facedir",
paramtype = "light",
drawtype = "mesh",
mesh = "papi_right.b3d",
visual_scale = 1.0,
light_source = 13,
backface_culling = true,
selection_box = airutils.papi_selection_box,
collision_box = airutils.papi_collision_box,
can_dig = airutils.canDig,
selection_box = airutils.papi_selection_box,
collision_box = airutils.papi_collision_box,
can_dig = airutils.canDig,
_color = "",
on_destruct = airutils.remove_papi,
on_rightclick=airutils.togglePapiSide,
on_destruct = airutils.remove_papi,
on_rightclick=airutils.togglePapiSide,
on_punch = function(pos, node, puncher, pointed_thing)
local player_name = puncher:get_player_name()
local player_name = puncher:get_player_name()
local meta = core.get_meta(pos)
if player_name ~= meta:get_string("owner") then
return
end
if player_name ~= meta:get_string("owner") then
return
end
local itmstck=puncher:get_wielded_item()
local item_name = ""
@ -170,10 +170,10 @@ minetest.register_node("airutils:papi_right",{
-- PAPI craft
minetest.register_craft({
output = 'airutils:papi',
recipe = {
{'default:glass', 'default:mese_crystal', 'default:glass'},
{'default:glass', 'default:steel_ingot' , 'default:glass'},
{'' , 'default:steel_ingot' , ''},
}
output = 'airutils:papi',
recipe = {
{'default:glass', 'default:mese_crystal', 'default:glass'},
{'default:glass', 'default:steel_ingot' , 'default:glass'},
{'' , 'default:steel_ingot' , ''},
}
})

View File

@ -2,16 +2,16 @@ local S = minetest.get_translator("airutils")
-- trike repair
minetest.register_craftitem("airutils:repair_tool",{
description = "Repair Tool",
inventory_image = "airutils_repair_tool.png",
description = "Repair Tool",
inventory_image = "airutils_repair_tool.png",
})
minetest.register_craft({
output = "airutils:repair_tool",
recipe = {
{"", "default:steel_ingot", ""},
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "", "default:steel_ingot"},
{"", "default:steel_ingot", ""},
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "", "default:steel_ingot"},
},
})

View File

@ -41,13 +41,13 @@ function airutils.move_target(player, pointed_thing)
end
minetest.register_tool("airutils:tug", {
description = "Tug tool for airport",
inventory_image = "airutils_tug.png",
stack_max=1,
on_use = function(itemstack, player, pointed_thing)
if not player then
return
end
description = "Tug tool for airport",
inventory_image = "airutils_tug.png",
stack_max=1,
on_use = function(itemstack, player, pointed_thing)
if not player then
return
end
local is_admin = false
is_admin = minetest.check_player_privs(player, {server=true})
@ -57,12 +57,12 @@ minetest.register_tool("airutils:tug", {
--[[if areas then
if not areas:canInteract(pos, pname) then
local owners = areas:getNodeOwners(pos)
minetest.chat_send_player(pname,
S("@1 is protected by @2.",
minetest.pos_to_string(pos),
table.concat(owners, ", ")))
else
local owners = areas:getNodeOwners(pos)
minetest.chat_send_player(pname,
S("@1 is protected by @2.",
minetest.pos_to_string(pos),
table.concat(owners, ", ")))
else
airutils.move_target(player, pointed_thing)
end
end]]--
@ -79,9 +79,9 @@ minetest.register_tool("airutils:tug", {
if not is_protected(pos, pname) or pname == owner or is_admin then
airutils.move_target(player, pointed_thing)
else
minetest.chat_send_player(pname,
S("@1 is protected.",
minetest.pos_to_string(pos)))
minetest.chat_send_player(pname,
S("@1 is protected.",
minetest.pos_to_string(pos)))
end
end
@ -90,16 +90,16 @@ minetest.register_tool("airutils:tug", {
end
end,
end,
sound = {breaks = "default_tool_breaks"},
sound = {breaks = "default_tool_breaks"},
})
minetest.register_craft({
output = "airutils:tug",
recipe = {
{"", "", "default:steel_ingot"},
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "default:stick", "default:diamond"},
}
output = "airutils:tug",
recipe = {
{"", "", "default:steel_ingot"},
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "default:stick", "default:diamond"},
}
})

View File

@ -1,14 +1,14 @@
local function check_protection(pos, name)
if minetest.is_protected(pos, name) then
minetest.log("action", name
.. " tried to place a Wind Indicator"
.. " at protected position "
.. minetest.pos_to_string(pos)
if minetest.is_protected(pos, name) then
minetest.log("action", name
.. " tried to place a Wind Indicator"
.. " at protected position "
.. minetest.pos_to_string(pos)
)
minetest.record_protection_violation(pos, name)
return true
end
return false
minetest.record_protection_violation(pos, name)
return true
end
return false
end
function airutils.WindDplace(player,pos)
@ -16,30 +16,30 @@ function airutils.WindDplace(player,pos)
return
end
local dir = minetest.dir_to_facedir(vector.new())
local pos1 = vector.new(pos)
local dir = minetest.dir_to_facedir(vector.new())
local pos1 = vector.new(pos)
local player_name = player:get_player_name()
if check_protection(pos, player_name) then
return
end
if check_protection(pos, player_name) then
return
end
core.set_node(pos1, {name="airutils:wind", param2=dir})
local meta = core.get_meta(pos)
meta:set_string("infotext", "Wind Indicator\rOwned by: "..player_name)
meta:set_string("owner", player_name)
meta:set_string("dont_destroy", "false")
return true
core.set_node(pos1, {name="airutils:wind", param2=dir})
local meta = core.get_meta(pos)
meta:set_string("infotext", "Wind Indicator\rOwned by: "..player_name)
meta:set_string("owner", player_name)
meta:set_string("dont_destroy", "false")
return true
end
airutils.wind_collision_box = {
type = "fixed",
fixed={{-0.5,0,-0.5,0.5,5.0,0.5},},
type = "fixed",
fixed={{-0.5,0,-0.5,0.5,5.0,0.5},},
}
airutils.wind_selection_box = {
type = "fixed",
fixed={{-0.5,0,-0.5,0.5,5.0,0.5},},
type = "fixed",
fixed={{-0.5,0,-0.5,0.5,5.0,0.5},},
}
local function get_smooth(angle_initial, reference, last_ref, value)
@ -51,23 +51,23 @@ local function get_smooth(angle_initial, reference, last_ref, value)
end
minetest.register_entity("airutils:wind_indicator",{
-- common props
physical = true,
stepheight = 0.5,
collide_with_objects = true,
collisionbox = {-0.5, 0, -0.5, 0.5, 5.0, 0.5},
visual = "mesh",
mesh = "airutils_wind.b3d",
textures = {"airutils_red.png", "airutils_black.png", "airutils_white.png", "airutils_metal.png"},
static_save = true,
makes_footstep_sound = false,
-- common props
physical = true,
stepheight = 0.5,
collide_with_objects = true,
collisionbox = {-0.5, 0, -0.5, 0.5, 5.0, 0.5},
visual = "mesh",
mesh = "airutils_wind.b3d",
textures = {"airutils_red.png", "airutils_black.png", "airutils_white.png", "airutils_metal.png"},
static_save = true,
makes_footstep_sound = false,
_pos = nil,
on_activate = function(self, staticdata, dtime_s)
self._pos = self.object:get_pos()
end,
on_step = function(self,dtime,colinfo)
on_step = function(self,dtime,colinfo)
self.object:set_pos(self._pos)
local wind = airutils.get_wind(self._pos, 1.0)
@ -103,20 +103,20 @@ minetest.register_entity("airutils:wind_indicator",{
self.object:set_bone_position("b_e", {x=0,y=3,z=0}, {x=0,y=0,z=-b_e})
--minetest.chat_send_all("Wind Direction: "..math.deg(wind_yaw))
end, -- required
--on_activate = mobkit.actfunc, -- required
--get_staticdata = mobkit.statfunc,
max_hp = 65535,
timeout = 0,
end, -- required
--on_activate = mobkit.actfunc, -- required
--get_staticdata = mobkit.statfunc,
max_hp = 65535,
timeout = 0,
on_punch=function(self, puncher)
return
end,
return
end,
on_rightclick = function(self, clicker)
local wind = airutils.get_wind(pos, 2.0)
local wind_yaw = minetest.dir_to_yaw(wind)
minetest.chat_send_player(clicker:get_player_name(),core.colorize('#00ff00', " >>> The wind direction now is "..math.deg(wind_yaw)))
return
return
end,
})
@ -125,69 +125,69 @@ minetest.register_entity("airutils:wind_indicator",{
-- Wind Indicator node (default left)
minetest.register_node("airutils:wind",{
description = "Wind Direction Indicator",
waving = 1,
tiles = {"default_steel_block.png","default_steel_block.png","default_steel_block.png","default_steel_block.png","default_steel_block.png","default_steel_block.png"},
paramtype = "light",
paramtype2 = "leveled",
is_ground_content = false,
groups = {cracky = 1, level = 2},
walkable = true,
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
{-0.1, 0.5, -0.1, 0.1, 2.0, 0.1}
}
},
node_dig_prediction = "default:dirt",
node_placement_prediction = "airutils:wind",
on_place = function(itemstack, placer, pointed_thing)
description = "Wind Direction Indicator",
waving = 1,
tiles = {"default_steel_block.png","default_steel_block.png","default_steel_block.png","default_steel_block.png","default_steel_block.png","default_steel_block.png"},
paramtype = "light",
paramtype2 = "leveled",
is_ground_content = false,
groups = {cracky = 1, level = 2},
walkable = true,
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
{-0.1, 0.5, -0.1, 0.1, 2.0, 0.1}
}
},
node_dig_prediction = "default:dirt",
node_placement_prediction = "airutils:wind",
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
local pos = pointed_thing.above
local player_name = placer:get_player_name()
local player_name = placer:get_player_name()
if not minetest.is_protected(pos, player_name) and not minetest.is_protected(pos, player_name) then
minetest.set_node(pos, {name = "airutils:wind",param2 = 1 })
minetest.add_entity({x=pos.x, y=pos.y, z=pos.z},"airutils:wind_indicator")
local meta = minetest.get_meta(pos)
if not (creative and creative.is_enabled_for and creative.is_enabled_for(player_name)) then
itemstack:take_item()
end
else
minetest.chat_send_player(player_name, "Node is protected")
minetest.record_protection_violation(pos, player_name)
end
if not minetest.is_protected(pos, player_name) and not minetest.is_protected(pos, player_name) then
minetest.set_node(pos, {name = "airutils:wind",param2 = 1 })
minetest.add_entity({x=pos.x, y=pos.y, z=pos.z},"airutils:wind_indicator")
local meta = minetest.get_meta(pos)
if not (creative and creative.is_enabled_for and creative.is_enabled_for(player_name)) then
itemstack:take_item()
end
else
minetest.chat_send_player(player_name, "Node is protected")
minetest.record_protection_violation(pos, player_name)
end
return itemstack
end,
on_destruct = function(pos)
local meta=minetest.get_meta(pos)
if meta then
local cpos = {x=pos.x, y= pos.y, z=pos.z}
local object = minetest.get_objects_inside_radius(cpos, 1)
for _,obj in ipairs(object) do
local entity = obj:get_luaentity()
if entity and entity.name == "airutils:wind_indicator" then
obj:remove()
end
end
end
end,
return itemstack
end,
on_destruct = function(pos)
local meta=minetest.get_meta(pos)
if meta then
local cpos = {x=pos.x, y= pos.y, z=pos.z}
local object = minetest.get_objects_inside_radius(cpos, 1)
for _,obj in ipairs(object) do
local entity = obj:get_luaentity()
if entity and entity.name == "airutils:wind_indicator" then
obj:remove()
end
end
end
end,
})
-- WIND craft
minetest.register_craft({
output = 'airutils:wind',
recipe = {
{'wool:white', 'wool:white', 'wool:white'},
{'wool:white', 'default:steel_ingot' , 'wool:white'},
{'' , 'default:steel_ingot' , ''},
}
output = 'airutils:wind',
recipe = {
{'wool:white', 'wool:white', 'wool:white'},
{'wool:white', 'default:steel_ingot' , 'wool:white'},
{'' , 'default:steel_ingot' , ''},
}
})

View File

@ -3,22 +3,22 @@
--
minetest.register_entity('airutils:seat_base',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "airutils_seat_base.b3d",
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "airutils_seat_base.b3d",
textures = {"airutils_alpha.png",},
},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})

126
init.lua
View File

@ -66,17 +66,17 @@ if minetest.get_modpath("player_api") and not minetest.settings:get_bool('airuti
end
function airutils.remove(pos)
local meta = core.get_meta(pos)
if meta:get_string("dont_destroy") == "true" then
-- when swapping it
return
end
local meta = core.get_meta(pos)
if meta:get_string("dont_destroy") == "true" then
-- when swapping it
return
end
end
function airutils.canDig(pos, player)
local meta = core.get_meta(pos)
return meta:get_string("dont_destroy") ~= "true"
and player:get_player_name() == meta:get_string("owner")
local meta = core.get_meta(pos)
return meta:get_string("dont_destroy") ~= "true"
and player:get_player_name() == meta:get_string("owner")
end
function airutils.check_node_below(obj, how_low)
@ -86,7 +86,7 @@ function airutils.check_node_below(obj, how_low)
local node_below = minetest.get_node(pos_below).name
local nodedef = minetest.registered_nodes[node_below]
local touching_ground = not nodedef or -- unknown nodes are solid
nodedef.walkable or false
nodedef.walkable or false
local liquid_below = not touching_ground and nodedef.liquidtype ~= "none"
return touching_ground, liquid_below
end
@ -94,12 +94,12 @@ function airutils.check_node_below(obj, how_low)
end
function airutils.check_is_under_water(obj)
local pos_up = obj:get_pos()
pos_up.y = pos_up.y + 0.1
local node_up = minetest.get_node(pos_up).name
local nodedef = minetest.registered_nodes[node_up]
local liquid_up = nodedef.liquidtype ~= "none"
return liquid_up
local pos_up = obj:get_pos()
pos_up.y = pos_up.y + 0.1
local node_up = minetest.get_node(pos_up).name
local nodedef = minetest.registered_nodes[node_up]
local liquid_up = nodedef.liquidtype ~= "none"
return liquid_up
end
function airutils.setText(self, vehicle_name)
@ -177,10 +177,10 @@ end
--for
function airutils.eval_vertical_interception(initial_pos, end_pos)
local ret_y = nil
local cast = minetest.raycast(initial_pos, end_pos, true, true)
local thing = cast:next()
while thing do
if thing.type == "node" then
local cast = minetest.raycast(initial_pos, end_pos, true, true)
local thing = cast:next()
while thing do
if thing.type == "node" then
local pos = thing.intersection_point
if pos then
local nodename = minetest.get_node(thing.under).name
@ -198,25 +198,25 @@ end
--lift
local function pitchroll2pitchyaw(aoa,roll)
if roll == 0.0 then return aoa,0 end
-- assumed vector x=0,y=0,z=1
local p1 = math.tan(aoa)
local y = math.cos(roll)*p1
local x = math.sqrt(p1^2-y^2)
local pitch = math.atan(y)
local yaw=math.atan(x)*math.sign(roll)
return pitch,yaw
if roll == 0.0 then return aoa,0 end
-- assumed vector x=0,y=0,z=1
local p1 = math.tan(aoa)
local y = math.cos(roll)*p1
local x = math.sqrt(p1^2-y^2)
local pitch = math.atan(y)
local yaw=math.atan(x)*math.sign(roll)
return pitch,yaw
end
local function lerp(a, b, c)
return a + (b - a) * c
return a + (b - a) * c
end
function airutils.quadBezier(t, p0, p1, p2)
local l1 = lerp(p0, p1, t)
local l2 = lerp(p1, p2, t)
local quad = lerp(l1, l2, t)
return quad
local l1 = lerp(p0, p1, t)
local l2 = lerp(p1, p2, t)
local quad = lerp(l1, l2, t)
return quad
end
function airutils.get_ground_effect_lift(self, curr_pos, lift, wingspan)
@ -303,15 +303,15 @@ function airutils.getLiftAccel(self, velocity, accel, longit_speed, roll, curr_p
--to decrease the lift coefficient at hight altitudes
local curr_percent_height = (100 - ((curr_pos.y * 100) / max_height))/100
local rotation=self.object:get_rotation()
local vrot = airutils.dir_to_rot(velocity,rotation)
local hpitch,hyaw = pitchroll2pitchyaw(angle_of_attack,roll)
local rotation=self.object:get_rotation()
local vrot = airutils.dir_to_rot(velocity,rotation)
local hpitch,hyaw = pitchroll2pitchyaw(angle_of_attack,roll)
local hrot = {x=vrot.x+hpitch,y=vrot.y-hyaw,z=roll}
local hdir = airutils.rot_to_dir(hrot) --(hrot)
local cross = vector.cross(velocity,hdir)
local lift_dir = vector.normalize(vector.cross(cross,hdir))
local hrot = {x=vrot.x+hpitch,y=vrot.y-hyaw,z=roll}
local hdir = airutils.rot_to_dir(hrot) --(hrot)
local cross = vector.cross(velocity,hdir)
local lift_dir = vector.normalize(vector.cross(cross,hdir))
local lift_coefficient = (0.24*math.abs(daoa)*(1/(0.025*daoa+3))^4*math.sign(daoa))
local lift_val = math.abs((lift*(vector.length(striped_velocity)^2)*lift_coefficient)*curr_percent_height)
@ -383,7 +383,7 @@ function airutils.set_paint(self, puncher, itmstck, texture_name)
if item_name == "automobiles_lib:painter" or item_name == "bike:painter" then
--painting with bike painter
local meta = itmstck:get_meta()
local colstr = meta:get_string("paint_color")
local colstr = meta:get_string("paint_color")
--minetest.chat_send_all(dump(colstr))
airutils.paint(self, colstr, texture_name)
return true
@ -398,18 +398,18 @@ function airutils.set_paint(self, puncher, itmstck, texture_name)
if x then color = clr end
end]]--
--lets paint!!!!
local color = (item_name:sub(indx+1)):gsub(":", "")
local colstr = airutils.colors[color]
local color = (item_name:sub(indx+1)):gsub(":", "")
local colstr = airutils.colors[color]
--minetest.chat_send_all(color ..' '.. dump(colstr))
if colstr then
if colstr then
airutils.paint(self, colstr, texture_name)
if self._alternate_painting_texture and self._mask_painting_texture then
airutils.paint_with_mask(self, colstr, self._alternate_painting_texture, self._mask_painting_texture)
end
itmstck:set_count(itmstck:get_count()-1)
itmstck:set_count(itmstck:get_count()-1)
if puncher ~= nil then puncher:set_wielded_item(itmstck) end
return true
end
end
-- end painting
end
end
@ -428,7 +428,7 @@ function airutils.paint(self, colstr, texture_name)
l_textures[_] = texture_name.."^[multiply:".. colstr
end
end
self.object:set_properties({textures=l_textures})
self.object:set_properties({textures=l_textures})
end
end
@ -481,12 +481,12 @@ minetest.register_chatcommand("transfer_ownership", {
params = "<new_owner>",
description = "Transfer the property of a plane to another player",
privs = {interact=true},
func = function(name, param)
func = function(name, param)
local player = minetest.get_player_by_name(name)
local target_player = minetest.get_player_by_name(param)
local attached_to = player:get_attach()
if attached_to ~= nil then
if attached_to ~= nil then
if target_player ~= nil then
local seat = attached_to:get_attach()
if seat ~= nil then
@ -503,22 +503,22 @@ minetest.register_chatcommand("transfer_ownership", {
else
minetest.chat_send_player(name,core.colorize('#ff0000', " >>> the target player must be logged in"))
end
else
minetest.chat_send_player(name,core.colorize('#ff0000', " >>> you are not inside a plane to perform the command"))
end
end
else
minetest.chat_send_player(name,core.colorize('#ff0000', " >>> you are not inside a plane to perform the command"))
end
end
})
minetest.register_chatcommand("eject_from_plane", {
params = "",
description = "Ejects from a plane",
privs = {interact = true},
func = function(name, param)
params = "",
description = "Ejects from a plane",
privs = {interact = true},
func = function(name, param)
local colorstring = core.colorize('#ff0000', " >>> you are not inside a plane")
local player = minetest.get_player_by_name(name)
local attached_to = player:get_attach()
if attached_to ~= nil then
if attached_to ~= nil then
local seat = attached_to:get_attach()
if seat ~= nil then
local entity = seat:get_luaentity()
@ -531,12 +531,12 @@ minetest.register_chatcommand("eject_from_plane", {
airutils.dettach_pax(entity, passenger)
end
else
minetest.chat_send_player(name,colorstring)
minetest.chat_send_player(name,colorstring)
end
end
end
else
minetest.chat_send_player(name,colorstring)
end
end
else
minetest.chat_send_player(name,colorstring)
end
end
})

View File

@ -18,89 +18,89 @@ local function get_formspec_by_size(self, size)
hotbar = default.get_hotbar_bg(0,4.85)
end
local default_inventory_formspecs = {
["2"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;3.0,0;3,1;]" .. airutils.get_itemslot_bg(3.0, 0, 2, 1) ..
"list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["2"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;3.0,0;3,1;]" .. airutils.get_itemslot_bg(3.0, 0, 2, 1) ..
"list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["3"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;2.5,0;3,1;]" .. airutils.get_itemslot_bg(2.5, 0, 3, 1) ..
"list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["3"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;2.5,0;3,1;]" .. airutils.get_itemslot_bg(2.5, 0, 3, 1) ..
"list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["4"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;2,0;4,1;]" .. airutils.get_itemslot_bg(2.0, 0, 4, 1) ..
"list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["4"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;2,0;4,1;]" .. airutils.get_itemslot_bg(2.0, 0, 4, 1) ..
"list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["6"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;1,0;6,1;]".. airutils.get_itemslot_bg(1.0, 0, 6, 1) ..
"list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["6"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;1,0;6,1;]".. airutils.get_itemslot_bg(1.0, 0, 6, 1) ..
"list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["8"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,1;]".. airutils.get_itemslot_bg(0, 0, 8, 1) ..
"list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["8"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,1;]".. airutils.get_itemslot_bg(0, 0, 8, 1) ..
"list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["12"]="size[8,7]".. background ..
"list[detached:" .. self._inv_id .. ";main;1,0;6,2;]".. airutils.get_itemslot_bg(1, 0, 6, 2) ..
"list[current_player;main;0,3;8,4;]" .. airutils.get_itemslot_bg(0, 3, 8, 4) ..
"listring[]",
["12"]="size[8,7]".. background ..
"list[detached:" .. self._inv_id .. ";main;1,0;6,2;]".. airutils.get_itemslot_bg(1, 0, 6, 2) ..
"list[current_player;main;0,3;8,4;]" .. airutils.get_itemslot_bg(0, 3, 8, 4) ..
"listring[]",
["16"]="size[8,7]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,2;]".. airutils.get_itemslot_bg(0, 0, 8, 2) ..
"list[current_player;main;0,3;8,4;]" .. airutils.get_itemslot_bg(0, 3, 8, 4) ..
"listring[]",
["16"]="size[8,7]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,2;]".. airutils.get_itemslot_bg(0, 0, 8, 2) ..
"list[current_player;main;0,3;8,4;]" .. airutils.get_itemslot_bg(0, 3, 8, 4) ..
"listring[]",
["24"]="size[8,8]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,3;]".. airutils.get_itemslot_bg(0, 0, 8, 3) ..
"list[current_player;main;0,4;8,4;]" .. airutils.get_itemslot_bg(0, 4, 8, 4) ..
"listring[]",
["24"]="size[8,8]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,3;]".. airutils.get_itemslot_bg(0, 0, 8, 3) ..
"list[current_player;main;0,4;8,4;]" .. airutils.get_itemslot_bg(0, 4, 8, 4) ..
"listring[]",
["32"]="size[8,9]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0.3;8,4;]".. airutils.get_itemslot_bg(0, 0.3, 8, 4) ..
"list[current_player;main;0,5;8,4;]".. airutils.get_itemslot_bg(0, 5, 8, 4) ..
"listring[]" ..
hotbar,
["32"]="size[8,9]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0.3;8,4;]".. airutils.get_itemslot_bg(0, 0.3, 8, 4) ..
"list[current_player;main;0,5;8,4;]".. airutils.get_itemslot_bg(0, 5, 8, 4) ..
"listring[]" ..
hotbar,
["50"]="size[10,10]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;10,5;]".. airutils.get_itemslot_bg(0, 0, 10, 5) ..
"list[current_player;main;1,6;8,4;]" .. airutils.get_itemslot_bg(1, 6, 8, 4) ..
"listring[]",
["50"]="size[10,10]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;10,5;]".. airutils.get_itemslot_bg(0, 0, 10, 5) ..
"list[current_player;main;1,6;8,4;]" .. airutils.get_itemslot_bg(1, 6, 8, 4) ..
"listring[]",
}
local formspec = default_inventory_formspecs[tostring(size)]
return formspec
local formspec = default_inventory_formspecs[tostring(size)]
return formspec
end
local function inventory_id(maker_name)
local id= airutils.modname .. "_" .. maker_name .. "_"
for i=0,5 do
id=id..(math.random(0,9))
end
return id
local id= airutils.modname .. "_" .. maker_name .. "_"
for i=0,5 do
id=id..(math.random(0,9))
end
return id
end
function airutils.load_inventory(self)
if self._inv then
local inv_content = minetest.deserialize(storage:get_string(self._inv_id))
if self._inv then
local inv_content = minetest.deserialize(storage:get_string(self._inv_id))
if inv_content then
self._inv:set_list("main", inv_content)
self._inv:set_list("main", inv_content)
end
end
end
end
function airutils.save_inventory(self)
if self._inv then
local inv_content = self._inv:get_list("main")
local inv_content = self._inv:get_list("main")
if inv_content then
for k, v in pairs(inv_content) do
inv_content[k] = v:to_string()
end
for k, v in pairs(inv_content) do
inv_content[k] = v:to_string()
end
local inv_content = minetest.serialize(inv_content)
storage:set_string(self._inv_id, inv_content)
local inv_content = minetest.serialize(inv_content)
storage:set_string(self._inv_id, inv_content)
end
end
end
@ -109,7 +109,7 @@ function airutils.remove_inventory(self)
local inventory = airutils.get_inventory(self)
if inventory then
if inventory:is_empty("main") then
return minetest.remove_detached_inventory(self._inv_id)
return minetest.remove_detached_inventory(self._inv_id)
else
local inv_content = inventory:get_list("main")
if inv_content then
@ -163,24 +163,24 @@ function airutils.create_inventory(self, size, owner)
allow_take = function(inv, listname, index, stack, player)
return stack:get_count() -- allow taking
end,
on_put = function(inv, toList, toIndex, stack, player)
on_put = function(inv, toList, toIndex, stack, player)
airutils.save_inventory(self)
end,
on_take = function(inv, toList, toIndex, stack, player)
end,
on_take = function(inv, toList, toIndex, stack, player)
airutils.save_inventory(self)
end,
end,
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
airutils.save_inventory(self)
end,
})
if size >= 8 then
if vehicle_inv:set_size("main", size) then
vehicle_inv:set_width("main", 8)
vehicle_inv:set_width("main", 8)
end
else
vehicle_inv:set_size("main", size)
end
self._inv = vehicle_inv
self._inv = vehicle_inv
airutils.load_inventory(self)
end
end

View File

@ -39,9 +39,9 @@ function airutils.control(self, dtime, hull_direction, longit_speed, longit_drag
local stop = false
local ctrl = nil
-- player control
if player then
ctrl = player:get_player_control()
-- player control
if player then
ctrl = player:get_player_control()
if ctrl.aux1 and self._last_time_command > 0.5 then
self._last_time_command = 0
@ -96,14 +96,14 @@ function airutils.control(self, dtime, hull_direction, longit_speed, longit_drag
end
self._acceleration = engineacc
else
local paddleacc = 0
if longit_speed < 1.0 then
local paddleacc = 0
if longit_speed < 1.0 then
if ctrl.jump then paddleacc = 0.5 end
end
if longit_speed > -1.0 then
if longit_speed > -1.0 then
if ctrl.sneak then paddleacc = -0.5 end
end
self._acceleration = paddleacc
end
self._acceleration = paddleacc
end
local hull_acc = vector.multiply(hull_direction,self._acceleration)
@ -118,10 +118,10 @@ function airutils.control(self, dtime, hull_direction, longit_speed, longit_drag
airutils.set_pitch(self, pitch_cmd, dtime)
end
-- yaw
-- yaw
local yaw_cmd = 0
if self._yaw_by_mouse == true then
local rot_y = math.deg(player:get_look_horizontal())
local rot_y = math.deg(player:get_look_horizontal())
airutils.set_yaw_by_mouse(self, rot_y)
else
if ctrl.right then yaw_cmd = 1 elseif ctrl.left then yaw_cmd = -1 end
@ -145,7 +145,7 @@ function airutils.control(self, dtime, hull_direction, longit_speed, longit_drag
self._yaw_by_mouse = true
end
end
end
end
if longit_speed > 0 then
if ctrl then
@ -167,7 +167,7 @@ end
function airutils.set_pitch_by_mouse(self, player)
local vehicle_rot = self.object:get_rotation()
local rot_x = player:get_look_vertical()-vehicle_rot.x
self._elevator_angle = -(rot_x * self._elevator_limit)*(self._pitch_intensity*10)
self._elevator_angle = -(rot_x * self._elevator_limit)*(self._pitch_intensity*10)
if self._elevator_angle > self._elevator_limit then self._elevator_angle = self._elevator_limit end
if self._elevator_angle < -self._elevator_limit then self._elevator_angle = -self._elevator_limit end
end
@ -175,29 +175,29 @@ end
function airutils.set_pitch(self, dir, dtime)
local pitch_factor = self._pitch_intensity or 0.6
local multiplier = pitch_factor*(dtime/airutils.ideal_step)
if dir == -1 then
if dir == -1 then
--minetest.chat_send_all("cabrando")
if self._elevator_angle > 0 then pitch_factor = pitch_factor * 2 end
self._elevator_angle = math.max(self._elevator_angle-multiplier,-self._elevator_limit)
elseif dir == 1 then
self._elevator_angle = math.max(self._elevator_angle-multiplier,-self._elevator_limit)
elseif dir == 1 then
--minetest.chat_send_all("picando")
if self._angle_of_attack < 0 then pitch_factor = 1 end --lets reduce the command power to avoid accidents
self._elevator_angle = math.min(self._elevator_angle+multiplier,self._elevator_limit)
end
self._elevator_angle = math.min(self._elevator_angle+multiplier,self._elevator_limit)
end
end
function airutils.set_autopilot_pitch(self, dir, dtime)
local pitch_factor = 0.05
local multiplier = pitch_factor*(dtime/airutils.ideal_step)
if dir == -1 then
if dir == -1 then
--minetest.chat_send_all("cabrando")
if self._elevator_angle > 0 then pitch_factor = pitch_factor * 2 end
self._elevator_angle = math.max(self._elevator_angle-multiplier,-self._elevator_limit)
elseif dir == 1 then
self._elevator_angle = math.max(self._elevator_angle-multiplier,-self._elevator_limit)
elseif dir == 1 then
--minetest.chat_send_all("picando")
if self._angle_of_attack < 0 then pitch_factor = 1 end --lets reduce the command power to avoid accidents
self._elevator_angle = math.min(self._elevator_angle+multiplier,self._elevator_limit)
end
self._elevator_angle = math.min(self._elevator_angle+multiplier,self._elevator_limit)
end
end
function airutils.set_yaw_by_mouse(self, dir)
@ -217,16 +217,16 @@ function airutils.set_yaw_by_mouse(self, dir)
elseif command > 90 then command = 90 end
--minetest.chat_send_all("rotation y: "..rot_y.." - dir: "..dir.." - command: "..command)
self._rudder_angle = (-command * self._rudder_limit)/90
self._rudder_angle = (-command * self._rudder_limit)/90
end
function airutils.set_yaw(self, dir, dtime)
local yaw_factor = self._yaw_intensity or 25
if dir == 1 then
self._rudder_angle = math.max(self._rudder_angle-(yaw_factor*dtime),-self._rudder_limit)
elseif dir == -1 then
self._rudder_angle = math.min(self._rudder_angle+(yaw_factor*dtime),self._rudder_limit)
end
if dir == 1 then
self._rudder_angle = math.max(self._rudder_angle-(yaw_factor*dtime),-self._rudder_limit)
elseif dir == -1 then
self._rudder_angle = math.min(self._rudder_angle+(yaw_factor*dtime),self._rudder_limit)
end
end
function airutils.rudder_auto_correction(self, longit_speed, dtime)
@ -302,7 +302,7 @@ function airutils.autopilot(self, dtime, hull_direction, longit_speed, accel, cu
airutils.set_autopilot_pitch(self, -1, dtime)
end
-- yaw
-- yaw
airutils.set_yaw(self, 0, dtime)
if longit_speed > 0 then

View File

@ -1,27 +1,27 @@
function airutils.physics(self)
local friction = self._ground_friction or 0.99
local vel=self.object:get_velocity()
local vel=self.object:get_velocity()
local new_velocity = vel
--buoyancy
local surface = nil
local surfnodename = nil
local spos = airutils.get_stand_pos(self)
--buoyancy
local surface = nil
local surfnodename = nil
local spos = airutils.get_stand_pos(self)
if not spos then return end
spos.y = spos.y+0.01
-- get surface height
local snodepos = airutils.get_node_pos(spos)
local surfnode = airutils.nodeatpos(spos)
while surfnode and (surfnode.drawtype == 'liquid' or surfnode.drawtype == 'flowingliquid') do
surfnodename = surfnode.name
surface = snodepos.y +0.5
if surface > spos.y+self.height then break end
snodepos.y = snodepos.y+1
surfnode = airutils.nodeatpos(snodepos)
end
spos.y = spos.y+0.01
-- get surface height
local snodepos = airutils.get_node_pos(spos)
local surfnode = airutils.nodeatpos(spos)
while surfnode and (surfnode.drawtype == 'liquid' or surfnode.drawtype == 'flowingliquid') do
surfnodename = surfnode.name
surface = snodepos.y +0.5
if surface > spos.y+self.height then break end
snodepos.y = snodepos.y+1
surfnode = airutils.nodeatpos(snodepos)
end
self.isinliquid = surfnodename
if surface then -- standing in liquid
self.isinliquid = surfnodename
if surface then -- standing in liquid
self.isinliquid = true
end
@ -30,9 +30,9 @@ function airutils.physics(self)
self.water_drag = 0.2
self.isinliquid = true
local height = self.height
local submergence = math.min(surface-spos.y,height)/height
-- local balance = self.buoyancy*self.height
local buoyacc = airutils.gravity*(self.buoyancy-submergence)
local submergence = math.min(surface-spos.y,height)/height
-- local balance = self.buoyancy*self.height
local buoyacc = airutils.gravity*(self.buoyancy-submergence)
--local buoyacc = self._baloon_buoyancy*(self.buoyancy-submergence)
accell = {x=-vel.x*self.water_drag,y=buoyacc-(vel.y*math.abs(vel.y)*0.4),z=-vel.z*self.water_drag}
if self.buoyancy >= 1 then self._engine_running = false end
@ -40,36 +40,36 @@ function airutils.physics(self)
--new_velocity = vector.add(new_velocity, vector.multiply(accell, self.dtime))
self.object:move_to(self.object:get_pos())
return
else
else
airutils.set_acceleration(self.object,{x=0,y=airutils.gravity,z=0})
self.isinliquid = false
self.isinliquid = false
--new_velocity = vector.add(new_velocity, {x=0,y=airutils.gravity * self.dtime,z=0})
end
end
if self.isonground and not self.isinliquid then
--dumb friction
new_velocity = {x=new_velocity.x*friction,
y=new_velocity.y,
z=new_velocity.z*friction}
y=new_velocity.y,
z=new_velocity.z*friction}
-- bounciness
if self.springiness and self.springiness > 0 and self.buoyancy >= 1 then
local vnew = vector.new(new_velocity)
if not self.collided then -- ugly workaround for inconsistent collisions
for _,k in ipairs({'y','z','x'}) do
if new_velocity[k]==0 and math.abs(self.lastvelocity[k])> 0.1 then
vnew[k]=-self.lastvelocity[k]*self.springiness
end
end
if not self.collided then -- ugly workaround for inconsistent collisions
for _,k in ipairs({'y','z','x'}) do
if new_velocity[k]==0 and math.abs(self.lastvelocity[k])> 0.1 then
vnew[k]=-self.lastvelocity[k]*self.springiness
end
end
end
if not vector.equals(new_velocity,vnew) then
self.collided = true
self.collided = true
else
if self.collided then
vnew = vector.new(self.lastvelocity)
end
self.collided = false
if self.collided then
vnew = vector.new(self.lastvelocity)
end
self.collided = false
end
new_velocity = vnew
end

View File

@ -70,7 +70,7 @@ function airutils.on_activate(self, staticdata, dtime_s)
airutils.param_paint(self, self._color, self._color_2)
self.object:set_armor_groups({immortal=1})
self.object:set_armor_groups({immortal=1})
local start_frame = 1
local end_frame = self._anim_frames
@ -84,12 +84,12 @@ function airutils.on_activate(self, staticdata, dtime_s)
self.wheels:set_animation({x = 1, y = self._anim_frames}, 0, 0, true)
end
local inv = minetest.get_inventory({type = "detached", name = self._inv_id})
-- if the game was closed the inventories have to be made anew, instead of just reattached
if not inv then
local inv = minetest.get_inventory({type = "detached", name = self._inv_id})
-- if the game was closed the inventories have to be made anew, instead of just reattached
if not inv then
airutils.create_inventory(self, self._trunk_slots)
else
self.inv = inv
else
self.inv = inv
end
airutils.seats_create(self)
@ -110,13 +110,13 @@ function airutils.on_step(self,dtime,colinfo)
local vel = self.object:get_velocity()
if colinfo then
self.isonground = colinfo.touching_ground
self.isonground = colinfo.touching_ground
else
if self.lastvelocity.y==0 and vel.y==0 then
self.isonground = true
else
self.isonground = false
end
if self.lastvelocity.y==0 and vel.y==0 then
self.isonground = true
else
self.isonground = false
end
end
if self.hp_max <= 0 then
@ -126,7 +126,7 @@ function airutils.on_step(self,dtime,colinfo)
self:physics()
if self.logic then
self:logic()
self:logic()
end
self.lastvelocity = self.object:get_velocity()
@ -222,23 +222,23 @@ function airutils.logic(self)
local accel_y = self.object:get_acceleration().y
local rotation = self.object:get_rotation()
local yaw = rotation.y
local newyaw=yaw
local newyaw=yaw
local pitch = rotation.x
local roll = rotation.z
local newroll=roll
local roll = rotation.z
local newroll=roll
newroll = math.floor(newroll/360)
newroll = newroll * 360
local hull_direction = airutils.rot_to_dir(rotation) --minetest.yaw_to_dir(yaw)
local nhdir = {x=hull_direction.z,y=0,z=-hull_direction.x} -- lateral unit vector
local nhdir = {x=hull_direction.z,y=0,z=-hull_direction.x} -- lateral unit vector
local longit_speed = vector.dot(velocity,hull_direction)
self._longit_speed = longit_speed
local longit_drag = vector.multiply(hull_direction,longit_speed*
longit_speed*self._longit_drag_factor*-1*airutils.sign(longit_speed))
local later_speed = airutils.dot(velocity,nhdir)
local later_speed = airutils.dot(velocity,nhdir)
--minetest.chat_send_all('later_speed: '.. later_speed)
local later_drag = vector.multiply(nhdir,later_speed*later_speed*
local later_drag = vector.multiply(nhdir,later_speed*later_speed*
self._later_drag_factor*-1*airutils.sign(later_speed))
local accel = vector.add(longit_drag,later_drag)
local stop = false
@ -253,7 +253,7 @@ function airutils.logic(self)
local is_attached = airutils.checkAttach(self, player)
if self._indicated_speed == nil then self._indicated_speed = 0 end
if not is_attached then
if not is_attached then
-- for some engine error the player can be detached from the machine, so lets set him attached again
airutils.checkattachBug(self)
end
@ -365,12 +365,12 @@ function airutils.logic(self)
end
-- new yaw
if math.abs(self._rudder_angle)>1.5 then
if math.abs(self._rudder_angle)>1.5 then
local turn_rate = math.rad(self._yaw_turn_rate)
local yaw_turn = self.dtime * math.rad(self._rudder_angle) * turn_rate *
airutils.sign(longit_speed) * math.abs(longit_speed/2)
newyaw = yaw + yaw_turn
end
newyaw = yaw + yaw_turn
end
--roll adjust
---------------------------------
@ -378,7 +378,7 @@ function airutils.logic(self)
if is_flying then
local roll_reference = newyaw
local sdir = minetest.yaw_to_dir(roll_reference)
local snormal = {x=sdir.z,y=0,z=-sdir.x} -- rightside, dot is negative
local snormal = {x=sdir.z,y=0,z=-sdir.x} -- rightside, dot is negative
local prsr = airutils.dot(snormal,nhdir)
local rollfactor = -90
local roll_rate = math.rad(10)
@ -434,8 +434,8 @@ function airutils.logic(self)
accel.y = accel_y
--lets apply some bob in water
if self.isinliquid then
local bob = airutils.minmax(airutils.dot(accel,hull_direction),0.02) -- vertical bobbing
if self.isinliquid then
local bob = airutils.minmax(airutils.dot(accel,hull_direction),0.02) -- vertical bobbing
if bob < 0 then bob = 0 end
accel.y = accel.y + bob
local max_pitch = 6
@ -480,7 +480,7 @@ function airutils.logic(self)
if stop ~= true then --maybe == nil
self._last_accell = new_accel
self.object:move_to(curr_pos)
self.object:move_to(curr_pos)
--self.object:set_velocity(velocity)
--[[if player then
airutils.attach(self, player, self._instruction_mode)
@ -548,7 +548,7 @@ function airutils.logic(self)
local turn_rate = math.rad(30)
local yaw_turn = self.dtime * math.rad(self._rudder_angle) * turn_rate *
airutils.sign(longit_speed) * math.abs(longit_speed/2)
newyaw = yaw + yaw_turn
newyaw = yaw + yaw_turn
end
if player and self._use_camera_relocation then
@ -600,9 +600,9 @@ local function damage_vehicle(self, toolcaps, ttime, damage)
local tmp = ttime / (toolcaps.full_punch_interval or 1.4)
if tmp < 0 then
tmp = 0.0
tmp = 0.0
elseif tmp > 1 then
tmp = 1.0
tmp = 1.0
end
damage = damage + (toolcaps.damage_groups[group] or 0) * tmp
@ -612,7 +612,7 @@ local function damage_vehicle(self, toolcaps, ttime, damage)
end
function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage)
local name = puncher:get_player_name()
local name = puncher:get_player_name()
if self.hp_max <= 0 then
airutils.destroy(self, name)
end
@ -627,8 +627,8 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage)
--end
if not puncher or not puncher:is_player() then
return
end
return
end
local is_admin = false
is_admin = minetest.check_player_privs(puncher, {server=true})
@ -638,11 +638,11 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage)
if self.owner == nil then
self.owner = name
end
if self.driver_name and self.driver_name ~= name then
-- do not allow other players to remove the object while there is a driver
return
end
-- do not allow other players to remove the object while there is a driver
return
end
local is_attached = false
local player_attach = puncher:get_attach()
@ -687,12 +687,12 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage)
end
-- deal with painting or destroying
if itmstck then
if airutils.set_param_paint(self, puncher, itmstck, 1) == false then
if not self.driver and toolcaps and toolcaps.damage_groups
if itmstck then
if airutils.set_param_paint(self, puncher, itmstck, 1) == false then
if not self.driver and toolcaps and toolcaps.damage_groups
and toolcaps.groupcaps and (toolcaps.groupcaps.choppy or toolcaps.groupcaps.axey_dig) and item_name ~= airutils.fuel then
--airutils.hurt(self,toolcaps.damage_groups.fleshy - 1)
--airutils.make_sound(self,'hit')
--airutils.hurt(self,toolcaps.damage_groups.fleshy - 1)
--airutils.make_sound(self,'hit')
damage_vehicle(self, toolcaps, ttime, damage)
minetest.sound_play(self._collision_sound, {
object = self.object,
@ -702,8 +702,8 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage)
pitch = 1.0,
})
airutils.setText(self, self._vehicle_name)
end
end
end
end
end
if self.hp_max <= 0 then
@ -716,9 +716,9 @@ end
function airutils.on_rightclick(self, clicker)
local message = ""
if not clicker or not clicker:is_player() then
return
end
if not clicker or not clicker:is_player() then
return
end
local name = clicker:get_player_name()
@ -788,10 +788,10 @@ function airutils.on_rightclick(self, clicker)
local item_name = ""
if itmstck then item_name = itmstck:get_name() end
if itmstck then
if airutils.set_param_paint(self, clicker, itmstck, 2) == true then
if itmstck then
if airutils.set_param_paint(self, clicker, itmstck, 2) == true then
return
end
end
end
if clicker:get_player_control().aux1 == true then --lets see the inventory

View File

@ -47,17 +47,17 @@ function airutils.pilot_formspec(name)
local ver_pos = 1.0
local basic_form = ""
basic_form = basic_form.."button[1,"..ver_pos..";4,1;turn_on;Start/Stop Engines]"
basic_form = basic_form.."button[1,"..ver_pos..";4,1;turn_on;Start/Stop Engines]"
ver_pos = ver_pos + 1.1
basic_form = basic_form.."button[1,"..ver_pos..";4,1;hud;Show/Hide Gauges]"
basic_form = basic_form.."button[1,"..ver_pos..";4,1;hud;Show/Hide Gauges]"
ver_pos = ver_pos + 1.1
basic_form = basic_form.."button[1,"..ver_pos..";4,1;inventory;Show Inventory]"
basic_form = basic_form.."button[1,"..ver_pos..";4,1;inventory;Show Inventory]"
ver_pos = ver_pos + 1.5
basic_form = basic_form.."checkbox[1,"..ver_pos..";yaw;Yaw by mouse;"..yaw.."]"
ver_pos = ver_pos + 0.5
basic_form = basic_form.."button[1,"..ver_pos..";4,1;go_out;Go Out!]"
basic_form = basic_form.."button[1,"..ver_pos..";4,1;go_out;Go Out!]"
--form second part
local expand_form = false
@ -93,7 +93,7 @@ function airutils.pilot_formspec(name)
end
if ent._have_manual then
basic_form = basic_form.."button[6,5.2;4,1;manual;Manual]"
basic_form = basic_form.."button[6,5.2;4,1;manual;Manual]"
expand_form = true
end
@ -102,7 +102,7 @@ function airutils.pilot_formspec(name)
local form = table.concat({
"formspec_version[3]",
"size["..form_width..",7.2]",
}, "")
}, "")
minetest.show_formspec(name, "lib_planes:pilot_main", form..basic_form)
end
@ -123,7 +123,7 @@ function airutils.manage_copilot_formspec(name)
local basic_form = table.concat({
"formspec_version[3]",
"size[6,4.5]",
}, "")
}, "")
basic_form = basic_form.."label[1,1.0;Bring a copilot:]"
@ -167,7 +167,7 @@ function airutils.adf_formspec(name)
local basic_form = table.concat({
"formspec_version[3]",
"size[6,3.5]",
}, "")
}, "")
basic_form = basic_form.."checkbox[1.0,1.0;adf;Auto Direction Find;"..adf.."]"
basic_form = basic_form.."field[1.0,1.7;1.5,0.6;adf_x;pos x;"..x.."]"
@ -181,10 +181,10 @@ function airutils.pax_formspec(name)
local basic_form = table.concat({
"formspec_version[3]",
"size[6,5]",
}, "")
}, "")
basic_form = basic_form.."button[1,1.0;4,1;new_seat;Change Seat]"
basic_form = basic_form.."button[1,2.5;4,1;go_out;Go Offboard]"
basic_form = basic_form.."button[1,1.0;4,1;new_seat;Change Seat]"
basic_form = basic_form.."button[1,2.5;4,1;go_out;Go Offboard]"
minetest.show_formspec(name, "lib_planes:passenger_main", basic_form)
end
@ -193,11 +193,11 @@ function airutils.go_out_confirmation_formspec(name)
local basic_form = table.concat({
"formspec_version[3]",
"size[7,2.2]",
}, "")
}, "")
basic_form = basic_form.."label[0.5,0.5;Do you really want to go offboard now?]"
basic_form = basic_form.."button[1.3,1.0;2,0.8;no;No]"
basic_form = basic_form.."button[3.6,1.0;2,0.8;yes;Yes]"
basic_form = basic_form.."button[1.3,1.0;2,0.8;no;No]"
basic_form = basic_form.."button[3.6,1.0;2,0.8;yes;Yes]"
minetest.show_formspec(name, "lib_planes:go_out_confirmation_form", basic_form)
end
@ -212,13 +212,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
local ent = plane_obj:get_luaentity()
if ent then
if fields.yes then
if fields.yes then
airutils.dettach_pax(ent, player)
end
end
end
minetest.close_formspec(name, "lib_planes:go_out_confirmation_form")
end
if formname == "lib_planes:adf_main" then
if formname == "lib_planes:adf_main" then
local name = player:get_player_name()
local plane_obj = airutils.getPlaneFromPlayer(player)
if plane_obj == nil then
@ -257,8 +257,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
minetest.chat_send_player(name, core.colorize('#ff0000', " >>> There is something wrong on ADF saving..."))
end
minetest.close_formspec(name, "lib_planes:adf_main")
end
if formname == "lib_planes:passenger_main" then
end
if formname == "lib_planes:passenger_main" then
local name = player:get_player_name()
local plane_obj = airutils.getPlaneFromPlayer(player)
if plane_obj == nil then
@ -267,29 +267,29 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
local ent = plane_obj:get_luaentity()
if ent then
if fields.new_seat then
if fields.new_seat then
airutils.dettach_pax(ent, player)
airutils.attach_pax(ent, player)
end
if fields.go_out then
end
if fields.go_out then
local touching_ground, liquid_below = airutils.check_node_below(plane_obj, 2.5)
if ent.isinliquid or touching_ground then --isn't flying?
airutils.dettach_pax(ent, player)
else
airutils.go_out_confirmation_formspec(name)
end
end
end
end
minetest.close_formspec(name, "lib_planes:passenger_main")
end
if formname == "lib_planes:pilot_main" then
end
if formname == "lib_planes:pilot_main" then
local name = player:get_player_name()
local plane_obj = airutils.getPlaneFromPlayer(player)
if plane_obj then
local ent = plane_obj:get_luaentity()
if fields.turn_on then
if fields.turn_on then
airutils.start_engine(ent)
end
end
if fields.hud then
if ent._show_hud == true then
ent._show_hud = false
@ -297,7 +297,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
ent._show_hud = true
end
end
if fields.go_out then
if fields.go_out then
local touch_point = ent.initial_properties.collisionbox[2]-1.0
-----////
local is_on_ground = false
@ -338,7 +338,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
else --anyone
airutils.dettach_pax(ent, player)
end
end
end
if fields.inventory then
if ent._trunk_slots then
airutils.show_vehicle_trunk_formspec(ent, player, ent._trunk_slots)
@ -378,13 +378,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.adf_form then
airutils.adf_formspec(name)
end
if fields.turn_auto_pilot_on then
if fields.turn_auto_pilot_on then
if ent._autopilot == true then
ent._autopilot = false
else
ent._autopilot = true
end
end
end
if fields.manual then
if ent._have_manual then
ent._have_manual(name)
@ -402,7 +402,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
local ent = plane_obj:get_luaentity()
if fields.copilot then
if fields.copilot then
--look for a free seat first
local is_there_a_free_seat = false
for i = 2,1,-1
@ -430,16 +430,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
airutils.attach_pax(ent, new_copilot_player_obj, true)
end
end
end
if fields.pass_control then
end
if fields.pass_control then
if ent._command_is_given == true then
--take the control
airutils.transfer_control(ent, false)
--take the control
airutils.transfer_control(ent, false)
else
--trasnfer the control to student
airutils.transfer_control(ent, true)
--trasnfer the control to student
airutils.transfer_control(ent, true)
end
end
end
minetest.close_formspec(name, "lib_planes:manage_copilot")
end

View File

@ -55,6 +55,6 @@ function airutils.consumptionCalc(self, accel)
self._engine_running = false
self._autopilot = false
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
self.object:set_animation_frame_speed(0)
self.object:set_animation_frame_speed(0)
end
end

View File

@ -14,15 +14,15 @@ function airutils.get_hipotenuse_value(point1, point2)
end
function airutils.dot(v1,v2)
return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z
return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z
end
function airutils.sign(n)
return n>=0 and 1 or -1
return n>=0 and 1 or -1
end
function airutils.minmax(v,m)
return math.min(math.abs(v),m)*airutils.sign(v)
return math.min(math.abs(v),m)*airutils.sign(v)
end
function airutils.get_gauge_angle(value, initial_angle)
@ -30,7 +30,7 @@ function airutils.get_gauge_angle(value, initial_angle)
local angle = value * 18
angle = angle - initial_angle
angle = angle * -1
return angle
return angle
end
local function sit_player(player, name)
@ -38,7 +38,7 @@ local function sit_player(player, name)
player_api.player_attached[name] = true
player_api.set_animation(player, "sit")
elseif airutils.is_mcl then
mcl_player.player_attached[name] = true
mcl_player.player_attached[name] = true
mcl_player.player_set_animation(player, "sit" , 30)
airutils.sit(player)
end
@ -297,15 +297,15 @@ function airutils.destroy(self, by_name)
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'hidroplane:wings')
for i=1,6 do
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:steel_ingot')
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:steel_ingot')
end
for i=1,2 do
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'wool:white')
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'wool:white')
end
for i=1,6 do
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:mese_crystal')
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:mese_crystal')
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:diamond')
end]]--
@ -323,10 +323,10 @@ function airutils.testImpact(self, velocity, position)
local touch_point = self.initial_properties.collisionbox[2]-0.5
--lets calculate the vertical speed, to avoid the bug on colliding on floor with hard lag
if math.abs(velocity.y - self._last_vel.y) > impact_speed then
local noded = airutils.nodeatpos(airutils.pos_shift(p,{y=touch_point}))
if (noded and noded.drawtype ~= 'airlike') then
collision = true
else
local noded = airutils.nodeatpos(airutils.pos_shift(p,{y=touch_point}))
if (noded and noded.drawtype ~= 'airlike') then
collision = true
else
self.object:set_velocity(self._last_vel)
--self.object:set_acceleration(self._last_accell)
self.object:set_velocity(vector.add(velocity, vector.multiply(self._last_accell, self.dtime/8)))
@ -347,7 +347,7 @@ function airutils.testImpact(self, velocity, position)
if self._last_water_touch <= 3 then self._last_water_touch = self._last_water_touch + self.dtime end
if impact > 0.2 and self._longit_speed > 0.6 and self._last_water_touch >=3 then
local noded = airutils.nodeatpos(airutils.pos_shift(p,{y=touch_point}))
if (noded and noded.drawtype ~= 'airlike') then
if (noded and noded.drawtype ~= 'airlike') then
if noded.drawtype == 'liquid' then
self._last_water_touch = 0
minetest.sound_play("airutils_touch_water", {
@ -360,14 +360,14 @@ function airutils.testImpact(self, velocity, position)
}, true)
return
end
end
end
end
if self._last_touch == nil then self._last_touch = 1 end
if self._last_touch <= 1 then self._last_touch = self._last_touch + self.dtime end
if vertical_impact > 1.0 and self._longit_speed > self._min_speed/2 and self._last_touch >= 1 then
local noded = airutils.nodeatpos(airutils.pos_shift(p,{y=touch_point}))
if (noded and noded.drawtype ~= 'airlike') and (noded.drawtype ~= 'liquid') then
if (noded and noded.drawtype ~= 'airlike') and (noded.drawtype ~= 'liquid') then
self._last_touch = 0
if not self._ground_friction then self._ground_friction = 0.99 end
@ -390,7 +390,7 @@ function airutils.testImpact(self, velocity, position)
pitch = 1.0,
}, true)
end
end
end
end
--damage by speed
@ -461,18 +461,18 @@ function airutils.testImpact(self, velocity, position)
local player = minetest.get_player_by_name(player_name)
if player then
if player:get_hp() > 0 then
if player:get_hp() > 0 then
local hurt_by_impact_divisor = 0.5 --less is more
if self.hp_max > 0 then hurt_by_impact_divisor = 4 end
player:set_hp(player:get_hp()-(damage/hurt_by_impact_divisor))
end
player:set_hp(player:get_hp()-(damage/hurt_by_impact_divisor))
end
end
if self._passenger ~= nil then
local passenger = minetest.get_player_by_name(self._passenger)
if passenger then
if passenger:get_hp() > 0 then
passenger:set_hp(passenger:get_hp()-(damage/2))
end
if passenger:get_hp() > 0 then
passenger:set_hp(passenger:get_hp()-(damage/2))
end
end
end
end
@ -486,11 +486,11 @@ function airutils.checkattachBug(self)
-- attach the driver again
local player = minetest.get_player_by_name(self.owner)
if player then
if player:get_hp() > 0 then
if player:get_hp() > 0 then
airutils.attach(self, player, self._instruction_mode)
else
airutils.dettachPlayer(self, player)
end
end
else
if self._passenger ~= nil and self._command_is_given == false then
self._autopilot = false
@ -544,7 +544,7 @@ function airutils.set_param_paint(self, puncher, itmstck, mode)
self._skin = ""
--painting with bike painter
local meta = itmstck:get_meta()
local colour = meta:get_string("paint_color")
local colour = meta:get_string("paint_color")
local colstr = self._color
local colstr_2 = self._color_2
@ -565,7 +565,7 @@ function airutils.set_param_paint(self, puncher, itmstck, mode)
if x then color = clr end
end]]--
--lets paint!!!!
local color = (item_name:sub(indx+1)):gsub(":", "")
local color = (item_name:sub(indx+1)):gsub(":", "")
local colstr = self._color
local colstr_2 = self._color_2
@ -574,12 +574,12 @@ function airutils.set_param_paint(self, puncher, itmstck, mode)
--minetest.chat_send_all(color ..' '.. dump(colstr))
--minetest.chat_send_all(dump(airutils.colors))
if colstr then
if colstr then
airutils.param_paint(self, colstr, colstr_2)
itmstck:set_count(itmstck:get_count()-1)
itmstck:set_count(itmstck:get_count()-1)
if puncher ~= nil then puncher:set_wielded_item(itmstck) end
return true
end
end
-- end painting
end
end
@ -672,7 +672,7 @@ function airutils.paint_with_mask(self, colstr, target_texture, mask_texture)
l_textures[_] = "("..target_texture.."^[multiply:".. colstr..")^("..target_texture.."^[mask:"..mask_texture..")"
end
end
self.object:set_properties({textures=l_textures})
self.object:set_properties({textures=l_textures})
end
end
@ -712,22 +712,22 @@ function airutils.add_smoke_trail(self, smoke_type)
if self._smoke_spawner == nil then
local radius = 1
self._smoke_spawner = minetest.add_particlespawner({
amount = 3,
time = 0,
--minpos = vector.subtract(pos, radius / 2),
--maxpos = vector.add(pos, radius / 2),
minvel = {x = -1, y = -1, z = -1},
maxvel = {x = 1, y = 5, z = 1},
minacc = vector.new(),
maxacc = vector.new(),
self._smoke_spawner = minetest.add_particlespawner({
amount = 3,
time = 0,
--minpos = vector.subtract(pos, radius / 2),
--maxpos = vector.add(pos, radius / 2),
minvel = {x = -1, y = -1, z = -1},
maxvel = {x = 1, y = 5, z = 1},
minacc = vector.new(),
maxacc = vector.new(),
attached = self.object,
minexptime = 3,
maxexptime = 5.5,
minsize = 10,
maxsize = 15,
texture = smoke_texture,
})
minexptime = 3,
maxexptime = 5.5,
minsize = 10,
maxsize = 15,
texture = smoke_texture,
})
end
end
@ -735,7 +735,7 @@ function airutils.add_destruction_effects(pos, radius, w_fire)
if pos == nil then return end
w_fire = w_fire
if w_fire == nil then w_fire = true end
local node = airutils.nodeatpos(pos)
local node = airutils.nodeatpos(pos)
local is_liquid = false
if (node.drawtype == 'liquid' or node.drawtype == 'flowingliquid') then is_liquid = true end
@ -747,48 +747,48 @@ function airutils.add_destruction_effects(pos, radius, w_fire)
pitch = 1.0,
}, true)
if is_liquid == false and w_fire == true then
minetest.add_particle({
pos = pos,
velocity = vector.new(),
acceleration = vector.new(),
expirationtime = 0.4,
size = radius * 10,
collisiondetection = false,
vertical = false,
texture = "airutils_boom.png",
glow = 15,
})
minetest.add_particlespawner({
amount = 32,
time = 0.5,
minpos = vector.subtract(pos, radius / 2),
maxpos = vector.add(pos, radius / 2),
minvel = {x = -10, y = -10, z = -10},
maxvel = {x = 10, y = 10, z = 10},
minacc = vector.new(),
maxacc = vector.new(),
minexptime = 1,
maxexptime = 2.5,
minsize = radius * 3,
maxsize = radius * 5,
texture = "airutils_boom.png",
})
minetest.add_particle({
pos = pos,
velocity = vector.new(),
acceleration = vector.new(),
expirationtime = 0.4,
size = radius * 10,
collisiondetection = false,
vertical = false,
texture = "airutils_boom.png",
glow = 15,
})
minetest.add_particlespawner({
amount = 32,
time = 0.5,
minpos = vector.subtract(pos, radius / 2),
maxpos = vector.add(pos, radius / 2),
minvel = {x = -10, y = -10, z = -10},
maxvel = {x = 10, y = 10, z = 10},
minacc = vector.new(),
maxacc = vector.new(),
minexptime = 1,
maxexptime = 2.5,
minsize = radius * 3,
maxsize = radius * 5,
texture = "airutils_boom.png",
})
end
minetest.add_particlespawner({
amount = 64,
time = 1.0,
minpos = vector.subtract(pos, radius / 2),
maxpos = vector.add(pos, radius / 2),
minvel = {x = -10, y = -10, z = -10},
maxvel = {x = 10, y = 10, z = 10},
minacc = vector.new(),
maxacc = vector.new(),
minexptime = 1,
maxexptime = 2.5,
minsize = radius * 3,
maxsize = radius * 5,
texture = "airutils_smoke.png",
})
minetest.add_particlespawner({
amount = 64,
time = 1.0,
minpos = vector.subtract(pos, radius / 2),
maxpos = vector.add(pos, radius / 2),
minvel = {x = -10, y = -10, z = -10},
maxvel = {x = 10, y = 10, z = 10},
minacc = vector.new(),
maxacc = vector.new(),
minexptime = 1,
maxexptime = 2.5,
minsize = radius * 3,
maxsize = radius * 5,
texture = "airutils_smoke.png",
})
end
function airutils.add_blast_damage(pos, radius, damage_cal)
@ -797,9 +797,9 @@ function airutils.add_blast_damage(pos, radius, damage_cal)
damage_cal = damage_cal or 4
local objs = minetest.get_objects_inside_radius(pos, radius)
for _, obj in pairs(objs) do
local obj_pos = obj:get_pos()
local dist = math.max(1, vector.distance(pos, obj_pos))
for _, obj in pairs(objs) do
local obj_pos = obj:get_pos()
local dist = math.max(1, vector.distance(pos, obj_pos))
local damage = (damage_cal / dist) * radius
if obj:is_player() then
@ -809,28 +809,28 @@ function airutils.add_blast_damage(pos, radius, damage_cal)
-- object might have disappeared somehow
if luaobj then
local do_damage = true
local do_knockback = true
local entity_drops = {}
local objdef = minetest.registered_entities[luaobj.name]
local do_damage = true
local do_knockback = true
local entity_drops = {}
local objdef = minetest.registered_entities[luaobj.name]
if objdef and objdef.on_blast then
do_damage, do_knockback, entity_drops = objdef.on_blast(luaobj, damage)
end
if objdef and objdef.on_blast then
do_damage, do_knockback, entity_drops = objdef.on_blast(luaobj, damage)
end
if do_knockback then
local obj_vel = obj:get_velocity()
end
if do_damage then
if do_knockback then
local obj_vel = obj:get_velocity()
end
if do_damage then
obj:punch(obj, 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = damage},
}, nil)
end
for _, item in pairs(entity_drops) do
add_drop(drops, item)
end
end
end
for _, item in pairs(entity_drops) do
add_drop(drops, item)
end
end
end
end
@ -844,7 +844,7 @@ function airutils.add_blast_damage(pos, radius, damage_cal)
local r = vector.length(vector.new(x, y, z))
if (radius * radius) / (r * r) >= (pr:next(80, 125) / 100) then
local p = {x = pos.x + x, y = pos.y + y, z = pos.z + z}
local node = minetest.get_node(p).name
local node = minetest.get_node(p).name
if node == "tnt:tnt" then minetest.set_node(p, {name = "tnt:tnt_burning"}) end
end
end
@ -856,14 +856,14 @@ end
function airutils.start_engine(self)
if self._engine_running then
self._engine_running = false
self._engine_running = false
self._autopilot = false
self._power_lever = 0 --zero power
self._last_applied_power = 0 --zero engine
elseif self._engine_running == false and self._energy > 0 then
local curr_health_percent = (self.hp_max * 100)/self._max_plane_hp
if curr_health_percent > 20 then
self._engine_running = true
self._engine_running = true
self._last_applied_power = -1 --send signal to start
else
if self.driver_name then
@ -1045,10 +1045,10 @@ function airutils.rescueConnectionFailedPassengers(self)
if player:get_attach() == nil then
--if player_api.player_attached[self._passengers[i]] == nil then --but isn't attached?
--minetest.chat_send_all("okay")
if player:get_hp() > 0 then
if player:get_hp() > 0 then
self._passengers[i] = nil --clear the slot first
do_attach(self, player, i) --attach
end
end
end
end
end

View File

@ -8,19 +8,19 @@ function airutils.get_xz_from_hipotenuse(orig_x, orig_z, yaw, distance)
end
minetest.register_node("airutils:light", {
drawtype = "airlike",
--tile_images = {"airutils_light.png"},
inventory_image = minetest.inventorycube("airutils_light.png"),
paramtype = "light",
walkable = false,
is_ground_content = true,
light_propagates = true,
sunlight_propagates = true,
light_source = 14,
selection_box = {
type = "fixed",
fixed = {0, 0, 0, 0, 0, 0},
},
drawtype = "airlike",
--tile_images = {"airutils_light.png"},
inventory_image = minetest.inventorycube("airutils_light.png"),
paramtype = "light",
walkable = false,
is_ground_content = true,
light_propagates = true,
sunlight_propagates = true,
light_source = 14,
selection_box = {
type = "fixed",
fixed = {0, 0, 0, 0, 0, 0},
},
})
function airutils.remove_light(self)
@ -62,11 +62,11 @@ function airutils.put_light(self)
local lx, lz = airutils.get_xz_from_hipotenuse(pos.x, pos.z, yaw, 10)
local light_pos = {x=lx, y=pos.y, z=lz}
local cast = minetest.raycast(pos, light_pos, false, false)
local thing = cast:next()
local cast = minetest.raycast(pos, light_pos, false, false)
local thing = cast:next()
local was_set = false
while thing do
if thing.type == "node" then
while thing do
if thing.type == "node" then
local ipos = thing.intersection_point
if ipos then
was_set = airutils.swap_node(self, ipos)

View File

@ -12,171 +12,171 @@ local tan = math.tan
local pow = math.pow
local sign = function(x)
return (x<0) and -1 or 1
return (x<0) and -1 or 1
end
function airutils.rot_to_dir(rot) -- keep rot within <-pi/2,pi/2>
local dir = minetest.yaw_to_dir(rot.y)
dir.y = dir.y+tan(rot.x)*vector.length(dir)
return vector.normalize(dir)
local dir = minetest.yaw_to_dir(rot.y)
dir.y = dir.y+tan(rot.x)*vector.length(dir)
return vector.normalize(dir)
end
function airutils.dir_to_rot(v,rot)
rot = rot or {x=0,y=0,z=0}
return {x = (v.x==0 and v.y==0 and v.z==0) and rot.x or math.atan2(v.y,vector.length({x=v.x,y=0,z=v.z})),
y = (v.x==0 and v.z==0) and rot.y or minetest.dir_to_yaw(v),
z=rot.z}
rot = rot or {x=0,y=0,z=0}
return {x = (v.x==0 and v.y==0 and v.z==0) and rot.x or math.atan2(v.y,vector.length({x=v.x,y=0,z=v.z})),
y = (v.x==0 and v.z==0) and rot.y or minetest.dir_to_yaw(v),
z=rot.z}
end
function airutils.pos_shift(pos,vec) -- vec components can be omitted e.g. vec={y=1}
vec.x=vec.x or 0
vec.y=vec.y or 0
vec.z=vec.z or 0
return {x=pos.x+vec.x,
y=pos.y+vec.y,
z=pos.z+vec.z}
vec.x=vec.x or 0
vec.y=vec.y or 0
vec.z=vec.z or 0
return {x=pos.x+vec.x,
y=pos.y+vec.y,
z=pos.z+vec.z}
end
function airutils.get_stand_pos(thing) -- thing can be luaentity or objectref.
local pos = {}
local colbox = {}
if type(thing) == 'table' then
pos = thing.object:get_pos()
function airutils.get_stand_pos(thing) -- thing can be luaentity or objectref.
local pos = {}
local colbox = {}
if type(thing) == 'table' then
pos = thing.object:get_pos()
if not thing.object:get_properties() then return false end
colbox = thing.object:get_properties().collisionbox
elseif type(thing) == 'userdata' then
pos = thing:get_pos()
colbox = thing.object:get_properties().collisionbox
elseif type(thing) == 'userdata' then
pos = thing:get_pos()
if not thing:get_properties() then return false end
colbox = thing:get_properties().collisionbox
else
return false
end
return airutils.pos_shift(pos,{y=colbox[2]+0.01}), pos
colbox = thing:get_properties().collisionbox
else
return false
end
return airutils.pos_shift(pos,{y=colbox[2]+0.01}), pos
end
function airutils.get_node_pos(pos)
return {
x=floor(pos.x+0.5),
y=floor(pos.y+0.5),
z=floor(pos.z+0.5),
}
return {
x=floor(pos.x+0.5),
y=floor(pos.y+0.5),
z=floor(pos.z+0.5),
}
end
function airutils.nodeatpos(pos)
if pos == nil then return end
local node = minetest.get_node_or_nil(pos)
if node then return minetest.registered_nodes[node.name] end
local node = minetest.get_node_or_nil(pos)
if node then return minetest.registered_nodes[node.name] end
end
function airutils.minmax(v,m)
return min(abs(v),m)*sign(v)
return min(abs(v),m)*sign(v)
end
function airutils.set_acceleration(thing,vec,limit)
limit = limit or 100
if type(thing) == 'table' then thing=thing.object end
vec.x=airutils.minmax(vec.x,limit)
vec.y=airutils.minmax(vec.y,limit)
vec.z=airutils.minmax(vec.z,limit)
thing:set_acceleration(vec)
limit = limit or 100
if type(thing) == 'table' then thing=thing.object end
vec.x=airutils.minmax(vec.x,limit)
vec.y=airutils.minmax(vec.y,limit)
vec.z=airutils.minmax(vec.z,limit)
thing:set_acceleration(vec)
end
function airutils.actfunc(self, staticdata, dtime_s)
self.logic = self.logic or self.brainfunc
self.physics = self.physics or airutils.physics
self.lqueue = {}
self.hqueue = {}
self.nearby_objects = {}
self.nearby_players = {}
self.pos_history = {}
self.path_dir = 1
self.time_total = 0
self.water_drag = self.water_drag or 1
self.logic = self.logic or self.brainfunc
self.physics = self.physics or airutils.physics
self.lqueue = {}
self.hqueue = {}
self.nearby_objects = {}
self.nearby_players = {}
self.pos_history = {}
self.path_dir = 1
self.time_total = 0
self.water_drag = self.water_drag or 1
local sdata = minetest.deserialize(staticdata)
if sdata then
for k,v in pairs(sdata) do
self[k] = v
end
end
if self.textures==nil then
local prop_tex = self.object:get_properties().textures
if prop_tex then self.textures=prop_tex end
end
if not self.memory then -- this is the initial activation
self.memory = {}
-- texture variation
if #self.textures > 1 then self.texture_no = random(#self.textures) end
end
if self.timeout and ((self.timeout>0 and dtime_s > self.timeout and next(self.memory)==nil) or
(self.timeout<0 and dtime_s > abs(self.timeout))) then
self.object:remove()
end
-- apply texture
if self.textures and self.texture_no then
local props = {}
props.textures = {self.textures[self.texture_no]}
self.object:set_properties(props)
end
local sdata = minetest.deserialize(staticdata)
if sdata then
for k,v in pairs(sdata) do
self[k] = v
end
end
if self.textures==nil then
local prop_tex = self.object:get_properties().textures
if prop_tex then self.textures=prop_tex end
end
if not self.memory then -- this is the initial activation
self.memory = {}
-- texture variation
if #self.textures > 1 then self.texture_no = random(#self.textures) end
end
if self.timeout and ((self.timeout>0 and dtime_s > self.timeout and next(self.memory)==nil) or
(self.timeout<0 and dtime_s > abs(self.timeout))) then
self.object:remove()
end
-- apply texture
if self.textures and self.texture_no then
local props = {}
props.textures = {self.textures[self.texture_no]}
self.object:set_properties(props)
end
--hp
self.max_hp = self.max_hp or 10
self.hp = self.hp or self.max_hp
self.max_hp = self.max_hp or 10
self.hp = self.hp or self.max_hp
--armor
if type(self.armor_groups) ~= 'table' then
self.armor_groups={}
end
self.armor_groups.immortal = 1
self.object:set_armor_groups(self.armor_groups)
self.buoyancy = self.buoyancy or 0
self.oxygen = self.oxygen or self.lung_capacity
self.lastvelocity = {x=0,y=0,z=0}
if type(self.armor_groups) ~= 'table' then
self.armor_groups={}
end
self.armor_groups.immortal = 1
self.object:set_armor_groups(self.armor_groups)
self.buoyancy = self.buoyancy or 0
self.oxygen = self.oxygen or self.lung_capacity
self.lastvelocity = {x=0,y=0,z=0}
end
function airutils.get_box_height(self)
if type(self) == 'table' then self = self.object end
local colbox = self:get_properties().collisionbox
local height = 0.1
if colbox then height = colbox[5]-colbox[2] end
return height > 0 and height or 0.1
if type(self) == 'table' then self = self.object end
local colbox = self:get_properties().collisionbox
local height = 0.1
if colbox then height = colbox[5]-colbox[2] end
return height > 0 and height or 0.1
end
function airutils.stepfunc(self,dtime,colinfo)
self.dtime = min(dtime,0.2)
self.colinfo = colinfo
self.height = airutils.get_box_height(self)
self.dtime = min(dtime,0.2)
self.colinfo = colinfo
self.height = airutils.get_box_height(self)
-- physics comes first
local vel = self.object:get_velocity()
if colinfo then
self.isonground = colinfo.touching_ground
else
if self.lastvelocity.y==0 and vel.y==0 then
self.isonground = true
else
self.isonground = false
end
end
self:physics()
local vel = self.object:get_velocity()
if colinfo then
self.isonground = colinfo.touching_ground
else
if self.lastvelocity.y==0 and vel.y==0 then
self.isonground = true
else
self.isonground = false
end
end
self:physics()
if self.logic then
if self.view_range then self:sensefunc() end
self:logic()
execute_queues(self)
end
self.lastvelocity = self.object:get_velocity()
self.time_total=self.time_total+self.dtime
if self.logic then
if self.view_range then self:sensefunc() end
self:logic()
execute_queues(self)
end
self.lastvelocity = self.object:get_velocity()
self.time_total=self.time_total+self.dtime
end

View File

@ -22,8 +22,8 @@ minetest.register_chatcommand("au_uniform", {
})
local set_player_textures =
minetest.get_modpath("player_api") and player_api.set_textures
or default.player_set_textures
minetest.get_modpath("player_api") and player_api.set_textures
or default.player_set_textures
function airutils.set_player_skin(player, skin)
local player_properties = player:get_properties()
@ -54,12 +54,12 @@ function airutils.set_player_skin(player, skin)
--sets the combined texture
if texture ~= nil and texture ~= "" then
if skinsdb_mod_path then
player:set_properties({
visual = "mesh",
visual_size = {x=0.95, y=1},
mesh = "character.b3d",
textures = {texture},
})
player:set_properties({
visual = "mesh",
visual_size = {x=0.95, y=1},
mesh = "character.b3d",
textures = {texture},
})
if armor then
armor:update_player_visuals(player)
end
@ -85,12 +85,12 @@ function airutils.set_player_skin(player, skin)
end
--minetest.chat_send_all(dump(old_texture))
if skinsdb_mod_path then
player:set_properties({
visual = "mesh",
visual_size = {x=1, y=1},
mesh = "skinsdb_3d_armor_character_5.b3d",
textures = {texture},
})
player:set_properties({
visual = "mesh",
visual_size = {x=1, y=1},
mesh = "skinsdb_3d_armor_character_5.b3d",
textures = {texture},
})
skins.set_player_skin(player, skins.get_player_skin(player))
if armor then
armor:set_player_armor(player)
@ -113,7 +113,7 @@ function airutils.uniform_formspec(name)
local basic_form = table.concat({
"formspec_version[5]",
"size[5,2.9]",
}, "")
}, "")
--minetest.chat_send_all(dump(airutils.pilot_textures))
@ -123,7 +123,7 @@ function airutils.uniform_formspec(name)
textures = textures .. v .. ","
end
basic_form = basic_form.."dropdown[0.5,0.5;4,0.8;textures;".. textures ..";0;false]"
basic_form = basic_form.."dropdown[0.5,0.5;4,0.8;textures;".. textures ..";0;false]"
basic_form = basic_form.."button[0.5,1.6;4,0.8;set_texture;Set Player Texture]"
minetest.show_formspec(name, "airutils:change", basic_form)
@ -135,9 +135,9 @@ end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "airutils:change" then
local name = player:get_player_name()
if fields.textures or fields.set_texture then
if fields.textures or fields.set_texture then
airutils.set_player_skin(player, fields.textures)
end
end
minetest.close_formspec(name, "airutils:change")
end
end)
@ -147,10 +147,10 @@ minetest.register_on_joinplayer(function(player)
local skin = player_meta:get_string("curr_skin")
--minetest.chat_send_all(">>>"..skin)
if skin and skin ~= "" and skin ~= nil then
-- setting player skin on connect has no effect, so delay skin change
minetest.after(3, function(player1, skin1)
if skin and skin ~= "" and skin ~= nil then
-- setting player skin on connect has no effect, so delay skin change
minetest.after(3, function(player1, skin1)
airutils.set_player_skin(player1, skin1)
end, player, skin)
end
end, player, skin)
end
end)

View File

@ -25,36 +25,36 @@ SOFTWARE.
local get_wind
if minetest.get_modpath("climate_api") then
get_wind = function(pos, multiplier)
get_wind = function(pos, multiplier)
multiplier = multiplier or 0.1
local wind = climate_api.environment.get_wind({x=0,y=0,z=0})
return vector.multiply(wind, multiplier)
end
local wind = climate_api.environment.get_wind({x=0,y=0,z=0})
return vector.multiply(wind, multiplier)
end
else
local yaw = math.random()*math.pi*2-math.pi
local yaw = math.random()*math.pi*2-math.pi
local speed = math.random()*4.0
airutils.wind={}
airutils.wind.wind = vector.multiply(minetest.yaw_to_dir(yaw),speed)
airutils.wind.timer = 0
airutils.wind.ttime = math.random()*5*60+1*60
airutils.wind={}
airutils.wind.wind = vector.multiply(minetest.yaw_to_dir(yaw),speed)
airutils.wind.timer = 0
airutils.wind.ttime = math.random()*5*60+1*60
get_wind = function(pos, multiplier)
get_wind = function(pos, multiplier)
local retVal = vector.multiply(airutils.wind.wind, multiplier)
return retVal
end
return retVal
end
minetest.register_globalstep(
function(dtime)
airutils.wind.timer=airutils.wind.timer+dtime
if airutils.wind.timer >= airutils.wind.ttime then
local yaw = minetest.dir_to_yaw(airutils.wind.wind)
yaw = yaw+math.random()-0.5
minetest.register_globalstep(
function(dtime)
airutils.wind.timer=airutils.wind.timer+dtime
if airutils.wind.timer >= airutils.wind.ttime then
local yaw = minetest.dir_to_yaw(airutils.wind.wind)
yaw = yaw+math.random()-0.5
local speed = math.random()*4.0
airutils.wind.wind = vector.multiply(minetest.yaw_to_dir(yaw),speed)
airutils.wind.ttime = airutils.wind.timer+math.random()*5*60+1*60
end
end)
airutils.wind.wind = vector.multiply(minetest.yaw_to_dir(yaw),speed)
airutils.wind.ttime = airutils.wind.timer+math.random()*5*60+1*60
end
end)
end
return get_wind