Fix a couple of crashes (TNT minecart trying to update orientation after exploding, trying to punch/push a minecart not on track)

This commit is contained in:
teknomunk 2024-08-08 07:21:54 -05:00
parent 9ca053aa2e
commit 89a0bd6e39
1 changed files with 4 additions and 0 deletions

View File

@ -391,6 +391,8 @@ function mod.update_cart_orientation(self)
-- Check if the rotation is a 180 flip and don't change if so -- Check if the rotation is a 180 flip and don't change if so
local rot = self.object:get_rotation() local rot = self.object:get_rotation()
if not rot then return end
local diff = math.abs((rot_y - ( rot.y + pi ) % _2_pi) ) local diff = math.abs((rot_y - ( rot.y + pi ) % _2_pi) )
if diff < 0.001 or diff > _2_pi - 0.001 then if diff < 0.001 or diff > _2_pi - 0.001 then
-- Update rotation adjust and recalculate the rotation -- Update rotation adjust and recalculate the rotation
@ -431,6 +433,8 @@ function mod.reverse_cart_direction(staticdata)
-- Complete moving thru this block into the next, reverse direction, and put us back at the same position we were at -- Complete moving thru this block into the next, reverse direction, and put us back at the same position we were at
local next_dir = -staticdata.dir local next_dir = -staticdata.dir
if not staticdata.connected_at then return end
staticdata.connected_at = staticdata.connected_at + staticdata.dir staticdata.connected_at = staticdata.connected_at + staticdata.dir
staticdata.distance = 1 - (staticdata.distance or 0) staticdata.distance = 1 - (staticdata.distance or 0)