Make trains containing a player in a minecart function, minor cleanup in mcl_playerinfo
This commit is contained in:
parent
e3ca5a84c8
commit
a0d8e5ad7e
|
@ -27,10 +27,23 @@ local function detach_driver(self)
|
|||
if not self._driver then
|
||||
return
|
||||
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._start_pos = nil
|
||||
|
||||
-- Detatch the player object from the minecart
|
||||
local player = minetest.get_player_by_name(driver_name)
|
||||
if player then
|
||||
player:set_detach()
|
||||
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 S = minetest.get_translator(modname)
|
||||
local mcl_log = mcl_util.make_mcl_logger("mcl_logging_minecarts", "Minecarts")
|
||||
|
||||
local function activate_normal_minecart(self)
|
||||
detach_driver(self)
|
||||
|
@ -35,28 +36,35 @@ mcl_minecarts.register_minecart({
|
|||
icon = "mcl_minecarts_minecart_normal.png",
|
||||
drop = {"mcl_minecarts:minecart"},
|
||||
on_rightclick = function(self, clicker)
|
||||
local name = clicker:get_player_name()
|
||||
if not clicker or not clicker:is_player() then
|
||||
return
|
||||
end
|
||||
-- Make sure we have a player
|
||||
if not clicker or not clicker:is_player() then return end
|
||||
|
||||
local player_name = clicker:get_player_name()
|
||||
if self._driver and player_name == self._driver then
|
||||
--detach_driver(self)
|
||||
elseif not self._driver and not clicker:get_player_control().sneak then
|
||||
self._driver = player_name
|
||||
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))
|
||||
mcl_player.player_attached[name] = true
|
||||
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, name)
|
||||
if self._driver or clicker:get_player_control().sneak then return end
|
||||
|
||||
-- Update cart information
|
||||
self._driver = player_name
|
||||
self._start_pos = self.object:get_pos()
|
||||
|
||||
-- Update player information
|
||||
local uuid = self._staticdata.uuid
|
||||
local playerinfo = mcl_playerinfo[player_name]
|
||||
if playerinfo and self._staticdata then
|
||||
playerinfo.attached_to = uuid
|
||||
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,
|
||||
on_activate_by_rail = activate_normal_minecart,
|
||||
_mcl_minecarts_on_step = function(self, dtime)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name = mcl_minecarts
|
||||
author = Krock
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
end
|
||||
|
||||
|
||||
local function vector_away_from_players(self, staticdata)
|
||||
local objs = minetest.get_objects_inside_radius(self.object:get_pos(), 1.1)
|
||||
for n=1,#objs do
|
||||
local obj = objs[n]
|
||||
local function player_repel(obj, self)
|
||||
-- Only repel from players
|
||||
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()
|
||||
end
|
||||
end
|
||||
|
|
|
@ -89,7 +89,7 @@ function mod.update_train(cart)
|
|||
|
||||
-- Only update from the back
|
||||
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
|
||||
if not staticdata.ahead and not staticdata.behind then return end
|
||||
|
@ -102,7 +102,7 @@ function mod.update_train(cart)
|
|||
count = count + 1
|
||||
end
|
||||
velocity = velocity / count
|
||||
print("Using velocity "..tostring(velocity))
|
||||
--print("Using velocity "..tostring(velocity))
|
||||
|
||||
-- Set the entire train to the average velocity
|
||||
local behind = nil
|
||||
|
@ -125,8 +125,10 @@ function mod.update_train(cart)
|
|||
cart_velocity = velocity * 1.1
|
||||
end
|
||||
end
|
||||
--[[
|
||||
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.velocity = cart_velocity
|
||||
|
||||
behind = c
|
||||
|
|
|
@ -21,8 +21,6 @@ local function node_ok(pos, fallback)
|
|||
return fallback
|
||||
end
|
||||
|
||||
local time = 0
|
||||
|
||||
local function get_player_nodes(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
|
||||
end
|
||||
|
||||
local time = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
|
||||
time = time + dtime
|
||||
|
||||
-- Run the rest of the code every 0.5 seconds
|
||||
time = time + dtime
|
||||
if time < 0.5 then
|
||||
return
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue