Improves pre-teleport chunk loading

This commit is contained in:
Kristian Knarvik 2021-09-12 06:18:20 +02:00
parent 319849fd96
commit c35378cfe0

View File

@ -904,12 +904,22 @@ public class Portal {
* Loads the chunks at the portal's corners * Loads the chunks at the portal's corners
*/ */
public void loadChunks() { public void loadChunks() {
//TODO: Improve this in the case where the portal sits between two chunks
for (RelativeBlockVector vector : gate.getLayout().getCorners()) { for (RelativeBlockVector vector : gate.getLayout().getCorners()) {
Chunk chunk = getBlockAt(vector).getChunk(); Chunk chunk = getBlockAt(vector).getChunk();
//Get the chunk in front of the gate corner
Location cornerLocation = getBlockAt(vector).getLocation();
int blockOffset = this.isBackwards() ? -5 : 5;
Location fiveBlocksForward = DirectionHelper.adjustLocation(cornerLocation, 0, 0, blockOffset, modX, modZ);
Chunk forwardChunk = fiveBlocksForward.getChunk();
//Load the chunks
if (!getWorld().isChunkLoaded(chunk)) { if (!getWorld().isChunkLoaded(chunk)) {
chunk.load(); chunk.load();
} }
if (!getWorld().isChunkLoaded(forwardChunk)) {
forwardChunk.load();
}
} }
} }