Make default, tnt and dye all optional dependencies

player_api is now a dependency but it is more game-agnostic than default
master^2
ROllerozxa 2022-08-27 15:31:48 +02:00
parent 51a303fe73
commit fc48be004a
3 changed files with 38 additions and 17 deletions

29
api.lua
View File

@ -35,7 +35,7 @@ local function force_detach(player)
end
player:set_detach()
end
default.player_attached[player:get_player_name()] = false
player_api.player_attached[player:get_player_name()] = false
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
player:set_properties({visual_size = {x=1, y=1}})
end
@ -53,9 +53,9 @@ function vehicles.object_attach(entity, player, attach_at, visible, eye_offset)
player:set_properties({visual_size = {x=1, y=1}})
end
player:set_eye_offset(eye_offset, {x=eye_offset.x, y=eye_offset.y+1, z=-40})
default.player_attached[player:get_player_name()] = true
player_api.player_attached[player:get_player_name()] = true
minetest.after(0.2, function()
default.player_set_animation(player, "sit" , 30)
player_api.set_animation(player, "sit" , 30)
end)
entity.object:setyaw(player:get_look_yaw() - math.pi / 2)
end
@ -64,8 +64,8 @@ function vehicles.object_detach(entity, player, offset)
entity.driver = nil
entity.object:setvelocity({x=0, y=0, z=0})
player:set_detach()
default.player_attached[player:get_player_name()] = false
default.player_set_animation(player, "stand" , 30)
player_api.player_attached[player:get_player_name()] = false
player_api.set_animation(player, "stand" , 30)
player:set_properties({visual_size = {x=1, y=1}})
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
local pos = player:getpos()
@ -78,6 +78,18 @@ end
--mixed code(from this mod and lib_mount)
-- Cache water and lava nodes
local cache = { water = {}, lava = {} }
minetest.register_on_mods_loaded(function()
for name, def in pairs(minetest.registered_nodes) do
if def.groups.water then
cache.water[name] = true
elseif def.groups.lava then
cache.lava[name] = true
end
end
end)
local vtimer = 0
--New vehicle function, combines all of the others
@ -141,7 +153,7 @@ function vehicles.object_drive(entity, dtime, def)
local accell = 1
--lava explode
if node == "default:lava_source" or node == "default:lava_flowing" then
if cache.lava[node] then
if entity.driver then
vehicles.object_detach(entity, entity.driver, {x=1, y=0, z=1})
end
@ -153,10 +165,7 @@ function vehicles.object_drive(entity, dtime, def)
--respond to controls
--check for water
local function is_water(node)
return node == "default:river_water_source"
or node == "default:water_source"
or node == "default:river_water_flowing"
or node == "default:water_flowing"
return cache.water[node]
end
entity.on_water = is_water(node)
entity.in_water = is_water(minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name)

View File

@ -9,6 +9,15 @@ local step = 1.1
local enable_built_in = true
if enable_built_in then
local stone_sound = {}
if minetest.global_exists("default") then
stone_sound = default.node_sound_stone_defaults()
elseif minetest.global_exists("sounds") then
stone_sound = sounds.node_stone()
end
local function missile_bullet_hit_check(self, obj, pos)
local pos = self.object:getpos()
do
@ -79,7 +88,9 @@ local function missile_on_step_auxiliary(self, obj, pos)
damage_groups={fleshy=12},
}, nil)
end
tnt.boom(self.object:getpos(), {damage_radius=5,radius=5,ignore_protection=false})
if minetest.get_modpath('tnt') then
tnt.boom(self.object:getpos(), {damage_radius=5,radius=5,ignore_protection=false})
end
self.object:remove()
end
end
@ -1842,6 +1853,8 @@ minetest.register_tool("vehicles:rc", {
})
--crafting recipes and materials
-- (only if default and dye exists)
if minetest.get_modpath("default") and minetest.get_modpath("dye") then
minetest.register_craftitem("vehicles:wheel", {
description = S("Wheel"),
@ -2243,8 +2256,7 @@ minetest.register_craft({
}
})
end -- end default and dye mod check
--decorative nodes
@ -2261,7 +2273,7 @@ function vehicles.register_simplenode(name, desc, texture, light)
groups = {cracky=1},
paramtype2 = "facedir",
light_source = light,
sound = default.node_sound_stone_defaults(),
sound = stone_sound,
})
end--function vehicles.register_simplenode(name, desc, texture, light)
@ -2291,7 +2303,7 @@ if minetest.get_modpath("stairs") then
{"vehicles_road.png"},
S("Road Surface Stair"),
S("Road Surface Slab"),
default.node_sound_stone_defaults())
stone_sound)
end
minetest.register_node("vehicles:neon_arrow", {

View File

@ -1,4 +1,4 @@
name = vehicles
description = A mod that adds an api for cars, planes, and other vehicles. Several vehicles are included in the mod.
depends = default, tnt, dye
optional_depends = stairs, creative
depends = player_api
optional_depends = default, tnt, dye, stairs, creative, sounds