added hook functions
This commit is contained in:
parent
915db448f9
commit
27c1988d4c
16
entities.lua
16
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)
|
||||
|
49
forms.lua
49
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
|
||||
})
|
||||
|
2
init.lua
2
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user