0
0
Fork 0

Make mobs ride minecarts

This commit is contained in:
anarquimico 2023-03-04 17:14:59 -03:00 committed by Gitea
parent b4ea9f048b
commit d5f01e88c4
1 changed files with 29 additions and 0 deletions

View File

@ -66,6 +66,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
on_rightclick = on_rightclick,
_driver = nil, -- player who sits in and controls the minecart (only for minecart!)
_passenger = nil, -- for mobs
_punched = false, -- used to re-send _velocity and position
_velocity = {x=0, y=0, z=0}, -- only used on punch
_start_pos = nil, -- Used to calculate distance for “On A Rail” achievement
@ -212,6 +213,34 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
end
end
-- Grab mob
if not self._passenger then
if self.name == "mcl_minecarts:minecart" then
local mobsnear = minetest.get_objects_inside_radius(self.object:get_pos(), 1.3)
for n=1, #mobsnear do
local mob = mobsnear[n]
if mob then
local entity = mob:get_luaentity()
if entity and entity.is_mob then
self._passenger = entity.name
mob:set_attach(self.object, "", {x=0, y=-1.75, z=0}, {x=0, y=0, z=0})
break
end
end
end
end
-- Make room in the minecart after the mob dies
elseif self._passenger then
local mobinside = minetest.get_objects_inside_radius(self.object:get_pos(), 1)
for n=1, #mobinside do
local mob = mobinside[n]:get_luaentity()
if not mob or mob.is_mob == false then
self._passenger = nil
break
end
end
end
-- Drop minecart if it isn't on a rail anymore
if self._last_float_check >= mcl_minecarts.check_float_time then
pos = self.object:get_pos()