Portal entries of non-existent portals are not removed if entities keep using teleporting
The bug
Portal entries for portals which were destroyed remain in the map storing a portal position per chunk if entities keep teleporting to that chunk and therefor the entry is looked up.
A lookup entry is only removed if it was not used for 300 ticks (and the world time % 100 == 0). This means the teleporting entities might end up in a lava lake or fall from the sky on in the other dimension if they are searching for a portal in the respective chunk within this cooldown and additionally reset the cooldown.
Expected behavior
Portals being broken are directly removed from the lookup.
How to reproduce
- Create a Nether portal in the spawn chunks of the Overworld, or make somehow sure that the area remains loaded when you enter the portal.
- Place a dropper with a redstone clock dropping items into the the portal.
- Enter the Nether and break the exit portal, either by breaking the obsidian or breaking the portal blocks.
→ The items will continue to spawn at the position of the old portal.
Code analysis
Based on 1.11.2 decompiled using MCP 9.35 rc1
Only the method net.minecraft.world.Teleporter.removeStalePortalLocations(long) is removing portal entries once they have not been used for 300 ticks and the world time % 100 == 0. Instead the method net.minecraft.world.Teleporter.placeInExistingPortal(Entity, float) could additionally test if there is still a portal at the position the entry defines. If not it should search for a nearby portal.