tigris-mt / elevator

An entity-based elevator allowing fast realtime travel in Minetest.
https://forum.minetest.net/viewtopic.php?f=9&t=17079
Other
4 stars 14 forks source link

Make stacking the nodes easier #14

Closed Poikilos closed 3 years ago

Poikilos commented 4 years ago

Stacking nodes is very difficult, since (even if you shift-right-click which is required in the case of elevator) the edge is very small. You could make "top" versions that get replaced when you stack on the bottom or top of them, a better solution may be something like:

local elevator_part_names = {"elevator:elevator_on", "elevator:shaft", "elevator:motor", "elevator:off"}

local function has_value (tab, val)
    for index, value in ipairs(tab) do
        if value == val then
            return true
        end
    end

    return false
end

local function is_elevator_part(node) then
    return has_value(elevator_part_names, node.name)
end
local function is_elevator_part_at(pos) then
    local node = minetest.get_node(pos)
    return is_elevator_part(node)
end

local function pos_above_pos(pos)
    return {x = pos.x, y=pos.y, z=pos.z+1.0}
end

local function pos_below_pos(pos)
    return {x = pos.x, y=pos.y, z=pos.z-1.0}
end

local function is_elevator_part_above_or_below_pos(pos)
    return is_elevator_part_at(pos_above_pos(pos)) or is_elevator_part_at(pos_below_pos(pos))
end

local function positions_around(pos)
    return {
        {x = pos.x-1, y=pos.y, z=pos.z},
        {x = pos.x+1, y=pos.y, z=pos.z},
        {x = pos.x, y=pos.y-1, z=pos.z},
        {x = pos.x, y=pos.y+1, z=pos.z}
    }
end

minetest.register_on_placenode(
    function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
        if not is_elevator_part_above_or_below_pos(pos) then
            for i,next_pos in ipairs(positions_around(pos)) do
                if is_elevator_part_above_or_below_pos(next_pos)
                    if minetest.get_node(next_pos).name == "air" then
                        -- TODO: instead of placing at pos, place at next_pos
                    end
                end
            end
        end
    end
)
S-S-X commented 3 years ago

Could also check wield item and skip right click handler if item is from elavator mod, that would allow placing those without holding sneak. Basically player could not open formspec if he is holding elevator components in hand while right clicking elevator box.

That solution to allow even easier shaft placement above elevator box would also be fairly simple addition in terms of LoC.