commit 9af26c95968350d3185a82719a86fe5fa392eacd Author: octacian Date: Mon May 15 18:36:12 2017 -0700 Initial commit diff --git a/.gh-screenshot.png b/.gh-screenshot.png new file mode 100644 index 0000000..6e2eee7 Binary files /dev/null and b/.gh-screenshot.png differ diff --git a/.recipe.png b/.recipe.png new file mode 100644 index 0000000..acc9799 Binary files /dev/null and b/.recipe.png differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..615cf7d --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +![Screenshot](.gh-screenshot.png) + +Simple Elevators [televator] +============================ +* GitHub: https://github.com/octacian/televator +* Download: https://github.com/octacian/televator/archive/master.zip +* License: MIT (see below for media license) + +Televator allows you to create simple elevators in your worlds that work incredibly fast amidst lag and are relatively inexpensive to make. All you need to get started, is to craft an elevator (`televator:elevator`). + +Elevator nodes can be placed a maximum of 16 nodes apart. If anything obstructs the space between or there is not 2 blocks of space for the player above the next elevator node, the elevator will not work. + +Once standing on an elevator that has other elevators placed with no obstructions above or below it, you can press jump to go up to the next elevator, and sneak to go down the the previous. There are sound effects too! While standing on an elevator you cannot jump normally so as to maintain a consistent feel when ascending and descending. + +Televator does not use any entities, but rather teleports the player from elevator to elevator making it suitable for servers that prefer to use only the most efficient mods. This also helps increase general performance for users with less powerful computers or mobile devices, and provides a smooth and consistent feel. + +### Recipe +![Recipe](.recipe.png) + +Televator currently only supports Minetest Game items for it's recipe, however, I will gladly add support for other subgames on request. If you are unable to see the picture, please try a different browser such a Chrome/Chromium. + +### Media License +Everything not listed here:
+octacian (CC BY-SA 3.0) + +televator_whoosh.ogg (CC BY-SA 3.0):
+- https://opengameart.org/content/whoosh-1 \ No newline at end of file diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..5e78c21 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default? diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..d9dbb13 --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +Televator allows you to create simple elevators in your worlds that work incredibly fast amidst lag and are relatively inexpensive to make. All you need to get started, is to craft an elevator (`televator:elevator`). diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..404d99a --- /dev/null +++ b/init.lua @@ -0,0 +1,126 @@ +-- televator/init.lua + +local delay = {} + +local itemset +if minetest.get_modpath("default") then + itemset = { + steel = "default:steel_ingot", + gold = "default:gold_ingot", + copper = "default:copper_ingot", + glass = "default:glass", + } +end + +--- +--- Functions +--- + +-- [function] Get near elevators +local function get_near_elevators(pos, which) + for i = 1, 16 do + local cpos = vector.new(pos) + + if which == "above" then + cpos.y = cpos.y + i + elseif which == "below" then + cpos.y = cpos.y - i + end + + local name = minetest.get_node(cpos).name + if (which == "above" and name == "televator:elevator") + or (which == "below" and i ~= 1 and name == "televator:elevator") then + cpos.y = cpos.y + 1 + return cpos + elseif name ~= "air" and name ~= "televator:elevator" then + return + end + end +end + +-- [function] Elevator safe +local function is_safe(pos) + for i = 0, 1 do + local tpos = vector.new(pos) + tpos.y = tpos.y + i + + if minetest.get_node(tpos).name ~= "air" then + return + end + end + + return true +end + +--- +--- Registrations +--- + +-- [register] Elevator node +minetest.register_node("televator:elevator", { + description = "Elevator\n".. + minetest.colorize("grey","Can be placed up to 16 nodes apart\n" + .."Jump to go up, sneak to go down"), + tiles = {"televator_elevator.png"}, + groups = {cracky = 2, disable_jump = 1}, + after_place_node = function(pos) + -- Set infotext + minetest.get_meta(pos):set_string("infotext", "Elevator") + end, +}) + +-- [register] Recipe +if itemset then + minetest.register_craft({ + output = "televator:elevator 2", + recipe = { + {itemset.steel, itemset.glass, itemset.steel}, + {itemset.steel, itemset.gold, itemset.steel}, + {itemset.steel, itemset.copper, itemset.steel,} + }, + }) +end + +-- [register] Globalstep +minetest.register_globalstep(function(dtime) + for _, player in pairs(minetest.get_connected_players()) do + local pos = player:get_pos() + local name = player:get_player_name() + + if not delay[name] then + delay[name] = 0.5 + else + delay[name] = delay[name] + dtime + end + + if not delay[name] or delay[name] > 0.5 then + if minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name == "televator:elevator" then + local where + local controls = player:get_player_control() + if controls.jump then + where = "above" + elseif controls.sneak then + where = "below" + else return end + + local epos = get_near_elevators(pos, where) + if epos and is_safe(epos) then + player:set_pos(epos) -- Update player position + + -- Play sound + minetest.sound_play("televator_whoosh", { + gain = 0.75, + pos = epos, + max_hear_distance = 5, + }) + elseif epos then + minetest.chat_send_player(name, "Elevator blocked by obstruction") + else + minetest.chat_send_player(name, "Could not find elevator") + end + + delay[name] = 0 -- Restart delay + end + end + end +end) diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..504402b --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = televator diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..97038cc Binary files /dev/null and b/screenshot.png differ diff --git a/sounds/televator_whoosh.ogg b/sounds/televator_whoosh.ogg new file mode 100644 index 0000000..a72be50 Binary files /dev/null and b/sounds/televator_whoosh.ogg differ diff --git a/textures/televator_elevator.png b/textures/televator_elevator.png new file mode 100644 index 0000000..4a3fac8 Binary files /dev/null and b/textures/televator_elevator.png differ