mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-08-22 09:57:25 +02:00
Fix rail detach crash, make tnt minecarts explode if they hit something hard (off rails)
This commit is contained in:
parent
dcf833907e
commit
db96e86d57
@ -3,7 +3,12 @@ local modpath = minetest.get_modpath(modname)
|
||||
local mod = mcl_minecarts
|
||||
local S = minetest.get_translator(modname)
|
||||
|
||||
-- Minecart with TNT
|
||||
local function detonate_tnt_minecart(self)
|
||||
local pos = self.object:get_pos()
|
||||
self.object:remove()
|
||||
mcl_explosions.explode(pos, 6, { drop_chance = 1.0 })
|
||||
end
|
||||
|
||||
local function activate_tnt_minecart(self, timer)
|
||||
if self._boomtimer then
|
||||
return
|
||||
@ -76,19 +81,24 @@ mod.register_minecart({
|
||||
on_activate_by_rail = activate_tnt_minecart,
|
||||
creative = true,
|
||||
_mcl_minecarts_on_step = function(self, dtime)
|
||||
-- Update TNT stuff
|
||||
-- Impacts reduce the speed greatly. Use this to trigger explosions
|
||||
local current_speed = vector.length(self.object:get_velocity())
|
||||
if current_speed < (self._old_speed or 0) - 6 then
|
||||
detonate_tnt_minecart(self)
|
||||
end
|
||||
self._old_speed = current_speed
|
||||
|
||||
if self._boomtimer then
|
||||
-- Explode
|
||||
self._boomtimer = self._boomtimer - dtime
|
||||
local pos = self.object:get_pos()
|
||||
if self._boomtimer <= 0 then
|
||||
self.object:remove()
|
||||
mcl_explosions.explode(pos, 6, { drop_chance = 1.0 })
|
||||
detonate_tnt_minecart(self)
|
||||
return
|
||||
else
|
||||
tnt.smoke_step(pos)
|
||||
end
|
||||
end
|
||||
|
||||
if self._blinktimer then
|
||||
self._blinktimer = self._blinktimer - dtime
|
||||
if self._blinktimer <= 0 then
|
||||
|
@ -24,6 +24,10 @@ mod.detach_minecart = detach_minecart
|
||||
|
||||
local function try_detach_minecart(self)
|
||||
local staticdata = self._staticdata
|
||||
if not staticdata then return end
|
||||
|
||||
-- Don't try to detach if alread detached
|
||||
if not staticdata.connected_at then return end
|
||||
|
||||
local node = minetest.get_node(staticdata.connected_at)
|
||||
if minetest.get_item_group(node.name, "rail") == 0 then
|
||||
@ -461,7 +465,13 @@ local function do_detached_movement(self, dtime)
|
||||
friction.y = 0
|
||||
|
||||
local accel = vector.new(0,-9.81,0) -- gravity
|
||||
|
||||
-- Don't apply friction in the air
|
||||
local pos_rounded = vector.round(self.object:get_pos())
|
||||
if minetest.get_node(vector.offset(pos_rounded,0,-1,0)).name ~= "air" then
|
||||
accel = vector.add(accel, vector.multiply(friction,-0.9))
|
||||
end
|
||||
|
||||
self.object:set_acceleration(accel)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user