From 27c1988d4c4c0210b025bf8489192c0b06ff91b2 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Wed, 14 Feb 2024 21:22:27 -0300 Subject: [PATCH] added hook functions --- entities.lua | 16 +++++++++++++++- forms.lua | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- init.lua | 2 +- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/entities.lua b/entities.lua index 58444da..5aa85e2 100755 --- a/entities.lua +++ b/entities.lua @@ -393,7 +393,7 @@ minetest.register_entity("ap_airship:airship", { physical = true, collide_with_objects = true, --true, collisionbox = {-10, -4.1, -10, 10, 15, 10}, --{-1,0,-1, 1,0.3,1}, - selectionbox = {-2, -3.5, -2, 2, 0, 2}, + selectionbox = {-2, -4.1, -2, 2, 0, 2}, visual = "mesh", backface_culling = false, mesh = "ap_airship_mesh.b3d", @@ -416,6 +416,7 @@ minetest.register_entity("ap_airship:airship", { physics = ap_airship.physics, hull_integrity = nil, owner = "", + _vehicle_custom_data = {}, _shared_owners = {}, _engine_running = false, _power_lever = 0, @@ -439,6 +440,7 @@ minetest.register_entity("ap_airship:airship", { _inv_id = "", _name_color = 0, _name_hor_aligment = 3.0, + _simple_attach_pos = {x=0,y=-25,z=-40}, item = "ap_airship:airship", @@ -458,6 +460,7 @@ minetest.register_entity("ap_airship:airship", { stored_inv_id = self._inv_id, stored_passengers = self._passengers, --passengers list stored_passengers_locked = self._passengers_locked, + stored_vehicle_custom_data = self._vehicle_custom_data or {}, stored_ship_name = self._ship_name, }) end, @@ -489,6 +492,15 @@ minetest.register_entity("ap_airship:airship", { self._passengers = data.stored_passengers or ap_airship.copy_vector({[1]=nil, [2]=nil, [3]=nil, [4]=nil, [5]=nil, [6]=nil, [7]=nil, [8]=nil, [9]=nil, [10]=nil, [11]=nil, [12]=nil}) self._passengers_locked = data.stored_passengers_locked self._ship_name = data.stored_ship_name + + local custom_data = data.stored_vehicle_custom_data or nil + if custom_data then + self._vehicle_custom_data = custom_data + else + -- o macete aqui eh inicializar mesmo que não exista no escopo da entity + self._vehicle_custom_data = {} --initialize it + end + --minetest.debug("loaded: ", self._energy) local properties = self.object:get_properties() properties.infotext = data.stored_owner .. " nice airship" @@ -500,6 +512,7 @@ minetest.register_entity("ap_airship:airship", { colstr = "blue" self.color = colstr end + ap_airship.paint(self, self.color) ap_airship.paint2(self, self.color2) local pos = self.object:get_pos() @@ -564,6 +577,7 @@ minetest.register_entity("ap_airship:airship", { end ap_airship.engine_step(self, 0) + airutils.restore_external_attach(self) end, on_step = function(self,dtime,colinfo) diff --git a/forms.lua b/forms.lua index ad4d671..813f678 100755 --- a/forms.lua +++ b/forms.lua @@ -57,6 +57,19 @@ function ap_airship.pax_formspec(name) minetest.show_formspec(name, "ap_airship:passenger_main", basic_form) end +function ap_airship.external_attach(name) + local basic_form = table.concat({ + "formspec_version[3]", + "size[6,3]", + }, "") + + basic_form = basic_form.."label[1,1.0;Attach Outside:]" + basic_form = basic_form.."button[1,1.2;2,1;attach;Attach]" + basic_form = basic_form.."button[3,1.2;2,1;dettach;Dettach]" + + minetest.show_formspec(name, "ap_airship:attach_main", basic_form) +end + function ap_airship.logo_formspec(name) local basic_form = table.concat({ "formspec_version[3]", @@ -143,7 +156,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end minetest.close_formspec(name, "ap_airship:passenger_main") end - if formname == "ap_airship:logo_main" then + if formname == "ap_airship:attach_main" then local name = player:get_player_name() local plane_obj = ap_airship.getPlaneFromPlayer(player) if plane_obj == nil then @@ -152,8 +165,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end local ent = plane_obj:get_luaentity() if ent then - if fields.logo or fields.set_logo then - ap_airship.set_logo(ent, fields.logo) + if fields.attach then + airutils.simple_external_attach(ent, ent._simple_attach_pos, "albatros_d5:albatros_d5", 22) + end + if fields.dettach then + airutils.dettach_entity(ent) end end minetest.close_formspec(name, "ap_airship:logo_main") @@ -465,3 +481,30 @@ minetest.register_chatcommand("airship_eject", { end end }) + +minetest.register_chatcommand("external_attach_menu", { + params = "", + description = "Opens the panel to attach or dettach an external object", + privs = {interact = true}, + func = function(name, param) + local colorstring = core.colorize('#ff0000', " >>> you are not inside a airship") + local player = minetest.get_player_by_name(name) + local attached_to = player:get_attach() + + if attached_to ~= nil then + local seat = attached_to:get_attach() + if seat ~= nil then + local entity = seat:get_luaentity() + if entity then + if entity.name == "ap_airship:airship" then + ap_airship.external_attach(name) + else + minetest.chat_send_player(name,colorstring) + end + end + end + else + minetest.chat_send_player(name,colorstring) + end + end +}) diff --git a/init.lua b/init.lua index 0a471ed..a7bf03d 100755 --- a/init.lua +++ b/init.lua @@ -134,7 +134,7 @@ minetest.register_craftitem("ap_airship:airship", { --local node_below = minetest.get_node(pointed_pos).name --local nodedef = minetest.registered_nodes[node_below] - pointed_pos.y=pointed_pos.y+4 + pointed_pos.y=pointed_pos.y+4.6 local airship = minetest.add_entity(pointed_pos, "ap_airship:airship") if airship and placer then local ent = airship:get_luaentity()