From 4851a0b5e22a2a988962aa1173f0bc15aea42875 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Thu, 16 Sep 2021 21:31:32 +0200 Subject: [PATCH] Only gets vehicle exit world when it's actually used --- .../net/knarcraft/stargate/portal/Portal.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/knarcraft/stargate/portal/Portal.java b/src/main/java/net/knarcraft/stargate/portal/Portal.java index 1526d28..265846b 100644 --- a/src/main/java/net/knarcraft/stargate/portal/Portal.java +++ b/src/main/java/net/knarcraft/stargate/portal/Portal.java @@ -707,16 +707,16 @@ public class Portal { adjustRotation(exit, origin); List passengers = vehicle.getPassengers(); - World vehicleWorld = exit.getWorld(); - if (vehicleWorld == null) { - Stargate.log.warning(Stargate.getString("prefix") + "Unable to get the world to teleport the vehicle to"); - return; - } loadChunks(); if (!passengers.isEmpty()) { if (vehicle instanceof RideableMinecart || vehicle instanceof Boat) { + World vehicleWorld = exit.getWorld(); + if (vehicleWorld == null) { + Stargate.log.warning(Stargate.getString("prefix") + "Unable to get the world to teleport the vehicle to"); + return; + } putPassengersInNewVehicle(vehicle, passengers, vehicleWorld, exit, newVelocity); } else { teleportLivingVehicle(vehicle, exit, passengers); @@ -914,11 +914,19 @@ public class Portal { Chunk forwardChunk = fiveBlocksForward.getChunk(); //Load the chunks - if (!getWorld().isChunkLoaded(chunk)) { - chunk.load(); - } - if (!getWorld().isChunkLoaded(forwardChunk)) { - forwardChunk.load(); + loadOneChunk(chunk); + loadOneChunk(forwardChunk); + } + } + + /** + * Loads one chunk + * @param chunk

The chunk to load

+ */ + private void loadOneChunk(Chunk chunk) { + if (!getWorld().isChunkLoaded(chunk)) { + if (!chunk.load()) { + Stargate.debug("loadChunks", "Failed to load chunk " + chunk); } } }