Make punch move minecarts a little, comment out more debug prints

This commit is contained in:
teknomunk 2024-04-25 08:34:11 +00:00
parent 61a1cda7f8
commit 9d393aa2f1
2 changed files with 26 additions and 4 deletions

View File

@ -53,7 +53,7 @@ local function detach_driver(self)
local cart_pos = mod.get_cart_position(staticdata) or self.object:get_pos()
local new_pos = vector.offset(cart_pos, -dir.z, 0, dir.x)
player:set_detach()
print("placing player at "..tostring(new_pos).." from cart at "..tostring(cart_pos)..", old_pos="..tostring(player:get_pos()).."dir="..tostring(dir))
--print("placing player at "..tostring(new_pos).." from cart at "..tostring(cart_pos)..", old_pos="..tostring(player:get_pos()).."dir="..tostring(dir))
-- There needs to be a delay here or the player's position won't update
minetest.after(0.1,function(driver_name,new_pos)
@ -63,8 +63,8 @@ local function detach_driver(self)
player:set_eye_offset(vector.new(0,0,0),vector.new(0,0,0))
mcl_player.player_set_animation(player, "stand" , 30)
else
print("No player object found for "..driver_name)
--else
--print("No player object found for "..driver_name)
end
end
@ -188,6 +188,23 @@ function DEFAULT_CART_DEF:get_cart_position()
return self.object:get_pos()
end
end
function DEFAULT_CART_DEF:on_punch(puncher, time_from_last_punch, tool_capabilities, dir, damage)
if puncher == self._driver then return end
local staticdata = self._staticdata
local controls = staticdata.controls or {}
local impulse = vector.multiply(dir, damage * 20)
local accel = vector.dot(staticdata.dir, impulse)
if accel < 0 and staticdata.velocity == 0 then
mod.reverse_direction(staticdata)
end
controls.impulse = impulse
--print("uuid="..self._uuid..", controls="..dump(controls))
staticdata.controls = controls
end
function DEFAULT_CART_DEF:on_step(dtime)
local staticdata = self._staticdata
if not staticdata then
@ -206,7 +223,7 @@ function DEFAULT_CART_DEF:on_step(dtime)
-- Remove superceded entities
if self._seq ~= staticdata.seq then
print("removing cart #"..staticdata.uuid.." with sequence number mismatch")
--print("removing cart #"..staticdata.uuid.." with sequence number mismatch")
self.object:remove()
return
end

View File

@ -46,6 +46,7 @@ local function reverse_direction(staticdata)
mod.reverse_cart_direction(staticdata)
end
mod.reverse_direction = reverse_direction
--[[
@ -268,6 +269,9 @@ local function calculate_acceleration(staticdata)
acceleration = 4
elseif (ctrl.brake or 0) > time_active then
acceleration = -1.5
elseif ctrl.impulse then
acceleration = vector.dot(staticdata.dir, ctrl.impulse)
ctrl.impulse = nil
elseif (staticdata.fueltime or 0) > 0 and staticdata.velocity <= 4 then
acceleration = 0.6
elseif staticdata.velocity >= ( node_def._max_acceleration_velocity or SPEED_MAX ) then
@ -310,6 +314,7 @@ local function do_movement_step(staticdata, dtime)
": a="..tostring(a)..
",v_0="..tostring(v_0)..
",x_0="..tostring(x_0)..
",dtime="..tostring(dtime)..
",timestep="..tostring(timestep)..
",dir="..tostring(staticdata.dir)..
",connected_at="..tostring(staticdata.connected_at)..