From 4b7f8811e3d79ecccfc9f4f1e30f90f8930c6832 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Wed, 11 Jan 2023 13:30:25 +1100 Subject: [PATCH] add balloon --- balloon.lua | 181 ++++++++++------------------------------------------ init.lua | 8 +++ 2 files changed, 41 insertions(+), 148 deletions(-) create mode 100644 init.lua diff --git a/balloon.lua b/balloon.lua index 9a79036..e8d76b2 100644 --- a/balloon.lua +++ b/balloon.lua @@ -1,7 +1,7 @@ local mod_name = minetest.get_current_modname() local mod_path = minetest.get_modpath(mod_name) -local me = sum_hot_air_balloon +local me = sum_airship me.vars = { lift = 4, @@ -9,153 +9,10 @@ me.vars = { fuel_time = 30, } -local ship = { - physical = true, - pointable = true, - collisionbox = {-0.6, -0.2, -0.6, 0.6, 0.3, 0.6}, - selectionbox = {-0.7, -0.35, -0.7, 0.7, 0.3, 0.7}, - hp_max = 3, - visual = "mesh", - backface_culling = false, - mesh = "sum_airship_boat.b3d", - textures = {"sum_airship_texture.png"}, - animations = { - idle = {x= 10, y= 90}, - fly = {x= 91, y= 170}, - boost = {x= 91, y= 170}, - }, - on_rightclick = me.on_rightclick, - on_activate = me.on_activate, - get_staticdata = me.get_staticdata, - on_death = me.on_death, - on_step = me.on_step, - _driver = nil, - _removed = false, - _flags = {}, - _itemstring = "sum_hot_air_balloon:balloon_item", -} - -local sounds = { - engine_idle = { - sound_name = "sum_airship_lip_trill", - gain = 1.4, - max_hear_distance = 10, - loop = false, - pitch = 0.75, - }, - engine_stop = { - sound_name = "sum_airship_lip_trill_end", - gain = 2.2, - max_hear_distance = 10, - loop = false, - pitch = 1, - }, - engine_boost = { - sound_name = "sum_airship_lip_trill", - gain = 40, - max_hear_distance = 10, - loop = false, - pitch = 1, - }, -} - -function ship.sound_play(self, sound_obj, sound_instance) - sound_instance.handle = minetest.sound_play(sound_obj.sound_name, { - gain = sound_obj.gain, - max_hear_distance = sound_obj.max_hear_distance, - loop = sound_obj.loop, - pitch = sound_obj.pitch or 1, - object = self.object, - }) - sound_instance.playing = true - sound_instance.time_elapsed = 0 -end - -function ship.sound_stop(sound_instance) - if sound_instance.handle then - minetest.sound_stop(sound_instance.handle) - end - sound_instance.playing = false - sound_instance.time_elapsed = 0 - sound_instance.handle = nil -end - -function ship.update_sound(self, dtime, forward) - local fuel = self._fuel - local is_thrust = forward ~= 0 and self._driver - if not fuel or not type(fuel) == "number" then self._fuel = 0 end - - if self._sounds.engine.time_elapsed > 2.1 - and self._sounds.engine.handle - and self._sounds.engine.playing then - ship.sound_stop(self._sounds.engine) - end - if not self._sounds.engine.playing then - if self._fuel > 1 then - ship.sound_play(self, sounds.engine_boost, self._sounds.engine) - elseif is_thrust then - ship.sound_play(self, sounds.engine_idle, self._sounds.engine) - end - if self._fuel > 1 and self._sounds.engine_stop.playing then - ship.sound_stop(self._sounds.engine_stop) - end - end - - if self._fuel <= 1 and self._sounds.engine.playing then - if self._fuel > 0 and not self._sounds.engine_stop.playing - and self._sounds.engine_stop.time_elapsed == 0 then - ship.sound_play(self, sounds.engine_stop, self._sounds.engine_stop) - end - if not is_thrust - or (self._sounds.engine_stop.time_elapsed == 0 - and self._sounds.engine_stop.playing) then - ship.sound_stop(self._sounds.engine) - end - end -end - -minetest.register_on_respawnplayer(detach_object) - -function ship.on_rightclick(self, clicker) - local item = clicker:get_wielded_item() - local item_name = item:get_name() - if clicker and (string.find(item_name, ":coal") - or string.find(item_name, ":charcoal")) then - if not minetest.is_creative_enabled(clicker:get_player_name()) then - item:take_item() - clicker:set_wielded_item(item) - end - self._fuel = self._fuel + sum_airship.fuel_time - ship.sound_stop(self._sounds.engine) - minetest.sound_play("sum_airship_fire", { - gain = 1, - object = self.object, - }) - else - attach_object(self, clicker) - end -end - -ship.chimney_dist = -1.0 -ship.chimney_yaw = 0.13 -ship.chimney_height = 0.9 -function ship.get_chimney_pos(self) - local p = self.object:get_pos() - local yaw = self.object:get_yaw() - local ret = { - x = p.x + (ship.chimney_dist * math.sin(-yaw + ship.chimney_yaw)), - y = p.y + ship.chimney_height, - z = p.z + (ship.chimney_dist * math.cos(-yaw + ship.chimney_yaw))} - return ret -end - function me.on_activate(self, staticdata, dtime_s) local data = minetest.deserialize(staticdata) if type(data) == "table" then - self._v = data.v - self._last_v = self._v self._itemstring = data.itemstring - self._fuel = data.fuel if data._driver then self._driver = minetest.get_player_by_name((data._driver:get_player_name())) else @@ -359,11 +216,39 @@ function me.on_step(self, dtime, moveresult) end -minetest.register_entity("sum_hot_air_balloon:balloon_ENTITY", ship) +minetest.register_entity("sum_airship:balloon_ENTITY", { + physical = true, + pointable = true, + collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.2, 0.5}, + selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.2, 0.5}, + hp_max = 3, + visual = "mesh", + mesh = "sum_airship.b3d", + backface_culling = false, + textures = { + "sum_airship_canvas.png", -- balloon + "sum_wood_ash_planks.png", -- cradle + "sum_wood_oak_plank.png", -- lining + "sum_wood_oak_plank.png", -- strut + "sum_wood_oak_plank.png", -- strut + "sum_airship_canvas.png", -- burner + "sum_wood_oak_plank.png", -- small strut + "sum_wood_oak_plank.png", -- small strut + }, + on_rightclick = me.on_rightclick, + on_activate = me.on_activate, + get_staticdata = me.get_staticdata, + on_death = me.on_death, + on_step = me.on_step, + _driver = nil, + _removed = false, + _flags = {}, + _itemstring = "sum_airship:balloon_item", +}) -minetest.register_craftitem("sum_hot_air_balloon:balloon_item", { +minetest.register_craftitem("sum_airship:balloon_item", { description = "Hot air balloon", - inventory_image = "sum_hot_air_balloon_item.png", + inventory_image = "sum_airship_item.png", groups = { vehicle = 1, airship = 1, transport = 1}, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then @@ -376,7 +261,7 @@ minetest.register_craftitem("sum_hot_air_balloon:balloon_item", { end end local pos = vector.offset(pointed_thing.above, 0, 0.5, 0) - local self = minetest.add_entity(pos, "sum_hot_air_balloon:balloon_ENTITY"):get_luaentity() + local self = minetest.add_entity(pos, "sum_airship:balloon_ENTITY"):get_luaentity() if not minetest.is_creative_enabled(placer:get_player_name()) then itemstack:take_item() end diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..462ad5e --- /dev/null +++ b/init.lua @@ -0,0 +1,8 @@ +local mod_name = minetest.get_current_modname() +local mod_path = minetest.get_modpath(mod_name) + + +sum_airship = {} + + +dofile(mod_path .. DIR_DELIM .. "balloon.lua")