Skip to content

Commit

Permalink
prevent mimes from trying to repeatedly teleport out of the ground wh…
Browse files Browse the repository at this point in the history
…en they're not in the ground
  • Loading branch information
fluxionary committed May 22, 2023
1 parent 65fec62 commit b69b413
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 37 deletions.
21 changes: 15 additions & 6 deletions .pre-commit-config.yaml
Expand Up @@ -10,16 +10,25 @@ repos:

- repo: local
hooks:
- id: luacheck
name: luacheck
language: system
entry: luacheck
- id: detect_debug
name: detect debug
language: pygrep
entry: DEBUG
pass_filenames: true
types: [ file, lua ]
args: [ -q ]
exclude: .pre-commit-config.yaml
fail_fast: true
- id: stylua
name: stylua
language: system
entry: stylua
pass_filenames: true
types: [ file, lua ]
fail_fast: true
- id: luacheck
name: luacheck
language: system
entry: luacheck
pass_filenames: true
types: [ file, lua ]
args: [ -q ]
fail_fast: true
26 changes: 20 additions & 6 deletions core/mob.lua
Expand Up @@ -24,13 +24,20 @@ mobs:register_mob("mobs_mime:mime", {
knock_back = true, -- It can be knocked back by hits
fear_height = 3, -- It won't fall if the height is too steep
water_damage = 0, -- Doesn't take damage from water
lava_damage = 20, -- It dies if it wals into lava
lava_damage = 20, -- It dies if it falls into lava
light_damage = 0, -- Doesn't take damage from light
light_damage_min = (minetest.LIGHT_MAX / 2),
light_damage_max = minetest.LIGHT_MAX, -- Sunlight
suffocation = 0, -- Doesn't drown
floats = 0, -- Doesn't swim
fly_in = { "mobs_mime:glue", "mobs_mime:glue_flowing" },
fly_in = {
"mobs_mime:glue",
"mobs_mime:glue_flowing",
"default:water_source",
"default:water_flowing",
"default:river_water_source",
"default:river_water_flowing",
},
reach = 4, -- Same as player
docile_by_day = false, -- Attacks regardless of daytime or nighttime
attack_chance = 99, -- 1% chance it will attack
Expand All @@ -55,7 +62,7 @@ mobs:register_mob("mobs_mime:mime", {
visual = "cube",
visual_size = { x = 1, y = 1, z = 1 },
collisionbox = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
selectionbox = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
selectionbox = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, rotate = true },
textures = mobs_mime.get_chest_textures(),

on_rightclick = function(self, clicker)
Expand Down Expand Up @@ -86,7 +93,7 @@ mobs:register_mob("mobs_mime:mime", {
textures = mobs_mime.get_chest_textures(),
visual_size = { x = 1, y = 1, z = 1 },
collisionbox = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
selectionbox = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
selectionbox = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, rotate = true },
use_texture_alpha = false,
mesh = nil,
itemname = nil,
Expand Down Expand Up @@ -143,7 +150,7 @@ mobs:register_mob("mobs_mime:mime", {
local protected = attack_ent.protected
if protected == true or type(protected) == "number" and protected > 0 then
self.attack = nil
elseif attack ~= self.mimicking then
elseif attack ~= self.mimicking and not minetest.is_player(attack) then
mobs_mime.copy_nearby_mob(self)
end
end
Expand All @@ -170,7 +177,14 @@ mobs:register_mob("mobs_mime:mime", {
self.stepheight = 1.1
self.fear_height = 3
self.floats = 0
self.fly_in = { "mobs_mime:glue", "mobs_mime:glue_flowing" }
self.fly_in = {
"mobs_mime:glue",
"mobs_mime:glue_flowing",
"default:water_source",
"default:water_flowing",
"default:river_water_source",
"default:river_water_flowing",
}
end
end,
})
53 changes: 28 additions & 25 deletions core/procedures.lua
Expand Up @@ -57,27 +57,22 @@ local offsets = {

function mobs_mime.in_a_wall(self, pos)
local collisionbox = self.object:get_properties().collisionbox
for i, v in pairs(collisionbox) do
collisionbox[i] = v * 0.99
for i = 1, #collisionbox do
collisionbox[i] = collisionbox[i] * 0.90
end

local collisionbox_edges = {
vector.new(collisionbox[1], collisionbox[2], collisionbox[3]) + pos,
vector.new(collisionbox[1], collisionbox[2], collisionbox[6]) + pos,
vector.new(collisionbox[1], collisionbox[5], collisionbox[3]) + pos,
vector.new(collisionbox[1], collisionbox[5], collisionbox[6]) + pos,
vector.new(collisionbox[4], collisionbox[2], collisionbox[3]) + pos,
vector.new(collisionbox[4], collisionbox[2], collisionbox[6]) + pos,
vector.new(collisionbox[4], collisionbox[5], collisionbox[3]) + pos,
vector.new(collisionbox[4], collisionbox[5], collisionbox[6]) + pos,
}

for _, edge in ipairs(collisionbox_edges) do
local node = minetest.get_node(vector.round(edge))
local def = minetest.registered_nodes[node.name]

if (not def) or (def.drawtype == "normal" and def.walkable) then
return true
for i = 1, 4, 3 do
for j = 2, 5, 3 do
for k = 3, 6, 3 do
local edge = vector.new(collisionbox[i], collisionbox[j], collisionbox[k])
local node_pos = vector.round(edge + pos)
local node = minetest.get_node(node_pos)
local def = minetest.registered_nodes[node.name]

if (not def) or (def.drawtype == "normal" and def.walkable) then
return true
end
end
end
end

Expand Down Expand Up @@ -122,6 +117,10 @@ function mobs_mime.copy_nearby_mob(self)
local cb = props.collisionbox
local valid_collisionbox = (cb[1] ~= cb[4]) and (cb[2] ~= cb[5]) and (cb[3] ~= cb[6])
if props.physical and props.pointable and props.visual == "mesh" and valid_collisionbox then
if self.mimicking == object then
return true
end

self.mimicking = object

self.object:set_properties({
Expand All @@ -134,10 +133,12 @@ function mobs_mime.copy_nearby_mob(self)
selectionbox = props.selectionbox,
})

-- some entities have so large collisionboxes that mimes can't escape with escape_a_wall()
-- avoid them from glitching too deep into the ground
pos.y = math.round(pos.y) - 0.5 - cb[2]
self.object:set_pos(pos)
if mobs_mime.in_a_wall(self, pos) then
-- some entities have so large collisionboxes that mimes can't escape with escape_a_wall()
-- avoid them from glitching too deep into the ground
pos.y = math.round(pos.y) - 0.5 - cb[2]
self.object:set_pos(pos)
end

self.walk_velocity = ent.walk_velocity
self.randomly_turn = ent.randomly_turn
Expand Down Expand Up @@ -184,7 +185,7 @@ mobs_mime.pr_SetTexture = function(self)
textures = mobs_mime.get_chest_textures(),
visual_size = { x = 1, y = 1, z = 1 },
collisionbox = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
selectionbox = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
selectionbox = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, rotate = true },
use_texture_alpha = false,
mesh = nil,
itemname = nil,
Expand Down Expand Up @@ -215,7 +216,7 @@ mobs_mime.pr_SetTexture = function(self)
textures = textures,
visual_size = { x = 1, y = 1, z = 1 },
collisionbox = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
selectionbox = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
selectionbox = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, rotate = true },
use_texture_alpha = use_texture_alpha,
mesh = nil,
itemname = nil,
Expand All @@ -231,6 +232,8 @@ mobs_mime.pr_SetTexture = function(self)
textures = node_def.tiles,
use_texture_alpha = use_texture_alpha,
mesh = node_def.mesh,
collisionbox = node_def.collision_box or { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
selectionbox = node_def.selection_box or { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, rotate = true },
visual_size = { x = scale, y = scale, z = scale },
itemname = nil,
})
Expand Down

0 comments on commit b69b413

Please sign in to comment.