mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-08-22 01:47:24 +02:00
Make trains containing a player in a minecart function, minor cleanup in mcl_playerinfo
This commit is contained in:
parent
475d6f3e93
commit
79b3b3b26b
@ -27,10 +27,23 @@ local function detach_driver(self)
|
|||||||
if not self._driver then
|
if not self._driver then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
mcl_player.player_attached[self._driver] = nil
|
|
||||||
local player = minetest.get_player_by_name(self._driver)
|
-- Update player infomation
|
||||||
|
local driver_name = self._driver
|
||||||
|
local playerinfo = mcl_playerinfo[driver_name]
|
||||||
|
if playerinfo then
|
||||||
|
playerinfo.attached_to = nil
|
||||||
|
end
|
||||||
|
mcl_player.player_attached[driver_name] = nil
|
||||||
|
|
||||||
|
minetest.log("action", driver_name.." left a minecart")
|
||||||
|
|
||||||
|
-- Update cart informatino
|
||||||
self._driver = nil
|
self._driver = nil
|
||||||
self._start_pos = nil
|
self._start_pos = nil
|
||||||
|
|
||||||
|
-- Detatch the player object from the minecart
|
||||||
|
local player = minetest.get_player_by_name(driver_name)
|
||||||
if player then
|
if player then
|
||||||
player:set_detach()
|
player:set_detach()
|
||||||
player:set_eye_offset(vector.new(0,0,0),vector.new(0,0,0))
|
player:set_eye_offset(vector.new(0,0,0),vector.new(0,0,0))
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
local S = minetest.get_translator(modname)
|
local S = minetest.get_translator(modname)
|
||||||
|
local mcl_log = mcl_util.make_mcl_logger("mcl_logging_minecarts", "Minecarts")
|
||||||
|
|
||||||
local function activate_normal_minecart(self)
|
local function activate_normal_minecart(self)
|
||||||
detach_driver(self)
|
detach_driver(self)
|
||||||
@ -35,28 +36,35 @@ mcl_minecarts.register_minecart({
|
|||||||
icon = "mcl_minecarts_minecart_normal.png",
|
icon = "mcl_minecarts_minecart_normal.png",
|
||||||
drop = {"mcl_minecarts:minecart"},
|
drop = {"mcl_minecarts:minecart"},
|
||||||
on_rightclick = function(self, clicker)
|
on_rightclick = function(self, clicker)
|
||||||
local name = clicker:get_player_name()
|
-- Make sure we have a player
|
||||||
if not clicker or not clicker:is_player() then
|
if not clicker or not clicker:is_player() then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
local player_name = clicker:get_player_name()
|
local player_name = clicker:get_player_name()
|
||||||
if self._driver and player_name == self._driver then
|
if self._driver or clicker:get_player_control().sneak then return end
|
||||||
--detach_driver(self)
|
|
||||||
elseif not self._driver and not clicker:get_player_control().sneak then
|
-- Update cart information
|
||||||
self._driver = player_name
|
self._driver = player_name
|
||||||
self._start_pos = self.object:get_pos()
|
self._start_pos = self.object:get_pos()
|
||||||
mcl_player.player_attached[player_name] = true
|
|
||||||
clicker:set_attach(self.object, "", vector.new(1,-1.75,-2), vector.new(0,0,0))
|
-- Update player information
|
||||||
mcl_player.player_attached[name] = true
|
local uuid = self._staticdata.uuid
|
||||||
minetest.after(0.2, function(name)
|
local playerinfo = mcl_playerinfo[player_name]
|
||||||
local player = minetest.get_player_by_name(name)
|
if playerinfo and self._staticdata then
|
||||||
if player then
|
playerinfo.attached_to = uuid
|
||||||
mcl_player.player_set_animation(player, "sit" , 30)
|
|
||||||
player:set_eye_offset(vector.new(0,-5.5,0), vector.new(0,-4,0))
|
|
||||||
mcl_title.set(clicker, "actionbar", {text=S("Sneak to dismount"), color="white", stay=60})
|
|
||||||
end
|
|
||||||
end, name)
|
|
||||||
end
|
end
|
||||||
|
mcl_player.player_attached[player_name] = true
|
||||||
|
minetest.log("action", player_name.." entered minecart #"..tostring(uuid).." at "..tostring(self._start_pos))
|
||||||
|
|
||||||
|
-- Attach the player object to the minecart
|
||||||
|
clicker:set_attach(self.object, "", vector.new(1,-1.75,-2), vector.new(0,0,0))
|
||||||
|
minetest.after(0.2, function(name)
|
||||||
|
local player = minetest.get_player_by_name(name)
|
||||||
|
if player then
|
||||||
|
mcl_player.player_set_animation(player, "sit" , 30)
|
||||||
|
player:set_eye_offset(vector.new(0,-5.5,0), vector.new(0,-4,0))
|
||||||
|
mcl_title.set(clicker, "actionbar", {text=S("Sneak to dismount"), color="white", stay=60})
|
||||||
|
end
|
||||||
|
end, player_name)
|
||||||
end,
|
end,
|
||||||
on_activate_by_rail = activate_normal_minecart,
|
on_activate_by_rail = activate_normal_minecart,
|
||||||
_mcl_minecarts_on_step = function(self, dtime)
|
_mcl_minecarts_on_step = function(self, dtime)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name = mcl_minecarts
|
name = mcl_minecarts
|
||||||
author = Krock
|
author = Krock
|
||||||
description = Minecarts are vehicles to move players quickly on rails.
|
description = Minecarts are vehicles to move players quickly on rails.
|
||||||
depends = mcl_title, mcl_explosions, mcl_core, mcl_util, mcl_sounds, mcl_player, mcl_achievements, mcl_chests, mcl_furnaces, mesecons_commandblock, mcl_hoppers, mcl_tnt, mesecons, mcl_entity_invs
|
depends = mcl_title, mcl_explosions, mcl_core, mcl_util, mcl_sounds, mcl_player, mcl_playerinfo, mcl_achievements, mcl_chests, mcl_furnaces, mesecons_commandblock, mcl_hoppers, mcl_tnt, mesecons, mcl_entity_invs
|
||||||
optional_depends = doc_identifier, mcl_wip, mcl_physics
|
optional_depends = doc_identifier, mcl_wip, mcl_physics
|
||||||
|
@ -171,13 +171,21 @@ local function handle_cart_collision(cart1, prev_pos, next_dir)
|
|||||||
cart2_staticdata.dir = mcl_minecarts:get_rail_direction(cart2_staticdata.connected_at, cart1_staticdata.dir)
|
cart2_staticdata.dir = mcl_minecarts:get_rail_direction(cart2_staticdata.connected_at, cart1_staticdata.dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function vector_away_from_players(self, staticdata)
|
local function vector_away_from_players(self, staticdata)
|
||||||
local objs = minetest.get_objects_inside_radius(self.object:get_pos(), 1.1)
|
local function player_repel(obj, self)
|
||||||
for n=1,#objs do
|
-- Only repel from players
|
||||||
local obj = objs[n]
|
|
||||||
local player_name = obj:get_player_name()
|
local player_name = obj:get_player_name()
|
||||||
if player_name and player_name ~= "" and not ( self._driver and self._driver == player_name ) then
|
if not player_name or player_name == "" then return false end
|
||||||
|
|
||||||
|
-- Don't repel away from players in minecarts
|
||||||
|
local playerinfo = mcl_playerinfo[player_name]
|
||||||
|
if playerinfo and playerinfo.attached_to then return false end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
for _,obj in pairs(minetest.get_objects_inside_radius(self.object:get_pos(), 1.1)) do
|
||||||
|
if player_repel(obj, self) then
|
||||||
return obj:get_pos() - self.object:get_pos()
|
return obj:get_pos() - self.object:get_pos()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -89,7 +89,7 @@ function mod.update_train(cart)
|
|||||||
|
|
||||||
-- Only update from the back
|
-- Only update from the back
|
||||||
if staticdata.behind or not staticdata.ahead then return end
|
if staticdata.behind or not staticdata.ahead then return end
|
||||||
print("\nUpdating train")
|
--print("\nUpdating train")
|
||||||
|
|
||||||
-- Do no special processing if the cart is not part of a train
|
-- Do no special processing if the cart is not part of a train
|
||||||
if not staticdata.ahead and not staticdata.behind then return end
|
if not staticdata.ahead and not staticdata.behind then return end
|
||||||
@ -102,7 +102,7 @@ function mod.update_train(cart)
|
|||||||
count = count + 1
|
count = count + 1
|
||||||
end
|
end
|
||||||
velocity = velocity / count
|
velocity = velocity / count
|
||||||
print("Using velocity "..tostring(velocity))
|
--print("Using velocity "..tostring(velocity))
|
||||||
|
|
||||||
-- Set the entire train to the average velocity
|
-- Set the entire train to the average velocity
|
||||||
local behind = nil
|
local behind = nil
|
||||||
@ -125,8 +125,10 @@ function mod.update_train(cart)
|
|||||||
cart_velocity = velocity * 1.1
|
cart_velocity = velocity * 1.1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--[[
|
||||||
print(tostring(c.behind).."->"..c.uuid.."->"..tostring(c.ahead).."("..tostring(separation)..") setting cart #"..
|
print(tostring(c.behind).."->"..c.uuid.."->"..tostring(c.ahead).."("..tostring(separation)..") setting cart #"..
|
||||||
c.uuid.." velocity from "..tostring(c.velocity).." to "..tostring(cart_velocity))
|
c.uuid.." velocity from "..tostring(c.velocity).." to "..tostring(cart_velocity))
|
||||||
|
]]
|
||||||
c.velocity = cart_velocity
|
c.velocity = cart_velocity
|
||||||
|
|
||||||
behind = c
|
behind = c
|
||||||
|
@ -21,8 +21,6 @@ local function node_ok(pos, fallback)
|
|||||||
return fallback
|
return fallback
|
||||||
end
|
end
|
||||||
|
|
||||||
local time = 0
|
|
||||||
|
|
||||||
local function get_player_nodes(player_pos)
|
local function get_player_nodes(player_pos)
|
||||||
local work_pos = table.copy(player_pos)
|
local work_pos = table.copy(player_pos)
|
||||||
|
|
||||||
@ -43,11 +41,10 @@ local function get_player_nodes(player_pos)
|
|||||||
return node_stand, node_stand_below, node_head, node_feet, node_head_top
|
return node_stand, node_stand_below, node_head, node_feet, node_head_top
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local time = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
|
|
||||||
time = time + dtime
|
|
||||||
|
|
||||||
-- Run the rest of the code every 0.5 seconds
|
-- Run the rest of the code every 0.5 seconds
|
||||||
|
time = time + dtime
|
||||||
if time < 0.5 then
|
if time < 0.5 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user