CodeMouse92 / no-monster-minecraft

A data pack for Minecrafters who like playing without monsters.
BSD 3-Clause "New" or "Revised" License
15 stars 4 forks source link

Preventing mob spawn in The Nether causes lag spikes with a subsequent crash #6

Closed cafuneandchill closed 2 years ago

cafuneandchill commented 3 years ago

Installed datapack version: v16.2.1

Minecraft version: 1.16.5

latest.log

crash-2021-05-31_14.00.58-server.txt

Preventing mob spawn in Nether via teleporting them to ~ -100 ~, apparently, causes spawning of duplicate entities, which, in turn, causes debug message spam, as well as high lag spikes.

embeddedt commented 3 years ago

My educated guess is that there are no spawn chunks in the nether, so they don’t despawn like in the overworld.

On Mon, May 31, 2021 at 2:46 PM cafuneandchill @.***> wrote:

Installed datapack version: v16.2.1

Minecraft version: 1.16.5

latest.log https://github.com/CodeMouse92/no-monster-minecraft/files/6571822/latest.log

crash-2021-05-31_14.00.58-server.txt https://github.com/CodeMouse92/no-monster-minecraft/files/6571828/crash-2021-05-31_14.00.58-server.txt

Preventing mob spawn in Nether via teleporting them to ~ -100 ~, apparently, causes spawning of duplicate entities, which, in turn, causes debug message spam, as well as high lag spikes.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/CodeMouse92/no-monster-minecraft/issues/6, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKHTVACKQ5YA22GXEGCYXUTTQPKP7ANCNFSM453KFMVQ .

cafuneandchill commented 3 years ago

I wonder if there's any other way to despawn them along with their loot, then. I've forked the datapack and tried to make it so that the Nether mobs would be teleported to a dummy void dimension, where they would, hopefully, despawn. Unfortunately, that didn't solve the lag spike problem.

One thing I forgot to mention is that, visually, the Nether mobs don't even get teleported, for some reason. I've tried replacing

tp @e[type=HOSTILE_MOB] ~ -100 ~

with

execute as @e[type=HOSTILE_MOB] in minecraft:the_nether run tp ~ -100 ~

which mitigated the problem to some extent.

embeddedt commented 3 years ago

I wonder if it's one of your Forge mods causing it? I've just made a fresh world using the CaffeineMC trifecta on Fabric and I don't see the same issue there. Will try with vanilla later.

EDIT: I get 3ms ticks in vanilla, which is the same as when I run without the datapack, so I don't seem to able to reproduce this here. My machine is relatively old and not powerful by Minecraft standards, so I wonder if it's some sort of vanilla concurrency issue which I'm not able to replicate.

embeddedt commented 3 years ago

I'm now back to Fabric and after leaving the world open for several minutes, the tick time has reached 70ms. Something is definitely up.

Part of it might just be down to the way this method for inhibiting mob spawns works. Since the mob cap is never reached, it forces the spawning algorithm to run overtime, which causes unavoidable lag.

EDIT: This log looks interesting; I get it when saving the world and reopening it:

Log ``` [19:07:19] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_4760['Hoglin'/15382, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:19] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_4760['Hoglin'/15383, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:19] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_4760['Hoglin'/15384, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:19] [main/INFO]: Preparing spawn area: 87% [19:07:19] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_4760['Hoglin'/15387, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:19] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15391, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:19] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1545['Blaze'/15393, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:19] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1590['Zombified Piglin'/15395, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:19] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15397, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:19] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15398, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:19] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15399, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1590['Zombified Piglin'/15401, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1590['Zombified Piglin'/15402, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_4760['Hoglin'/15403, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_4836['Piglin'/15404, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1590['Zombified Piglin'/15405, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1590['Zombified Piglin'/15406, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_4760['Hoglin'/15407, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_4836['Piglin'/15408, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15409, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1590['Zombified Piglin'/15410, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1590['Zombified Piglin'/15411, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1590['Zombified Piglin'/15412, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15413, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15414, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1590['Zombified Piglin'/15415, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1590['Zombified Piglin'/15416, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_4836['Piglin'/15417, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_4836['Piglin'/15418, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_4836['Piglin'/15419, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_4836['Piglin'/15420, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15421, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15422, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15423, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15424, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15425, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15426, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15427, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] [19:07:20] [Server thread/WARN]: Wrong location! (16, -3) should be (15, -4), class_1613['Skeleton'/15428, l='ServerLevel[datapacktest]', x=256.00, y=-100.00, z=-48.00] ```
cafuneandchill commented 3 years ago

