From 621be8bb84a0a9ff7a98120226bfac99f316c685 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Wed, 10 Feb 2021 12:08:46 +0000 Subject: [PATCH] added flight potion --- README.md | 3 +- flight.lua | 146 ++++++++++++++++++++++++++++ init.lua | 5 + lucky_block.lua | 1 + settings.conf_example | 1 + settingtypes.txt | 1 + textures/ethereal_flight_potion.png | Bin 0 -> 170 bytes 7 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 flight.lua create mode 100644 textures/ethereal_flight_potion.png diff --git a/README.md b/README.md index 2eb233f..eab9f65 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Ethereal Mapgen mod for Minetest (works on all except v6) - https://forum.minetest.net/viewtopic.php?f=11&t=14638 ## Lucky Blocks -45 +46 ## Changelog @@ -17,6 +17,7 @@ Ethereal Mapgen mod for Minetest (works on all except v6) - Rewrite stairs and add auto-select function - Added Lemonade - Added smaller redwood trees, to grow large variety 2 saplings required + - Added Flight Potion (etherium dust arch, fire dust middle, empty bottle bottom) ### 1.27 diff --git a/flight.lua b/flight.lua new file mode 100644 index 0000000..cee278f --- /dev/null +++ b/flight.lua @@ -0,0 +1,146 @@ +local timer_check = 5 -- seconds per check +local flight_secs = 5 * 60 -- seconds of flight +local S = ethereal.intllib + + +-- disable flight +local function set_flight(user, set) + + local privs = minetest.get_player_privs(user:get_player_name()) + privs.fly = set + minetest.set_player_privs(user:get_player_name(), privs) +end + + +-- after function +local function ethereal_set_flight(user) + + local meta = user:get_meta() ; if not meta then return end + local timer = tonumber(meta:get_string("ethereal:fly_timer")) + local privs = minetest.get_player_privs(user:get_player_name()) + + -- timer ran out, remove 'fly' privelage + if not timer or timer <= 0 then + set_flight(user, nil) + return + end + + -- have we already applied 'fly' privelage? + if not privs.fly then + set_flight(user, true) + end + + -- handle timer + timer = timer - timer_check + + local name = user:get_player_name() + + if timer < 10 then + + minetest.chat_send_player(name, + minetest.get_color_escape_sequence("#ff5500") + .. S("Flight timer about to expire!")) + + minetest.sound_play("default_dig_dig_immediate", + {to_player = name, gain = 1.0}, true) + end + + meta:set_string("ethereal:fly_timer", timer) -- lower timer + + minetest.after(timer_check, function() + ethereal_set_flight(user) + end) +end + + +-- on join / leave +minetest.register_on_joinplayer(function(player) + + local meta = player:get_meta() ; if not meta then return end + local privs = minetest.get_player_privs(player:get_player_name()) + + if privs.fly then + + local timer = tonumber(meta:get_string("ethereal:fly_timer")) + + if timer <= 0 then + set_flight(player, nil) + else + ethereal_set_flight(player) + end + end +end) + + +-- potion item +minetest.register_node("ethereal:flight_potion", { + description = S("Flight Potion"), + drawtype = "plantlike", + tiles = {"ethereal_flight_potion.png"}, + inventory_image = "ethereal_flight_potion.png", + wield_image = "ethereal_flight_potion.png", + paramtype = "light", + sunlight_propagates = true, + walkable = false, + selection_box = { + type = "fixed", + fixed = {-0.2, -0.37, -0.2, 0.2, 0.31, 0.2} + }, + groups = {dig_immediate = 3}, + sounds = default.node_sound_glass_defaults(), + + on_use = function(itemstack, user, pointed_thing) + + -- get privs + local name = user:get_player_name() + local privs = minetest.get_player_privs(name) + local meta = user:get_meta() + local timer = meta:get_string("ethereal:fly_timer") + + if privs.fly then + minetest.chat_send_player(name, + minetest.get_color_escape_sequence("#ffff00") + .. S("Flight already granted, @1 seconds left!", timer)) + return + end + + if not meta then return end + + meta:set_string("ethereal:fly_timer", flight_secs) + + minetest.chat_send_player(name, + minetest.get_color_escape_sequence("#1eff00") + .. S("Flight granted, you have @1 seconds!", flight_secs)) + + ethereal_set_flight(user) + + -- take item + itemstack:take_item() + + -- return empty bottle + local inv = user:get_inventory() + + if inv:room_for_item("main", {name = "vessels:glass_bottle"}) then + user:get_inventory():add_item("main", "vessels:glass_bottle") + else + local pos = user:get_pos() + pos.y = pos.y + 0.5 + minetest.add_item(pos, {name = "vessels:glass_bottle"}) + end + + return itemstack + end +}) + + +-- recipe +if ethereal.flight then +minetest.register_craft({ + output = "ethereal:flight_potion", + recipe = { + {"ethereal:etherium_dust", "ethereal:etherium_dust", "ethereal:etherium_dust"}, + {"ethereal:etherium_dust", "ethereal:fire_dust", "ethereal:etherium_dust"}, + {"ethereal:etherium_dust", "vessels:glass_bottle", "ethereal:etherium_dust"}, + } +}) +end diff --git a/init.lua b/init.lua index 9e8ad64..2584b72 100644 --- a/init.lua +++ b/init.lua @@ -19,6 +19,7 @@ ethereal = { papyruswalk = minetest.settings:get_bool('ethereal.papyruswalk', true), lilywalk = minetest.settings:get_bool('ethereal.lilywalk', true), xcraft = minetest.settings:get_bool('ethereal.xcraft', true), + flight = minetest.settings:get_bool('ethereal.flight', true), glacier = minetest.settings:get('ethereal.glacier') or 1, bamboo = minetest.settings:get('ethereal.bamboo') or 1, @@ -109,6 +110,10 @@ dofile(path .. "/compatibility.lua") dofile(path .. "/stairs.lua") dofile(path .. "/lucky_block.lua") +if ethereal.flight then + dofile(path .. "/flight.lua") +end + -- Set bonemeal aliases if minetest.get_modpath("bonemeal") then minetest.register_alias("ethereal:bone", "bonemeal:bone") diff --git a/lucky_block.lua b/lucky_block.lua index 604c0d1..24663e5 100644 --- a/lucky_block.lua +++ b/lucky_block.lua @@ -33,6 +33,7 @@ lucky_block:add_blocks({ {"dro", {"ethereal:willow_sapling"} ,5}, {"dro", {"ethereal:mushroom_sapling"} ,5}, {"dro", {"ethereal:palm_sapling"} ,5}, + {"dro", {"ethereal:flight_potion", 1}, {"dro", {"ethereal:birch_sapling"} ,5}, {"dro", {"ethereal:redwood_sapling"} ,1}, {"dro", {"ethereal:prairie_dirt"}, 10}, diff --git a/settings.conf_example b/settings.conf_example index 83cf5fc..dc761aa 100644 --- a/settings.conf_example +++ b/settings.conf_example @@ -11,6 +11,7 @@ ethereal.torchdrop = true -- torches drop when touching water ethereal.papyruswalk = true -- papyrus can be walked on ethereal.lilywalk = true -- waterlilies can be walked on ethereal.xcraft = true -- allow cheat crafts for cobble->gravel->dirt->sand, ice->snow, dry dirt->desert sand +ethereal.flight = true -- allow flight potion recipe -- Set following to 1 to enable biome or false to disable ethereal.glacier = 1 -- Ice glaciers with snow diff --git a/settingtypes.txt b/settingtypes.txt index 1cc37de..44cdab6 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -6,6 +6,7 @@ ethereal.torchdrop (Torches drop when in water) bool true ethereal.papyruswalk (Papyrus and Bamboo are walkable) bool true ethereal.lilywalk (Lilypads are walkable) bool true ethereal.xcraft (Enable X-Craft cheats) bool true +ethereal.flight (Enable Flight Potion) bool true ethereal.glacier (Glacier biome, 1 = Enable / 0 = Disable) int 1 ethereal.bambo (Bamboo biome, 1 = Enable / 0 = Disable) int 1 diff --git a/textures/ethereal_flight_potion.png b/textures/ethereal_flight_potion.png new file mode 100644 index 0000000000000000000000000000000000000000..41d6abb15a5a2711006a9b5dbc7d934e8cdbf787 GIT binary patch literal 170 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPGa4)6(aRb*g@&6+u}ETwAN>+M@k zZ`pVD%!NA_Z#;PZ{qI#BEs!$Ck|4ie28U-i(tsRWPZ!4!j_b(@3Va5d4jI?BY+~Wi z_T<%idVno?gVWWL5*7!EvqA!HEgKWHX9(ux=x_;UPRno&J@X)pO@-mM6IY4(rsp9* PgBUzr{an^LB{Ts5L-#qX literal 0 HcmV?d00001