Skip to content

Commit

Permalink
Improves obsidian platform generation (#2246)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BONNe authored Dec 24, 2023
1 parent b260cf1 commit 96499f3
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -308,17 +309,28 @@ protected Location calculateLocation(Location fromLocation,
}
}

// 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
// AIR
// 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);
}


Expand Down

0 comments on commit 96499f3

Please sign in to comment.