Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gpcf/elevator into gpcf-m…
Browse files Browse the repository at this point in the history
…aster
  • Loading branch information
linewriter1024 committed Jun 14, 2021
2 parents a0f873e + 575bc0c commit d9df0bf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ read_globals = {

-- Minetest
"minetest",
"core",
"vector",
"VoxelManip",

-- deps
"default", "screwdriver",
"farming", "armor",
"mcl_core", "mcl_sounds",
}
2 changes: 1 addition & 1 deletion crafts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ elseif technic_path and chains_path then
{"chains:chain", "default:diamond", "chains:chain"}
},
})
elseif technic_path and farming and farming.mod and farming.mod == "redo" then
elseif technic_path and farming and farming.mod and ( farming.mod == "redo" or farming.mod == "undo" ) then
-- add alternative recipe with hemp rope
minetest.register_craft({
output = "elevator:elevator_off",
Expand Down
2 changes: 1 addition & 1 deletion helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ elevator.teleport_player_from_elevator = function(player)
if node.name == "elevator:elevator_on" then
local front = vector.subtract(pos, minetest.facedir_to_dir(node.param2))
local front_above = vector.add(front, {x=0, y=1, z=0})
local front_below = vector.subtract(front, {x=0, y=1, z=0})
-- local front_below = vector.subtract(front, {x=0, y=1, z=0})
-- If the front isn't solid, it's ok to teleport the player.
if not solid(front) and not solid(front_above) then
player:set_pos(front)
Expand Down
20 changes: 17 additions & 3 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ elevator = {
VISUAL_INCREASE = 1.75,
VERSION = 8, -- Elevator interface/database version.
PTIMEOUT = minetest.settings:get("elevator_time") or 120, -- Maximum time a box can go without players nearby.

SLOW_DIST = 16,
SLOW_SPEED = 1.75,
boxes = {}, -- Elevator boxes in action.
lastboxes = {}, -- Player near box timeout.
riding = {}, -- Players riding boxes.
Expand Down Expand Up @@ -50,9 +51,19 @@ elevator.create_box = function(motorhash, pos, target, sender)
obj:get_luaentity().target = target
obj:get_luaentity().halfway = {x=pos.x, y=(pos.y+target.y)/2, z=pos.z}
obj:get_luaentity().vmult = (target.y < pos.y) and -1 or 1
-- FIX for "overshooting"
local delta_y = math.abs(pos.y-target.y)

local speed = elevator.SPEED
if (delta_y<elevator.SLOW_DIST) then
speed = elevator.SLOW_SPEED

end

-- Set the speed.
obj:set_velocity({x=0, y=elevator.SPEED*obj:get_luaentity().vmult, z=0})
obj:set_velocity({x=0, y=speed*obj:get_luaentity().vmult, z=0})
obj:set_acceleration({x=0, y=elevator.ACCEL*obj:get_luaentity().vmult, z=0})

-- Set the tables.
elevator.boxes[motorhash] = obj
elevator.riding[sender:get_player_name()] = {
Expand Down Expand Up @@ -137,7 +148,6 @@ elevator.build_motor = function(hash)
end

elevator.unbuild = function(pos, add)
local need_saving = false
local p = table.copy(pos)
p.y = p.y - 1
-- Loop down through the network, set any elevators below this to the off position.
Expand Down Expand Up @@ -304,6 +314,10 @@ local box_entity = {
for y=self.lastpos.y,pos.y,((self.lastpos.y > pos.y) and -0.3 or 0.3) do
local p = vector.round({x=pos.x, y=y, z=pos.z})
local node = get_node(p)
if vector.distance(p,self.target) < elevator.SLOW_DIST then
self.object:set_velocity({x=0, y=elevator.SLOW_SPEED*self.vmult, z=0})
end

if node.name == "elevator:shaft" then
-- Nothing, just continue on our way.
elseif node.name == "elevator:elevator_on" or node.name == "elevator:elevator_off" then
Expand Down

0 comments on commit d9df0bf

Please sign in to comment.