accelerate non-moving carts on `mcl_minecarts:golden_rail_on` (#4097)
accelerate a non-moving minecart away from a solid opaque block the powered rail is facing Reviewed-on: MineClone2/MineClone2#4097 Reviewed-by: the-real-herowl <the-real-herowl@noreply.git.minetest.land> Co-authored-by: nixnoxus <nixnoxus@web.de> Co-committed-by: nixnoxus <nixnoxus@web.de>
This commit is contained in:
parent
26fc0cd4d8
commit
08b41a3b39
|
@ -134,4 +134,34 @@ function mcl_minecarts:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return {x=0, y=0, z=0}
|
return {x=0, y=0, z=0}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local plane_adjacents = {
|
||||||
|
vector.new(-1,0,0),
|
||||||
|
vector.new(1,0,0),
|
||||||
|
vector.new(0,0,-1),
|
||||||
|
vector.new(0,0,1),
|
||||||
|
}
|
||||||
|
|
||||||
|
function mcl_minecarts:get_start_direction(pos)
|
||||||
|
local dir
|
||||||
|
local i = 0
|
||||||
|
while (not dir and i < #plane_adjacents) do
|
||||||
|
i = i+1
|
||||||
|
local node = minetest.get_node_or_nil(vector.add(pos, plane_adjacents[i]))
|
||||||
|
if node ~= nil
|
||||||
|
and minetest.get_item_group(node.name, "rail") == 0
|
||||||
|
and minetest.get_item_group(node.name, "solid") == 1
|
||||||
|
and minetest.get_item_group(node.name, "opaque") == 1
|
||||||
|
then
|
||||||
|
dir = mcl_minecarts:check_front_up_down(pos, vector.multiply(plane_adjacents[i], -1), true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return dir
|
||||||
|
end
|
||||||
|
|
||||||
|
function mcl_minecarts:set_velocity(obj, dir, factor)
|
||||||
|
obj._velocity = vector.multiply(dir, factor or 3)
|
||||||
|
obj._old_pos = nil
|
||||||
|
obj._punched = true
|
||||||
|
end
|
||||||
|
|
|
@ -241,9 +241,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
|
||||||
if vector.equals(cart_dir, {x=0, y=0, z=0}) then
|
if vector.equals(cart_dir, {x=0, y=0, z=0}) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self._velocity = vector.multiply(cart_dir, 3)
|
mcl_minecarts:set_velocity(self, cart_dir)
|
||||||
self._old_pos = nil
|
|
||||||
self._punched = true
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -300,9 +298,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
|
||||||
time_from_last_punch = math.min(time_from_last_punch, tool_capabilities.full_punch_interval)
|
time_from_last_punch = math.min(time_from_last_punch, tool_capabilities.full_punch_interval)
|
||||||
local f = 3 * (time_from_last_punch / tool_capabilities.full_punch_interval)
|
local f = 3 * (time_from_last_punch / tool_capabilities.full_punch_interval)
|
||||||
|
|
||||||
self._velocity = vector.multiply(cart_dir, f)
|
mcl_minecarts:set_velocity(self, cart_dir, f)
|
||||||
self._old_pos = nil
|
|
||||||
self._punched = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
cart.on_activate_by_rail = on_activate_by_rail
|
cart.on_activate_by_rail = on_activate_by_rail
|
||||||
|
@ -470,7 +466,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local dir, last_switch = nil, nil
|
local dir, last_switch, restart_pos = nil, nil, nil
|
||||||
if not pos then
|
if not pos then
|
||||||
pos = self.object:get_pos()
|
pos = self.object:get_pos()
|
||||||
end
|
end
|
||||||
|
@ -497,6 +493,9 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
|
||||||
minetest.swap_node(rou_pos, newnode)
|
minetest.swap_node(rou_pos, newnode)
|
||||||
mesecon.receptor_on(rou_pos)
|
mesecon.receptor_on(rou_pos)
|
||||||
end
|
end
|
||||||
|
if node.name == "mcl_minecarts:golden_rail_on" then
|
||||||
|
restart_pos = rou_pos
|
||||||
|
end
|
||||||
if node_old.name == "mcl_minecarts:detector_rail_on" then
|
if node_old.name == "mcl_minecarts:detector_rail_on" then
|
||||||
local newnode = {name="mcl_minecarts:detector_rail", param2 = node_old.param2}
|
local newnode = {name="mcl_minecarts:detector_rail", param2 = node_old.param2}
|
||||||
minetest.swap_node(rou_old, newnode)
|
minetest.swap_node(rou_old, newnode)
|
||||||
|
@ -647,6 +646,14 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
|
||||||
if update.pos then
|
if update.pos then
|
||||||
self.object:set_pos(pos)
|
self.object:set_pos(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- stopped on "mcl_minecarts:golden_rail_on"
|
||||||
|
if vector.equals(vel, {x=0, y=0, z=0}) and restart_pos then
|
||||||
|
local dir = mcl_minecarts:get_start_direction(restart_pos)
|
||||||
|
if dir then
|
||||||
|
mcl_minecarts:set_velocity(self, dir)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function cart:get_staticdata()
|
function cart:get_staticdata()
|
||||||
|
@ -687,7 +694,15 @@ function mcl_minecarts.place_minecart(itemstack, pointed_thing, placer)
|
||||||
if le then
|
if le then
|
||||||
le._railtype = railtype
|
le._railtype = railtype
|
||||||
end
|
end
|
||||||
local cart_dir = mcl_minecarts:get_rail_direction(railpos, {x=1, y=0, z=0}, nil, nil, railtype)
|
local cart_dir
|
||||||
|
if node.name == "mcl_minecarts:golden_rail_on" then
|
||||||
|
cart_dir = mcl_minecarts:get_start_direction(railpos)
|
||||||
|
end
|
||||||
|
if cart_dir then
|
||||||
|
mcl_minecarts:set_velocity(le, cart_dir)
|
||||||
|
else
|
||||||
|
cart_dir = mcl_minecarts:get_rail_direction(railpos, {x=1, y=0, z=0}, nil, nil, railtype)
|
||||||
|
end
|
||||||
cart:set_yaw(minetest.dir_to_yaw(cart_dir))
|
cart:set_yaw(minetest.dir_to_yaw(cart_dir))
|
||||||
|
|
||||||
local pname = ""
|
local pname = ""
|
||||||
|
|
|
@ -112,6 +112,22 @@ register_rail("mcl_minecarts:golden_rail_on",
|
||||||
onstate = "mcl_minecarts:golden_rail_on",
|
onstate = "mcl_minecarts:golden_rail_on",
|
||||||
rules = rail_rules_long,
|
rules = rail_rules_long,
|
||||||
},
|
},
|
||||||
|
effector = {
|
||||||
|
action_on = function(pos, node)
|
||||||
|
local dir = mcl_minecarts:get_start_direction(pos)
|
||||||
|
if not dir then return end
|
||||||
|
local objs = minetest.get_objects_inside_radius(pos, 1)
|
||||||
|
for _, o in pairs(objs) do
|
||||||
|
local l = o:get_luaentity()
|
||||||
|
local v = o:get_velocity()
|
||||||
|
if l and string.sub(l.name, 1, 14) == "mcl_minecarts:"
|
||||||
|
and v and vector.equals(v, vector.zero())
|
||||||
|
then
|
||||||
|
mcl_minecarts:set_velocity(l, dir)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
drop = "mcl_minecarts:golden_rail",
|
drop = "mcl_minecarts:golden_rail",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue