added convertible beetle

This commit is contained in:
Alexsandro Percy 2024-11-17 18:34:45 -03:00
parent a3c2179f29
commit 07d9ca1532
8 changed files with 175 additions and 0 deletions

View File

@ -47,6 +47,43 @@ minetest.register_tool("automobiles_beetle:beetle", {
end,
})
-- beetle
minetest.register_tool("automobiles_beetle:beetle_conv", {
description = "Beetle",
inventory_image = "automobiles_beetle_conv.png",
liquids_pointable = false,
stack_max = 1,
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return
end
local stack_meta = itemstack:get_meta()
local staticdata = stack_meta:get_string("staticdata")
local pointed_pos = pointed_thing.above
--pointed_pos.y=pointed_pos.y+0.2
local car = minetest.add_entity(pointed_pos, "automobiles_beetle:beetle_conv", staticdata)
if car and placer then
local ent = car:get_luaentity()
local owner = placer:get_player_name()
if ent then
ent.owner = owner
ent.hp = 50 --reset hp
--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, S("Beetle"))
automobiles_lib.create_inventory(ent, ent._trunk_slots, owner)
end
end
return itemstack
end,
})
--
-- crafting
--
@ -58,6 +95,14 @@ if minetest.get_modpath("default") then
{"automobiles_lib:wheel","automobiles_beetle:beetle_body", "automobiles_lib:wheel"},
}
})
minetest.register_craft({
output = "automobiles_beetle:beetle_conv",
recipe = {
{"wool:white","wool:black","wool:black"},
{"automobiles_lib:wheel", "automobiles_lib:engine", "automobiles_lib:wheel"},
{"automobiles_lib:wheel","automobiles_beetle:beetle_body", "automobiles_lib:wheel"},
}
})
minetest.register_craft({
output = "automobiles_beetle:beetle_body",
recipe = {

View File

@ -240,6 +240,52 @@ initial_properties = {
})
minetest.register_entity('automobiles_beetle:top',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "beetle_top.b3d",
backface_culling = false,
textures = {"automobiles_white.png", "automobiles_black.png", "beetle_glasses.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,
})
minetest.register_entity('automobiles_beetle:top_retracted',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "beetle_top_retracted.b3d",
backface_culling = false,
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,
})
function auto_beetle.paint(self, colstr)
local l_textures = self.initial_properties.textures
self._color = colstr
@ -432,3 +478,18 @@ auto_beetle.car_properties1 = {
}
minetest.register_entity("automobiles_beetle:beetle", auto_beetle.car_properties1)
auto_beetle.car_properties2 = automobiles_lib.properties_copy(auto_beetle.car_properties1)
auto_beetle.car_properties2._vehicle_name = "Convertible Beetle"
auto_beetle.car_properties2.initial_properties = automobiles_lib.properties_copy(auto_beetle.car_properties1.initial_properties)
auto_beetle.car_properties2.initial_properties.mesh = "beetle_body_convertible.b3d"
auto_beetle.car_properties2.initial_properties.textures = automobiles_lib.properties_copy(auto_beetle.car_properties1.initial_properties.textures)
auto_beetle.car_properties2._color = "#FFB82D"
auto_beetle.car_properties2._formspec_function = auto_beetle.driver_formspec
auto_beetle.car_properties2._rag_extended_ent = 'automobiles_beetle:top'
auto_beetle.car_properties2._rag_retracted_ent = 'automobiles_beetle:top_retracted'
auto_beetle.car_properties2._show_rag = true
minetest.register_entity("automobiles_beetle:beetle_conv", auto_beetle.car_properties2)

View File

@ -0,0 +1,68 @@
local S = auto_beetle.S
function auto_beetle.driver_formspec(name)
local player = minetest.get_player_by_name(name)
local vehicle_obj = automobiles_lib.getCarFromPlayer(player)
if vehicle_obj == nil then
return
end
local ent = vehicle_obj:get_luaentity()
local yaw = "false"
if ent._yaw_by_mouse then yaw = "true" end
local basic_form = table.concat({
"formspec_version[3]",
"size[6,7]",
}, "")
basic_form = basic_form.."button[1,1.0;4,1;go_out;" .. S("Go Offboard") .. "]"
basic_form = basic_form.."button[1,2.5;4,1;top;" .. S("Close/Open Ragtop") .. "]"
basic_form = basic_form.."button[1,4.0;4,1;lights;" .. S("Lights") .. "]"
basic_form = basic_form.."checkbox[1,5.5;yaw;" .. S("Direction by mouse") .. ";"..yaw.."]"
minetest.show_formspec(name, "auto_beetle:driver_main", basic_form)
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "auto_beetle:driver_main" then
local name = player:get_player_name()
local car_obj = automobiles_lib.getCarFromPlayer(player)
if car_obj then
local ent = car_obj:get_luaentity()
if ent then
if fields.top then
if ent._show_rag == true then
ent._show_rag = false
else
ent._show_rag = true
end
end
if fields.go_out then
if ent._passenger then --any pax?
local pax_obj = minetest.get_player_by_name(ent._passenger)
automobiles_lib.dettach_pax(ent, pax_obj)
end
automobiles_lib.dettach_driver(ent, player)
end
if fields.lights then
if ent._show_lights == true then
ent._show_lights = false
else
ent._show_lights = true
end
end
if fields.yaw then
if ent._yaw_by_mouse == true then
ent._yaw_by_mouse = false
else
ent._yaw_by_mouse = true
end
end
end
end
minetest.close_formspec(name, "auto_beetle:driver_main")
end
end)

View File

@ -20,6 +20,7 @@ dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.l
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "fuel_management.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "ground_detection.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "control.lua")
dofile(minetest.get_modpath("automobiles_beetle") .. DIR_DELIM .. "forms.lua")
dofile(minetest.get_modpath("automobiles_beetle") .. DIR_DELIM .. "entities.lua")
dofile(minetest.get_modpath("automobiles_beetle") .. DIR_DELIM .. "crafts.lua")

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB