From d5f01e88c4d2431560825c46237d0049d9c40725 Mon Sep 17 00:00:00 2001 From: anarquimico Date: Sat, 4 Mar 2023 17:14:59 -0300 Subject: [PATCH] Make mobs ride minecarts --- mods/ENTITIES/mcl_minecarts/init.lua | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/mods/ENTITIES/mcl_minecarts/init.lua b/mods/ENTITIES/mcl_minecarts/init.lua index 6a837207f..a951ae4b2 100644 --- a/mods/ENTITIES/mcl_minecarts/init.lua +++ b/mods/ENTITIES/mcl_minecarts/init.lua @@ -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()