added inventory

master
Alexsandro Percy 2022-03-21 19:41:26 -03:00
parent 0416a93fec
commit 516915b091
5 changed files with 55 additions and 34 deletions

View File

@ -1,11 +1,10 @@
ju52={}
ju52.fuel = {['biofuel:biofuel'] = 1,['biofuel:bottle_fuel'] = 1,
['biofuel:phial_fuel'] = 0.25, ['biofuel:fuel_can'] = 10}
ju52.gravity = tonumber(minetest.settings:get("movement_gravity")) or 9.8
ju52.wing_angle_of_attack = 1
ju52.min_speed = 9
ju52.max_engine_acc = 9 --5
ju52.lift = 10 --12
ju52.trunk_slots = 50
ju52.colors ={
black='#2b2b2b',

View File

@ -25,14 +25,15 @@ minetest.register_craftitem("ju52:ju52", {
--local nodedef = minetest.registered_nodes[node_below]
pointed_pos.y=pointed_pos.y+3
local ju52 = minetest.add_entity(pointed_pos, "ju52:ju52")
if ju52 and placer then
local ent = ju52:get_luaentity()
local new_ju52 = minetest.add_entity(pointed_pos, "ju52:ju52")
if new_ju52 and placer then
local ent = new_ju52:get_luaentity()
local owner = placer:get_player_name()
ent.owner = owner
ju52:set_yaw(placer:get_look_horizontal())
new_ju52:set_yaw(placer:get_look_horizontal())
itemstack:take_item()
ent.object:set_acceleration({x=0,y=mobkit.gravity,z=0})
airutils.create_inventory(ent, ju52.trunk_slots, owner)
end
return itemstack

View File

@ -108,6 +108,8 @@ minetest.register_entity("ju52:ju52", {
_passengers = {},
_color = nil,
_skin = 'ju52_skin_lufthansa.png',
_inv = nil,
_inv_id = "",
get_staticdata = function(self) -- unloaded/unloads ... is now saved
return minetest.serialize({
@ -119,9 +121,14 @@ minetest.register_entity("ju52:ju52", {
stored_flap = self._flap,
stored_color = self._color,
stored_skin = self._skin,
stored_inv_id = self._inv_id,
})
end,
on_deactivate = function(self)
airutils.save_inventory(self)
end,
on_activate = function(self, staticdata, dtime_s)
mobkit.actfunc(self, staticdata, dtime_s)
if staticdata ~= "" and staticdata ~= nil then
@ -134,6 +141,7 @@ minetest.register_entity("ju52:ju52", {
self._flap = data.stored_flap
self._color = data.stored_color
self._skin = data.stored_skin
self._inv_id = data.stored_inv_id
--minetest.debug("loaded: ", self._energy)
end
airutils.setText(self, "Ju 52")
@ -195,6 +203,14 @@ minetest.register_entity("ju52:ju52", {
end
self.object:set_armor_groups({immortal=1})
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, ju52.trunk_slots)
else
self.inv = inv
end
end,
--on_step = mobkit.stepfunc,
@ -283,11 +299,11 @@ minetest.register_entity("ju52:ju52", {
else
-- deal with painting or destroying
if not self.driver and toolcaps and toolcaps.damage_groups
and toolcaps.damage_groups.fleshy and item_name ~= ju52.fuel then
and toolcaps.damage_groups.fleshy and item_name ~= airutils.fuel then
--mobkit.hurt(self,toolcaps.damage_groups.fleshy - 1)
--mobkit.make_sound(self,'hit')
self.hp_max = self.hp_max - 10
minetest.sound_play("collision", {
minetest.sound_play("ju52_collision", {
object = self.object,
max_hear_distance = 5,
gain = 1.0,
@ -364,36 +380,40 @@ minetest.register_entity("ju52:ju52", {
--=========================
elseif not self.driver_name then
if self.owner == name or minetest.check_player_privs(clicker, {protection_bypass=true}) then
if ju52.restricted == "true" and not minetest.check_player_privs(clicker, {flight_licence=true}) then
minetest.show_formspec(name, "ju52:flightlicence",
"size[4,2]" ..
"label[0.0,0.0;Sorry ...]"..
"label[0.0,0.7;You need a flight licence to fly it.]" ..
"label[0.0,1.0;You must obtain it from server admin.]" ..
"button_exit[1.5,1.9;0.9,0.1;e;Exit]")
return
end
if clicker:get_player_control().aux1 == true then --lets see the inventory
airutils.show_vehicle_trunk_formspec(self, clicker, ju52.trunk_slots)
else
if ju52.restricted == "true" and not minetest.check_player_privs(clicker, {flight_licence=true}) then
minetest.show_formspec(name, "ju52:flightlicence",
"size[4,2]" ..
"label[0.0,0.0;Sorry ...]"..
"label[0.0,0.7;You need a flight licence to fly it.]" ..
"label[0.0,1.0;You must obtain it from server admin.]" ..
"button_exit[1.5,1.9;0.9,0.1;e;Exit]")
return
end
if is_under_water then return end
--remove pax to prevent bug
if self._passenger then
local pax_obj = minetest.get_player_by_name(self._passenger)
ju52.dettach_pax(self, pax_obj)
end
for i = 10,1,-1
do
if self._passengers[i] then
if is_under_water then return end
--remove pax to prevent bug
if self._passenger then
local pax_obj = minetest.get_player_by_name(self._passenger)
ju52.dettach_pax(self, pax_obj)
end
for i = 10,1,-1
do
if self._passengers[i] then
local passenger = minetest.get_player_by_name(self._passengers[i])
if passenger then ju52.dettach_pax(self, passenger) end
if self._passengers[i] then
local passenger = minetest.get_player_by_name(self._passengers[i])
if passenger then ju52.dettach_pax(self, passenger) end
end
end
end
end
--attach player
-- no driver => clicker is new driver
ju52.attach(self, clicker)
self._command_is_given = false
--attach player
-- no driver => clicker is new driver
ju52.attach(self, clicker)
self._command_is_given = false
end
else
ju52.dettach_pax(self, clicker)
minetest.chat_send_player(name, core.colorize('#ff0000', " >>> You aren't the owner of this Ju 52."))

View File

@ -17,7 +17,7 @@ function ju52.loadFuel(self, player_name)
local item_name = ""
if itmstck then item_name = itmstck:get_name() end
local fuel = ju52.contains(ju52.fuel, item_name)
local fuel = ju52.contains(airutils.fuel, item_name)
if fuel then
local stack = ItemStack(item_name .. " 1")

View File

@ -287,6 +287,7 @@ function ju52.destroy(self)
if self.stick then self.stick:remove() end
airutils.destroy_inventory(self)
self.object:remove()
pos.y=pos.y+2