1
0
Fork 0

Merge pull request 'Make mobs ride minecarts' (#3507) from mobs_in_minecarts into master

Reviewed-on: MineClone2/MineClone2#3507
Reviewed-by: ancientmarinerdev <ancientmariner_dev@proton.me>
This commit is contained in:
ancientmarinerdev 2023-03-20 13:42:38 +00:00
commit 5409a382f9
1 changed files with 30 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
@ -86,6 +87,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
local data = minetest.deserialize(staticdata)
if type(data) == "table" then
self._railtype = data._railtype
self._passenger = data._passenger
end
self.object:set_armor_groups({immortal=1})
@ -177,6 +179,8 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
cart.on_activate_by_rail = on_activate_by_rail
local passenger_attach_position = vector.new(0, -1.75, 0)
function cart:on_step(dtime)
local ctrl, player = nil, nil
if self._driver then
@ -212,6 +216,32 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
end
end
-- Grab mob
if math.random(1,20) > 15 and 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
mob:set_attach(self.object, "", passenger_attach_position, vector.zero())
break
end
end
end
end
-- Make room in the minecart after the mob dies
elseif self._passenger then
if math.random(1,20) == 1 then
local dead = self._passenger:check_for_death()
if dead == true then
self._passenger = nil
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()