forked from VoxeLibre/VoxeLibre
Fix rail detach crash, make tnt minecarts explode if they hit something hard (off rails)
This commit is contained in:
parent
4943fff0d5
commit
4e27774679
|
@ -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
|
||||
accel = vector.add(accel, vector.multiply(friction,-0.9))
|
||||
|
||||
-- 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