Fix 'Unable to register same mod storage twice' error

This commit is contained in:
Maksym H 2023-09-25 20:51:23 +03:00
parent 1c4ed7e761
commit 07a8783769
2 changed files with 28 additions and 26 deletions

View file

@ -1,8 +1,10 @@
-- Minetest 5.4.1 : airutils -- Minetest 5.4.1 : airutils
local storage = minetest.get_mod_storage() airutils = {
storage = minetest.get_mod_storage()
}
airutils = {} local storage = airutils.storage
airutils.colors ={ airutils.colors ={
black='#2b2b2b', black='#2b2b2b',
@ -174,7 +176,7 @@ local function get_nodedef_field(nodename, fieldname)
return minetest.registered_nodes[nodename][fieldname] return minetest.registered_nodes[nodename][fieldname]
end end
--for --for
function airutils.eval_vertical_interception(initial_pos, end_pos) function airutils.eval_vertical_interception(initial_pos, end_pos)
local ret_y = nil local ret_y = nil
local cast = minetest.raycast(initial_pos, end_pos, true, true) local cast = minetest.raycast(initial_pos, end_pos, true, true)
@ -211,7 +213,7 @@ end
local function lerp(a, b, c) local function lerp(a, b, c)
return a + (b - a) * c return a + (b - a) * c
end end
function airutils.quadBezier(t, p0, p1, p2) function airutils.quadBezier(t, p0, p1, p2)
local l1 = lerp(p0, p1, t) local l1 = lerp(p0, p1, t)
local l2 = lerp(p1, p2, t) local l2 = lerp(p1, p2, t)
@ -238,7 +240,7 @@ function airutils.get_ground_effect_lift(self, curr_pos, lift, wingspan)
ground_distance = initial_pos.y - ground_y ground_distance = initial_pos.y - ground_y
end end
--minetest.chat_send_all(dump(ground_distance)) --minetest.chat_send_all(dump(ground_distance))
--smooth the curve --smooth the curve
local distance_factor = ((ground_distance) * 1) / (wingspan) local distance_factor = ((ground_distance) * 1) / (wingspan)
local effect_factor = airutils.quadBezier(distance_factor, 0, wingspan, 0) local effect_factor = airutils.quadBezier(distance_factor, 0, wingspan, 0)
@ -246,13 +248,13 @@ function airutils.get_ground_effect_lift(self, curr_pos, lift, wingspan)
if effect_factor > 0 then if effect_factor > 0 then
effect_factor = math.abs( half_wingspan - effect_factor ) effect_factor = math.abs( half_wingspan - effect_factor )
end end
local lift_factor = ((effect_factor) * 1) / (half_wingspan) --agora isso é um percentual local lift_factor = ((effect_factor) * 1) / (half_wingspan) --agora isso é um percentual
local max_extra_lift_percent = 0.5 * lift --e aqui o maximo extra de sustentação local max_extra_lift_percent = 0.5 * lift --e aqui o maximo extra de sustentação
local extra_lift = max_extra_lift_percent * lift_factor local extra_lift = max_extra_lift_percent * lift_factor
self._extra_lift = extra_lift self._extra_lift = extra_lift
end end
return self._extra_lift --return the value stored return self._extra_lift --return the value stored
end end
@ -271,7 +273,7 @@ function airutils.getLiftAccel(self, velocity, accel, longit_speed, roll, curr_p
local accel_wind = vector.subtract(accel, wind) --why? because I need to fake more speed when against the wind to gain lift local accel_wind = vector.subtract(accel, wind) --why? because I need to fake more speed when against the wind to gain lift
local vel_wind = vector.multiply(accel_wind, self.dtime) local vel_wind = vector.multiply(accel_wind, self.dtime)
local new_velocity = vector.add(velocity, vel_wind) local new_velocity = vector.add(velocity, vel_wind)
if longit_speed == nil then longit_speed = 0 end if longit_speed == nil then longit_speed = 0 end
wingspan = wingspan or 10 wingspan = wingspan or 10
local ground_effect_extra_lift = airutils.get_ground_effect_lift(self, curr_pos, lift, wingspan) local ground_effect_extra_lift = airutils.get_ground_effect_lift(self, curr_pos, lift, wingspan)
@ -283,7 +285,7 @@ function airutils.getLiftAccel(self, velocity, accel, longit_speed, roll, curr_p
max_height = max_height or 20000 max_height = max_height or 20000
local wing_config = 0 local wing_config = 0
if self._wing_configuration then wing_config = self._wing_configuration end --flaps! if self._wing_configuration then wing_config = self._wing_configuration end --flaps!
local retval = accel local retval = accel
local min_speed = 1; local min_speed = 1;
if self._min_speed then min_speed = self._min_speed end if self._min_speed then min_speed = self._min_speed end
@ -305,7 +307,7 @@ function airutils.getLiftAccel(self, velocity, accel, longit_speed, roll, curr_p
local rotation=self.object:get_rotation() local rotation=self.object:get_rotation()
local vrot = airutils.dir_to_rot(velocity,rotation) local vrot = airutils.dir_to_rot(velocity,rotation)
local hpitch,hyaw = pitchroll2pitchyaw(angle_of_attack,roll) local hpitch,hyaw = pitchroll2pitchyaw(angle_of_attack,roll)
local hrot = {x=vrot.x+hpitch,y=vrot.y-hyaw,z=roll} local hrot = {x=vrot.x+hpitch,y=vrot.y-hyaw,z=roll}
@ -358,7 +360,7 @@ function airutils.elevator_auto_correction(self, longit_speed, dtime, max_speed,
intensity = intensity or 500 intensity = intensity or 500
if longit_speed <= 0 then return end if longit_speed <= 0 then return end
local factor = 1 local factor = 1
if self._elevator_angle > 0 then factor = -1 end if self._elevator_angle > 0 then factor = -1 end
local ref_speed = longit_speed local ref_speed = longit_speed
if ref_speed > max_speed then ref_speed = max_speed end if ref_speed > max_speed then ref_speed = max_speed end
@ -366,7 +368,7 @@ function airutils.elevator_auto_correction(self, longit_speed, dtime, max_speed,
local divisor = intensity local divisor = intensity
speed_scale = speed_scale / divisor speed_scale = speed_scale / divisor
local correction = speed_scale * factor * (dtime/ideal_step) local correction = speed_scale * factor * (dtime/ideal_step)
local before_correction = elevator_angle local before_correction = elevator_angle
local new_elevator_angle = elevator_angle + correction local new_elevator_angle = elevator_angle + correction

View file

@ -1,4 +1,4 @@
local storage = minetest.get_mod_storage() local storage = airutils.storage
airutils.modname = minetest.get_current_modname() airutils.modname = minetest.get_current_modname()
--function to format formspec for mineclone. In case of minetest, just returns an empty string --function to format formspec for mineclone. In case of minetest, just returns an empty string
@ -19,54 +19,54 @@ local function get_formspec_by_size(self, size)
end end
local default_inventory_formspecs = { local default_inventory_formspecs = {
["2"]="size[8,6]".. background .. ["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[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) .. "list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]", "listring[]",
["3"]="size[8,6]".. background .. ["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[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) .. "list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]", "listring[]",
["4"]="size[8,6]".. background .. ["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[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) .. "list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]", "listring[]",
["6"]="size[8,6]".. background .. ["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[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) .. "list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]", "listring[]",
["8"]="size[8,6]".. background .. ["8"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,1;]".. airutils.get_itemslot_bg(0, 0, 8, 1) .. "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) .. "list[current_player;main;0,2;8,4;]" .. airutils.get_itemslot_bg(0, 2, 8, 4) ..
"listring[]", "listring[]",
["12"]="size[8,7]".. background .. ["12"]="size[8,7]".. background ..
"list[detached:" .. self._inv_id .. ";main;1,0;6,2;]".. airutils.get_itemslot_bg(1, 0, 6, 2) .. "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) .. "list[current_player;main;0,3;8,4;]" .. airutils.get_itemslot_bg(0, 3, 8, 4) ..
"listring[]", "listring[]",
["16"]="size[8,7]".. background .. ["16"]="size[8,7]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,2;]".. airutils.get_itemslot_bg(0, 0, 8, 2) .. "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) .. "list[current_player;main;0,3;8,4;]" .. airutils.get_itemslot_bg(0, 3, 8, 4) ..
"listring[]", "listring[]",
["24"]="size[8,8]".. background .. ["24"]="size[8,8]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,3;]".. airutils.get_itemslot_bg(0, 0, 8, 3) .. "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) .. "list[current_player;main;0,4;8,4;]" .. airutils.get_itemslot_bg(0, 4, 8, 4) ..
"listring[]", "listring[]",
["32"]="size[8,9]".. background .. ["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[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) .. "list[current_player;main;0,5;8,4;]".. airutils.get_itemslot_bg(0, 5, 8, 4) ..
"listring[]" .. "listring[]" ..
hotbar, hotbar,
["50"]="size[10,10]".. background .. ["50"]="size[10,10]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;10,5;]".. airutils.get_itemslot_bg(0, 0, 10, 5) .. "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) .. "list[current_player;main;1,6;8,4;]" .. airutils.get_itemslot_bg(1, 6, 8, 4) ..
"listring[]", "listring[]",
} }
@ -116,7 +116,7 @@ function airutils.remove_inventory(self)
local pos = self.object:get_pos() local pos = self.object:get_pos()
for k, v in pairs(inv_content) do for k, v in pairs(inv_content) do
local count = 0 local count = 0
for i = 0,v:get_count()-1,1 for i = 0,v:get_count()-1,1
do do
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},v:get_name()) minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},v:get_name())
count = count + 1 count = count + 1
@ -196,7 +196,7 @@ function airutils.list_inventory(self)
local inventory = airutils.get_inventory(self) local inventory = airutils.get_inventory(self)
if inventory then if inventory then
local list = inventory.get_list("main") local list = inventory.get_list("main")
minetest.chat_send_all(dump(list)) minetest.chat_send_all(dump(list))
end end
end end