I applied this technique to other functions for The Nether and The End mobs, and the lag spikes kinda died down. Upon entering The Nether via a portal the initial tick time is around 30 ms. After that it falls down to around 15 ms. Visually, mobs do get teleported fine.

However, after some time it starts to lag again, which causes Minecraft to freeze completely.

Crash report: crash-2021-06-01_09.51.15-server.txt

Latest game log: latest.log

Debug screen state after some time in The Nether: 2021-06-01_09 49 15

Debug screen after some more time in The Nether (**at this point the game had already frozen and crashed):** Screenshot_2021-06-01_09-53-04

As for your own observations, I'm not entirely sure what to make of them yet.

I've forked the repo and committed my edits there, so you can try them out for yourself.

embeddedt commented 3 years ago

One issue I see is that you are running on a really small Java heap for 1.16 standards (1 GB). I usually use 2 GB, especially for modded. That might be part of the issue, although it's also possible that the larger heap just delays the problem.

CodeMouse92 commented 3 years ago

@cafuneandchill I'd definitely embrace a PR for that command fix, even intiially! (I will need to test if it sucks Zoglins and ZPs out of overworld when they show up there, though.) Good catch in any case.

But even merging that, I'll be curious to leave this open and help figure out what's going on.


@embeddedt I've seen that before too on my own worlds, although it didn't seem to cause lag. I suspect it has to do with the world not getting saved quite right given the mob location update. It appears to be a very old Minecraft bug: https://bugs.mojang.com/browse/MC-2545

I suppose one way of mitigating that might be to kill the entity immediately after teleporting it, instead of waiting for void damage to do the deed.

embeddedt commented 3 years ago

Two more thoughts:

CodeMouse92 commented 3 years ago

I'd considered the first idea, but discarded it for the exact reason you described.

OptiFine might be contributing, but we'll need to test.

I think we're going to need to implement three changes:

  1. Nether and End removes entities within its own dimension. (There has to be a way to target only entities in the given dimension.)
  2. Kill each entity immediately after teleport.

Somehow I suspect this is going to be more of a trick than it first appears. But hey, if it was easy, someone would have already done it!

cafuneandchill commented 3 years ago

I've figured out a fix that doesn't depend on tp / teleport functionality. The idea is that the DeathLootTable tag of the mobs in question is emptied and then the mobs get killed via kill:

execute as @e[type=MOB_TYPE] run data modify entity @s DeathLootTable set value empty
kill @e[type=MOB_TYPE]

I've already made a commit on a separate branch in my fork. I'll do some merging there and, hopefully, do a PR to your repo.

EDIT: There may be a possibility that some mobs may still drop stuff like helmets and swords (monsters wearing armor, for example). However, the chances of it actually dropping are negligibly low even on pure vanilla, so I don't think it should cause any issue.

embeddedt commented 3 years ago

There may be a possibility that some mobs may still drop stuff like helmets and swords (monsters wearing armor, for example). However, the chances of it actually dropping are negligibly low even on pure vanilla, so I don't think it should cause any issue.

Can that be worked around by setting their inventory to be empty before running /kill?

cafuneandchill commented 3 years ago

There may be a possibility that some mobs may still drop stuff like helmets and swords (monsters wearing armor, for example). However, the chances of it actually dropping are negligibly low even on pure vanilla, so I don't think it should cause any issue.

Can that be worked around by setting their inventory to be empty before running /kill?

Technically, there are other mob NBT tags that define what the mob is currently holding/wearing, so I think it's possible to empty those as well.

CodeMouse92 commented 2 years ago

Thanks so much for everything you both did on this, @cafuneandchill and @embeddedt! I've reworked and merged the changes into main, and co-credited you both.