fixes and added a second catrelle

This commit is contained in:
Alexsandro Percy 2023-12-03 19:54:49 -03:00
parent 2abf853b18
commit d987350f6e
8 changed files with 324 additions and 122 deletions

View File

@ -43,6 +43,38 @@ minetest.register_craftitem("automobiles_catrelle:catrelle", {
end,
})
-- catrelle TL
minetest.register_craftitem("automobiles_catrelle:catrelle_tl", {
description = S("Catrelle TL"),
inventory_image = "automobiles_catrelle.png",
liquids_pointable = false,
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return
end
local pointed_pos = pointed_thing.above
--pointed_pos.y=pointed_pos.y+0.2
local car = minetest.add_entity(pointed_pos, "automobiles_catrelle:catrelle_tl")
if car and placer then
local ent = car:get_luaentity()
local owner = placer:get_player_name()
if ent then
ent.owner = owner
ent._catrelle_type = 1
--minetest.chat_send_all("owner: " .. ent.owner)
car:set_yaw(placer:get_look_horizontal())
itemstack:take_item()
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
automobiles_lib.setText(ent, "Catrelle TL")
automobiles_lib.create_inventory(ent, ent._trunk_slots, owner)
end
end
return itemstack
end,
})
--
-- crafting

View File

@ -1,3 +1,61 @@
function catrelle.extra_parts(self)
local pos = self.object:get_pos()
local back_seat = minetest.add_entity(pos,'automobiles_catrelle:back_seat')
back_seat:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.back_seat = back_seat
end
-- destroy the delorean
function catrelle.destroy(self, puncher)
automobiles_lib.remove_light(self)
if self.sound_handle then
minetest.sound_stop(self.sound_handle)
self.sound_handle = nil
end
if self.driver_name then
-- detach the driver first (puncher must be driver)
if puncher then
puncher:set_detach()
puncher:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
if minetest.global_exists("player_api") then
player_api.player_attached[self.driver_name] = nil
-- player should stand again
player_api.set_animation(puncher, "stand")
end
end
self.driver_name = nil
end
local pos = self.object:get_pos()
if self.front_suspension then self.front_suspension:remove() end
if self.lf_wheel then self.lf_wheel:remove() end
if self.rf_wheel then self.rf_wheel:remove() end
if self.rear_suspension then self.rear_suspension:remove() end
if self.lr_wheel then self.lr_wheel:remove() end
if self.rr_wheel then self.rr_wheel:remove() end
if self.fuel_gauge then self.fuel_gauge:remove() end
if self.lights then self.lights:remove() end
if self.r_lights then self.r_lights:remove() end
if self.reverse_lights then self.reverse_lights:remove() end
if self.turn_l_light then self.turn_l_light:remove() end
if self.turn_r_light then self.turn_r_light:remove() end
if self.back_seat then self.back_seat:remove() end
automobiles_lib.seats_destroy(self)
automobiles_lib.destroy_inventory(self)
self.object:remove()
pos.y=pos.y+2
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine')
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
end
--
-- entity
--
@ -166,7 +224,34 @@ initial_properties = {
})
minetest.register_entity("automobiles_catrelle:catrelle", {
minetest.register_entity('automobiles_catrelle:back_seat',{
initial_properties = {
physical = true,
collide_with_objects=true,
collisionbox = {-0.5, 0, -0.5, 0.5, 1, 0.5},
pointable=false,
visual = "mesh",
mesh = "automobiles_catrelle_seat.b3d",
textures = {"automobiles_black.png",},
},
on_activate = function(self,std)
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,
--[[on_step = function(self, dtime, moveresult)
minetest.chat_send_all(dump(moveresult))
end,]]--
})
catrelle.car_properties1 = {
initial_properties = {
physical = true,
collide_with_objects = true,
@ -210,7 +295,7 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
lastvelocity = vector.new(),
time_total = 0,
_passenger = nil,
_color = "#0063b0",
_color = "#07B6BC",
_steering_angle = 0,
_engine_running = false,
_last_checkpoint = "",
@ -535,6 +620,21 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
on_punch = automobiles_lib.on_punch,
on_rightclick = automobiles_lib.on_rightclick,
})
}
minetest.register_entity("automobiles_catrelle:catrelle", catrelle.car_properties1)
catrelle.car_properties2 = automobiles_lib.properties_copy(catrelle.car_properties1)
catrelle.car_properties2._vehicle_name = "Catrelle TL"
catrelle.car_properties2.initial_properties = automobiles_lib.properties_copy(catrelle.car_properties1.initial_properties)
catrelle.car_properties2.initial_properties.textures = automobiles_lib.properties_copy(catrelle.car_properties1.initial_properties.textures)
catrelle.car_properties2.initial_properties.textures[9] = "automobiles_alpha.png"
catrelle.car_properties2.initial_properties.textures[10] = "automobiles_catrelle_lat_glass.png"
catrelle.car_properties2._seat_pos = {{x=-4.0,y=3,z=15},{x=4.0,y=3,z=15}, {x=-4.0,y=3,z=7},{x=4.0,y=3,z=7}}
catrelle.car_properties2._color = "#0063b0"
catrelle.car_properties2._trunk_slots = 24
catrelle.car_properties2._extra_items_function = catrelle.extra_parts
catrelle.car_properties2._destroy_function = catrelle.destroy
minetest.register_entity("automobiles_catrelle:catrelle_tl", catrelle.car_properties2)

View File

@ -1,3 +1,26 @@
function delorean.set_kit(self)
local normal_kit = nil
if self.normal_kit then self.normal_kit:remove() end
local pos = self.object:get_pos()
if self._car_type == 0 or self._car_type == nil then
normal_kit = minetest.add_entity(pos,'automobiles_delorean:normal_kit')
normal_kit:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.normal_kit = normal_kit
self.normal_kit:set_properties({is_visible=true})
elseif self._car_type == 1 then
--time machine
normal_kit = minetest.add_entity(pos,'automobiles_delorean:time_machine_kit')
normal_kit:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.normal_kit = normal_kit
self.normal_kit:set_properties({is_visible=true})
local instruments = minetest.add_entity(pos,'automobiles_delorean:time_machine_kit_instruments')
instruments:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.instruments = instruments
self.instruments:set_properties({is_visible=true})
end
end
--
-- entity
--

View File

@ -1,26 +1,3 @@
function delorean.set_kit(self)
local normal_kit = nil
if self.normal_kit then self.normal_kit:remove() end
local pos = self.object:get_pos()
if self._car_type == 0 or self._car_type == nil then
normal_kit = minetest.add_entity(pos,'automobiles_delorean:normal_kit')
normal_kit:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.normal_kit = normal_kit
self.normal_kit:set_properties({is_visible=true})
elseif self._car_type == 1 then
--time machine
normal_kit = minetest.add_entity(pos,'automobiles_delorean:time_machine_kit')
normal_kit:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.normal_kit = normal_kit
self.normal_kit:set_properties({is_visible=true})
local instruments = minetest.add_entity(pos,'automobiles_delorean:time_machine_kit_instruments')
instruments:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.instruments = instruments
self.instruments:set_properties({is_visible=true})
end
end
function delorean.gravity_auto_correction(self, dtime)
local factor = 1
--minetest.chat_send_player(self.driver_name, "antes: " .. self._car_gravity)

View File

@ -78,7 +78,7 @@ function automobiles_lib.on_rightclick (self, clicker)
else
--minetest.chat_send_all("clicou")
--a passenger
if self._passenger == nil then
if not player_api.player_attached[name] then
--there is no passenger, so lets attach
if self.driver_name then
local attach_pax_f = automobiles_lib.attach_pax
@ -87,12 +87,10 @@ function automobiles_lib.on_rightclick (self, clicker)
end
else
--there is a passeger
if self._passenger == name then
--if you are the psenger, so deattach
local dettach_pax_f = automobiles_lib.dettach_pax
if self._dettach_pax then dettach_pax_f = self._dettach_pax end
dettach_pax_f(self, clicker)
end
--if you are the psenger, so deattach
local dettach_pax_f = automobiles_lib.dettach_pax
if self._dettach_pax then dettach_pax_f = self._dettach_pax end
dettach_pax_f(self, clicker)
end
end
end
@ -288,13 +286,15 @@ function automobiles_lib.on_activate(self, staticdata, dtime_s)
self.rag = rag
end
local driver_seat=minetest.add_entity(pos,'automobiles_lib:pivot_mesh')
automobiles_lib.seats_create(self)
--[[local driver_seat=minetest.add_entity(pos,'automobiles_lib:pivot_mesh')
driver_seat:set_attach(self.object,'',self._seat_pos[1],{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_lib:pivot_mesh')
passenger_seat:set_attach(self.object,'',self._seat_pos[2],{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
self.passenger_seat = passenger_seat]]--
local pointer_entity = 'automobiles_lib:pointer'
if self._gauge_pointer_ent then pointer_entity = self._gauge_pointer_ent end

View File

@ -63,6 +63,14 @@ function automobiles_lib.minmax(v,m)
return math.min(math.abs(v),m)*minekart.sign(v)
end
function automobiles_lib.properties_copy(origin_table)
local tablecopy = {}
for k, v in pairs(origin_table) do
tablecopy[k] = v
end
return tablecopy
end
--returns 0 for old, 1 for new
function automobiles_lib.detect_player_api(player)
local player_proterties = player:get_properties()
@ -83,6 +91,28 @@ function automobiles_lib.detect_player_api(player)
return 0
end
function automobiles_lib.seats_create(self)
if self.object then
local pos = self.object:get_pos()
self._passengers_base = {}
self._passengers = {}
if self._seat_pos then
local max_seats = table.getn(self._seat_pos)
for i=1, max_seats do
self._passengers_base[i] = minetest.add_entity(pos,'automobiles_lib:pivot_mesh')
if not self._seats_rot then
self._passengers_base[i]:set_attach(self.object,'',self._seat_pos[i],{x=0,y=0,z=0})
else
self._passengers_base[i]:set_attach(self.object,'',self._seat_pos[i],{x=0,y=self._seats_rot[i],z=0})
end
end
self.driver_seat = self._passengers_base[1] --sets pilot seat reference
self.passenger_seat = self._passengers_base[2] --sets copilot seat reference
end
end
end
-- attach player
function automobiles_lib.attach_driver(self, player)
local name = player:get_player_name()
@ -156,103 +186,112 @@ function automobiles_lib.attach_pax(self, player, onside)
local onside = onside or false
local name = player:get_player_name()
if onside == true then
if self._passenger == nil then
self._passenger = name
local eye_y = -4
if airutils.detect_player_api(player) == 1 then
eye_y = 2.5
end
-- attach the driver
player:set_attach(self.passenger_seat, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
local eye_y = -4
if automobiles_lib.detect_player_api(player) == 1 then
eye_y = 2.5
end
player:set_eye_offset({x = 0, y = eye_y, z = 0}, {x = 0, y = eye_y, z = -30})
player_api.player_attached[name] = true
-- make the pax sit
if self._passenger == nil then
self._passenger = name
minetest.after(0.2, function()
player = minetest.get_player_by_name(name)
if player then
local speed = 30.01
local mesh = player:get_properties().mesh
if mesh then
local character = player_api.registered_models[mesh]
if character and character.animation_speed then
speed = character.animation_speed + 0.01
end
-- attach the driver
player:set_attach(self.passenger_seat, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
player:set_eye_offset({x = 0, y = eye_y, z = 0}, {x = 0, y = eye_y, z = -30})
player_api.player_attached[name] = true
-- make the pax sit
minetest.after(0.2, function()
player = minetest.get_player_by_name(name)
if player then
local speed = 30.01
local mesh = player:get_properties().mesh
if mesh then
local character = player_api.registered_models[mesh]
if character and character.animation_speed then
speed = character.animation_speed + 0.01
end
player_api.set_animation(player, "sit", speed)
if emote then emote.start(player:get_player_name(), "sit") end
end
end)
end
player_api.set_animation(player, "sit", speed)
if emote then emote.start(player:get_player_name(), "sit") end
end
end)
else
--randomize the seat
--[[local t = {1,2,3,4,5,6,7,8,9,10}
local max_seats = table.getn(self._seat_pos) --driver and front passenger
t = {} -- new array
for i=1, max_seats do --(the first are for the driver
t[i] = i
end
for i = 1, #t*2 do
local a = math.random(#t)
local b = math.random(#t)
t[a],t[b] = t[b],t[a]
end
--for i = 1,10,1 do
for k,v in ipairs(t) do
i = t[k]
if self._passengers[i] == nil then
if self._passengers[i] == nil and i > 2 then
--minetest.chat_send_all(self.driver_name)
self._passengers[i] = name
player:set_attach(self._passengers_base[i], "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
if i > 2 then
player:set_eye_offset({x = 0, y = -4, z = 2}, {x = 0, y = 3, z = -30})
else
player:set_eye_offset({x = 0, y = -4, z = 0}, {x = 0, y = 3, z = -30})
end
player:set_eye_offset({x = 0, y = eye_y, z = 0}, {x = 0, y = 3, z = -30})
player_api.player_attached[name] = true
-- make the driver sit
-- make the pax sit
minetest.after(0.2, function()
player = minetest.get_player_by_name(name)
if player then
player_api.set_animation(player, "sit")
--apply_physics_override(player, {speed=0,gravity=0,jump=0})
local speed = 30.01
local mesh = player:get_properties().mesh
if mesh then
local character = player_api.registered_models[mesh]
if character and character.animation_speed then
speed = character.animation_speed + 0.01
end
end
player_api.set_animation(player, "sit", speed)
if emote then emote.start(player:get_player_name(), "sit") end
end
end)
break
end
end]]--
end
end
end
function automobiles_lib.dettach_pax(self, player)
if player then
local name = player:get_player_name() --self._passenger
if not player then return end
local name = player:get_player_name() --self._passenger
-- passenger clicked the object => driver gets off the vehicle
if self._passenger == name then
self._passenger = nil
else
--[[for i = 10,1,-1
do
if self._passengers[i] == name then
self._passengers[i] = nil
break
end
end]]--
end
-- detach the player
if player then
--player:set_properties({physical=true})
player:set_detach()
player_api.player_attached[name] = nil
player_api.set_animation(player, "stand")
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
--remove_physics_override(player, {speed=1,gravity=1,jump=1})
end
else
-- passenger clicked the object => driver gets off the vehicle
if self._passenger == name then
self._passenger = nil
self._passengers[2] = nil
else
local max_seats = table.getn(self._seat_pos)
for i = max_seats,1,-1
do
if self._passengers[i] == name then
self._passengers[i] = nil
break
end
end
end
-- detach the player
if player then
local pos = player:get_pos()
player:set_detach()
player_api.player_attached[name] = nil
player_api.set_animation(player, "stand")
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
--remove_physics_override(player, {speed=1,gravity=1,jump=1})
end
end
@ -369,6 +408,13 @@ function automobiles_lib.put_light(self)
end
function automobiles_lib.seats_destroy(self)
local max_seats = table.getn(self._passengers_base)
for i=1, max_seats do
if self._passengers_base[i] then self._passengers_base[i]:remove() end
end
end
function automobiles_lib.destroy(self, puncher)
automobiles_lib.remove_light(self)
if self.sound_handle then
@ -409,6 +455,8 @@ function automobiles_lib.destroy(self, puncher)
if self.turn_l_light then self.turn_l_light:remove() end
if self.turn_r_light then self.turn_r_light:remove() end
automobiles_lib.seats_destroy(self)
automobiles_lib.destroy_inventory(self)
self.object:remove()

View File

@ -1,50 +1,72 @@
local storage = automobiles_lib.storage
automobiles_lib.modname = minetest.get_current_modname()
--function to format formspec for mineclone. In case of minetest, just returns an empty string
local function get_itemslot_bg(a, b, c, d)
if mcl_formspec then
return mcl_formspec.get_itemslot_bg(a,b,c,d)
end
return ""
end
local function get_formspec_by_size(self, size)
local background = default.gui_bg .. default.gui_bg_img .. default.gui_slots
local background = ""
local hotbar = ""
local is_minetest_game = false
if is_minetest_game then
background = background .. default.gui_bg .. default.gui_bg_img .. default.gui_slots
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;]" .. get_itemslot_bg(3.0, 0, 2, 1) ..
"list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["3"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;2.5,0;3,1;]" .. get_itemslot_bg(2.5, 0, 3, 1) ..
"list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["4"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;2,0;4,1;]" ..
"list[current_player;main;0,2;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;2,0;4,1;]" .. get_itemslot_bg(2.0, 0, 4, 1) ..
"list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["6"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;1,0;6,1;]"..
"list[current_player;main;0,2;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;1,0;6,1;]".. get_itemslot_bg(1.0, 0, 6, 1) ..
"list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["8"]="size[8,6]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,1;]"..
"list[current_player;main;0,2;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,1;]".. get_itemslot_bg(0, 0, 8, 1) ..
"list[current_player;main;0,2;8,4;]" .. get_itemslot_bg(0, 2, 8, 4) ..
"listring[]",
["12"]="size[8,7]".. background ..
"list[detached:" .. self._inv_id .. ";main;1,0;6,2;]"..
"list[current_player;main;0,3;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;1,0;6,2;]".. get_itemslot_bg(1, 0, 6, 2) ..
"list[current_player;main;0,3;8,4;]" .. get_itemslot_bg(0, 3, 8, 4) ..
"listring[]",
["16"]="size[8,7]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,2;]"..
"list[current_player;main;0,3;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,2;]".. get_itemslot_bg(0, 0, 8, 2) ..
"list[current_player;main;0,3;8,4;]" .. get_itemslot_bg(0, 3, 8, 4) ..
"listring[]",
["24"]="size[8,8]".. background ..
"list[context:" .. self._inv_id .. ";main;0,0;8,3;]"..
"list[current_player;main;0,4;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;0,0;8,3;]".. get_itemslot_bg(0, 0, 8, 3) ..
"list[current_player;main;0,4;8,4;]" .. get_itemslot_bg(0, 4, 8, 4) ..
"listring[]",
["32"]="size[8,9]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0.3;8,4;]"..
"list[current_player;main;0,4.85;8,1;]"..
"list[current_player;main;0,6.08;8,3;8]"..
"listring[context;main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0,4.85),
"list[detached:" .. self._inv_id .. ";main;0,0.3;8,4;]".. get_itemslot_bg(0, 0.3, 8, 4) ..
"list[current_player;main;0,5;8,4;]".. get_itemslot_bg(0, 5, 8, 4) ..
"listring[]" ..
hotbar,
["50"]="size[10,10]".. background ..
"list[detached:" .. self._inv_id .. ";main;0,0;10,5;]"..
"list[current_player;main;1,6;8,4;]" ..
"list[detached:" .. self._inv_id .. ";main;0,0;10,5;]".. get_itemslot_bg(0, 0, 10, 5) ..
"list[current_player;main;1,6;8,4;]" .. get_itemslot_bg(1, 6, 8, 4) ..
"listring[]",
}

View File

@ -274,7 +274,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
_front_wheel_ent = 'automobiles_roadster:wheel',
_front_wheel_xpos = 10.26,
_front_wheel_frames = {x = 2, y = 13},
_rear_suspension_ent = 'automobiles_trans_am:rear_suspension',
_rear_suspension_ent = 'automobiles_roadster:rear_suspension',
_rear_suspension_pos = {x=0,y=0,z=0},
_rear_wheel_ent = 'automobiles_roadster:wheel',
_rear_wheel_xpos = 10.26,