From 9c9e8e9f728c04d83f0c7a926d9373df22120aa5 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Sun, 11 Sep 2022 10:04:14 -0300 Subject: [PATCH] improved light and sound --- automobiles_lib/init.lua | 1 + automobiles_motorcycle/motorcycle_entities.lua | 9 ++++++++- automobiles_motorcycle/motorcycle_utilities.lua | 10 +++++----- .../{buggy_engine.ogg => motorcycle_engine.ogg} | Bin 4 files changed, 14 insertions(+), 6 deletions(-) rename automobiles_motorcycle/sounds/{buggy_engine.ogg => motorcycle_engine.ogg} (100%) diff --git a/automobiles_lib/init.lua b/automobiles_lib/init.lua index e4fe97c..2524f51 100755 --- a/automobiles_lib/init.lua +++ b/automobiles_lib/init.lua @@ -288,6 +288,7 @@ function automobiles_lib.swap_node(self, pos) minetest.swap_node(target_pos, {name="air"}) end end, target_pos)]]-- + return true end return false diff --git a/automobiles_motorcycle/motorcycle_entities.lua b/automobiles_motorcycle/motorcycle_entities.lua index b436ff0..2ef3bc6 100755 --- a/automobiles_motorcycle/motorcycle_entities.lua +++ b/automobiles_motorcycle/motorcycle_entities.lua @@ -313,7 +313,14 @@ minetest.register_entity("automobiles_motorcycle:motorcycle", { self.lights:set_properties({textures={"automobiles_motorcycle_lights.png",}, glow=32}) self.rlights:set_properties({textures={"automobiles_motorcycle_rear_lights_full.png",}, glow=10}) end - automobiles_lib.put_light(self) + + --turn the light on just when needed to avoid lag + local target_pos = self.object:get_pos() + target_pos.y = target_pos.y + 2 + local light_now = minetest.get_node_light(target_pos) + if light_now < 12 then + automobiles_lib.put_light(self) + end else if is_breaking == false then --desligado diff --git a/automobiles_motorcycle/motorcycle_utilities.lua b/automobiles_motorcycle/motorcycle_utilities.lua index fd3a90c..77b16e3 100755 --- a/automobiles_motorcycle/motorcycle_utilities.lua +++ b/automobiles_motorcycle/motorcycle_utilities.lua @@ -1,7 +1,7 @@ ---dofile(minetest.get_modpath("automobiles_motorcycle") .. DIR_DELIM .. "buggy_global_definitions.lua") ---dofile(minetest.get_modpath("automobiles_motorcycle") .. DIR_DELIM .. "buggy_hud.lua") +--dofile(minetest.get_modpath("automobiles_motorcycle") .. DIR_DELIM .. "motorcycle_global_definitions.lua") +--dofile(minetest.get_modpath("automobiles_motorcycle") .. DIR_DELIM .. "motorcycle_hud.lua") --- destroy the buggy +-- destroy the motorcycle function motorcycle.destroy(self, puncher) automobiles_lib.remove_light(self) if self.sound_handle then @@ -37,7 +37,7 @@ function motorcycle.destroy(self, puncher) 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_motorcycle:buggy') + --minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_motorcycle:motorcycle') 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_motorcycle:wheel') minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_motorcycle:wheel') @@ -57,7 +57,7 @@ function motorcycle.engineSoundPlay(self) --sound if self.sound_handle then minetest.sound_stop(self.sound_handle) end if self.object then - self.sound_handle = minetest.sound_play({name = "buggy_engine"}, + self.sound_handle = minetest.sound_play({name = "motorcycle_engine"}, {object = self.object, gain = 8, pitch = 1 + ((self._longit_speed/10)/2), max_hear_distance = 10, diff --git a/automobiles_motorcycle/sounds/buggy_engine.ogg b/automobiles_motorcycle/sounds/motorcycle_engine.ogg similarity index 100% rename from automobiles_motorcycle/sounds/buggy_engine.ogg rename to automobiles_motorcycle/sounds/motorcycle_engine.ogg