Improves obsidian platform generation (#2246)

The obsidian platform was not generating constantly in the same spot. It was moving depending on the entrance point (from the sides).
This code changes it, as it will move through relative blocks. 
Also, this change will sync portal and platform center points, which was not done previously. 

Fixes #2239
This commit is contained in:
BONNe 2023-12-24 06:19:45 +02:00 committed by GitHub
parent b260cf1f4f
commit 96499f3ad6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 4 deletions

View File

@ -19,6 +19,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
@ -308,9 +309,20 @@ public abstract class AbstractTeleportListener
}
}
// Find the maximum x and z corner
for (; (i < x + 5) && fromWorld.getBlockAt(i, k, z).getType().equals(Material.END_PORTAL); i++) ;
for (; (j < z + 5) && fromWorld.getBlockAt(x, k, j).getType().equals(Material.END_PORTAL); j++) ;
// Find the maximum x and z corner using relative block search.
Block portalBlock = fromWorld.getBlockAt(i, k, j);
while (portalBlock.getRelative(1, 0, 0).getType() == Material.END_PORTAL)
{
portalBlock = portalBlock.getRelative(1, 0, 0);
i++;
}
while (portalBlock.getRelative(0, 0, 1).getType() == Material.END_PORTAL)
{
portalBlock = portalBlock.getRelative(0, 0, 1);
j++;
}
// Mojang end platform generation is:
// AIR
@ -318,7 +330,7 @@ public abstract class AbstractTeleportListener
// OBSIDIAN
// and player is placed on second air block above obsidian.
// If Y coordinate is below 2, then obsidian platform is not generated and player falls in void.
return new Location(toWorld, i, Math.min(toWorld.getMaxHeight() - 2, Math.max(toWorld.getMinHeight() + 2, k)), j);
return new Location(toWorld, i - 0.5, Math.min(toWorld.getMaxHeight() - 2, Math.max(toWorld.getMinHeight() + 2, k)), j - 0.5);
}