mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Change setInstance
This commit is contained in:
parent
b9679bc1ac
commit
1ead7c923a
@ -845,8 +845,9 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
|
|||||||
* @param instance the new instance of the entity
|
* @param instance the new instance of the entity
|
||||||
* @param spawnPosition the spawn position for the entity.
|
* @param spawnPosition the spawn position for the entity.
|
||||||
* @throws IllegalStateException if {@code instance} has not been registered in {@link InstanceManager}
|
* @throws IllegalStateException if {@code instance} has not been registered in {@link InstanceManager}
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public void setInstance(@NotNull Instance instance, @NotNull Pos spawnPosition) {
|
public CompletableFuture<Void> setInstance(@NotNull Instance instance, @NotNull Pos spawnPosition) {
|
||||||
Check.stateCondition(!instance.isRegistered(),
|
Check.stateCondition(!instance.isRegistered(),
|
||||||
"Instances need to be registered, please use InstanceManager#registerInstance or InstanceManager#registerSharedInstance");
|
"Instances need to be registered, please use InstanceManager#registerInstance or InstanceManager#registerSharedInstance");
|
||||||
if (this.instance != null) {
|
if (this.instance != null) {
|
||||||
@ -859,10 +860,11 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
|
|||||||
instance.UNSAFE_addEntity(this);
|
instance.UNSAFE_addEntity(this);
|
||||||
spawn();
|
spawn();
|
||||||
EventDispatcher.call(new EntitySpawnEvent(this, instance));
|
EventDispatcher.call(new EntitySpawnEvent(this, instance));
|
||||||
|
return CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInstance(@NotNull Instance instance, @NotNull Point spawnPosition) {
|
public CompletableFuture<Void> setInstance(@NotNull Instance instance, @NotNull Point spawnPosition) {
|
||||||
setInstance(instance, Pos.fromPoint(spawnPosition));
|
return setInstance(instance, Pos.fromPoint(spawnPosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,6 +18,7 @@ import java.time.Duration;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
public class EntityCreature extends LivingEntity implements NavigableEntity, EntityAI {
|
public class EntityCreature extends LivingEntity implements NavigableEntity, EntityAI {
|
||||||
@ -55,10 +56,10 @@ public class EntityCreature extends LivingEntity implements NavigableEntity, Ent
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInstance(@NotNull Instance instance, @NotNull Pos spawnPosition) {
|
public CompletableFuture<Void> setInstance(@NotNull Instance instance, @NotNull Pos spawnPosition) {
|
||||||
this.navigator.setPathFinder(new HydrazinePathFinder(navigator.getPathingEntity(), instance.getInstanceSpace()));
|
this.navigator.setPathFinder(new HydrazinePathFinder(navigator.getPathingEntity(), instance.getInstanceSpace()));
|
||||||
|
|
||||||
super.setInstance(instance, spawnPosition);
|
return super.setInstance(instance, spawnPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -86,6 +86,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@ -518,12 +519,12 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
* <p>
|
* <p>
|
||||||
* Be aware that because chunk operations are expensive,
|
* Be aware that because chunk operations are expensive,
|
||||||
* it is possible for this method to be non-blocking when retrieving chunks is required.
|
* it is possible for this method to be non-blocking when retrieving chunks is required.
|
||||||
*
|
* @param instance the new player instance
|
||||||
* @param instance the new player instance
|
|
||||||
* @param spawnPosition the new position of the player
|
* @param spawnPosition the new position of the player
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setInstance(@NotNull Instance instance, @NotNull Pos spawnPosition) {
|
public CompletableFuture<Void> setInstance(@NotNull Instance instance, @NotNull Pos spawnPosition) {
|
||||||
Check.argCondition(this.instance == instance, "Instance should be different than the current one");
|
Check.argCondition(this.instance == instance, "Instance should be different than the current one");
|
||||||
// true if the chunks need to be sent to the client, can be false if the instances share the same chunks (eg SharedInstance)
|
// true if the chunks need to be sent to the client, can be false if the instances share the same chunks (eg SharedInstance)
|
||||||
final boolean needWorldRefresh = !InstanceUtils.areLinked(this.instance, instance) ||
|
final boolean needWorldRefresh = !InstanceUtils.areLinked(this.instance, instance) ||
|
||||||
@ -543,14 +544,13 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
// Only load the spawning chunk to speed up login, remaining chunks are loaded in #spawnPlayer
|
// Only load the spawning chunk to speed up login, remaining chunks are loaded in #spawnPlayer
|
||||||
final long[] visibleChunks = ChunkUtils.getChunksInRange(spawnPosition, 0);
|
final long[] visibleChunks = ChunkUtils.getChunksInRange(spawnPosition, 0);
|
||||||
|
|
||||||
final ChunkCallback endCallback =
|
return ChunkUtils.optionalLoadAll(instance, visibleChunks, null)
|
||||||
chunk -> spawnPlayer(instance, spawnPosition, firstSpawn, dimensionChange, true);
|
.thenAccept(chunk -> spawnPlayer(instance, spawnPosition, firstSpawn, dimensionChange, true));
|
||||||
|
|
||||||
ChunkUtils.optionalLoadAll(instance, visibleChunks, null).thenAccept(endCallback);
|
|
||||||
} else {
|
} else {
|
||||||
// The player already has the good version of all the chunks.
|
// The player already has the good version of all the chunks.
|
||||||
// We just need to refresh his entity viewing list and add him to the instance
|
// We just need to refresh his entity viewing list and add him to the instance
|
||||||
spawnPlayer(instance, spawnPosition, false, false, false);
|
spawnPlayer(instance, spawnPosition, false, false, false);
|
||||||
|
return CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user