use of org.spongepowered.api.world.Dimension in project SpongeCommon by SpongePowered.
the class EntityUtil method getPlayerRespawnLocation.
// Internal to MixinPlayerList. has side effects
public static Location<World> getPlayerRespawnLocation(EntityPlayerMP playerIn, @Nullable WorldServer targetWorld) {
final Location<World> location = ((World) playerIn.world).getSpawnLocation();
tempIsBedSpawn = false;
if (targetWorld == null) {
// Target world doesn't exist? Use global
return location;
}
final Dimension targetDimension = (Dimension) targetWorld.provider;
int targetDimensionId = ((IMixinWorldServer) targetWorld).getDimensionId();
// that world. (Usually overworld unless a mod says otherwise).
if (!targetDimension.allowsPlayerRespawns()) {
targetDimensionId = SpongeImplHooks.getRespawnDimension((WorldProvider) targetDimension, playerIn);
targetWorld = targetWorld.getMinecraftServer().getWorld(targetDimensionId);
}
Vector3d targetSpawnVec = VecHelper.toVector3d(targetWorld.getSpawnPoint());
BlockPos bedPos = SpongeImplHooks.getBedLocation(playerIn, targetDimensionId);
if (bedPos != null) {
// Player has a bed
boolean forceBedSpawn = SpongeImplHooks.isSpawnForced(playerIn, targetDimensionId);
BlockPos bedSpawnLoc = EntityPlayer.getBedSpawnLocation(targetWorld, bedPos, forceBedSpawn);
if (bedSpawnLoc != null) {
// The bed exists and is not obstructed
tempIsBedSpawn = true;
targetSpawnVec = new Vector3d(bedSpawnLoc.getX() + 0.5D, bedSpawnLoc.getY() + 0.1D, bedSpawnLoc.getZ() + 0.5D);
} else {
// Bed invalid
playerIn.connection.sendPacket(new SPacketChangeGameState(0, 0.0F));
// Vanilla behaviour - Delete the known bed location if invalid
// null = remove location
bedPos = null;
}
// Set the new bed location for the new dimension
// Temporarily for setSpawnPoint
int prevDim = playerIn.dimension;
playerIn.dimension = targetDimensionId;
playerIn.setSpawnPoint(bedPos, forceBedSpawn);
playerIn.dimension = prevDim;
}
return new Location<>((World) targetWorld, targetSpawnVec);
}
Aggregations