Search in sources :

Example 1 with DimensionTypeBridge

use of io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge in project Arclight by IzzelAliz.

the class BukkitRegistry method registerEnvironments.

public static void registerEnvironments() {
    int i = World.Environment.values().length;
    List<World.Environment> newTypes = new ArrayList<>();
    for (DimensionType dimensionType : DimensionManager.getRegistry()) {
        DimensionType actual = ((DimensionTypeBridge) dimensionType).bridge$getType();
        World.Environment environment = World.Environment.getEnvironment(actual.getId());
        if (environment == null) {
            String name = ResourceLocationUtil.standardize(actual.getRegistryName());
            environment = EnumHelper.makeEnum(World.Environment.class, name, i++, ENV_CTOR, ImmutableList.of(actual.getId()));
            newTypes.add(environment);
            ENVIRONMENT_MAP.put(actual.getId(), environment);
            ArclightMod.LOGGER.debug("Registered {} as environment {}", actual.getRegistryName(), environment);
        }
    }
    EnumHelper.addEnums(World.Environment.class, newTypes);
    ArclightMod.LOGGER.info("registry.environment", newTypes.size());
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) DimensionTypeBridge(io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge) ArrayList(java.util.ArrayList) World(org.bukkit.World)

Example 2 with DimensionTypeBridge

use of io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge in project Arclight by IzzelAliz.

the class ServerPlayerEntityMixin_1_14 method changeDimension.

/**
 * @author IzzelAliz
 * @reason
 */
@Nullable
@Overwrite
public Entity changeDimension(DimensionType dimensionmanager) {
    PlayerTeleportEvent.TeleportCause cause = bridge$getTeleportCause().orElse(PlayerTeleportEvent.TeleportCause.UNKNOWN);
    if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension((ServerPlayerEntity) (Object) this, dimensionmanager))
        return null;
    if (this.isSleeping()) {
        return (ServerPlayerEntity) (Object) this;
    }
    DimensionType dimensionmanager2 = this.dimension;
    if (((DimensionTypeBridge) dimensionmanager2).bridge$getType() == DimensionType.THE_END && ((DimensionTypeBridge) dimensionmanager).bridge$getType() == DimensionType.OVERWORLD) {
        this.invulnerableDimensionChange = true;
        this.detach();
        this.func_71121_q().removePlayer((ServerPlayerEntity) (Object) this, true);
        if (!this.queuedEndExit) {
            this.queuedEndExit = true;
            this.connection.sendPacket(new SChangeGameStatePacket(4, this.seenCredits ? 0.0f : 1.0f));
            this.seenCredits = true;
        }
        return (ServerPlayerEntity) (Object) this;
    }
    ServerWorld worldserver = this.server.func_71218_a(dimensionmanager2);
    ServerWorld worldserver2 = this.server.func_71218_a(dimensionmanager);
    WorldInfo worlddata = this.world.getWorldInfo();
    double d0 = this.posX;
    double d2 = this.posY;
    double d3 = this.posZ;
    float f = this.rotationPitch;
    float f2 = this.rotationYaw;
    double d4 = 8.0;
    float f3 = f2;
    worldserver.getProfiler().startSection("moving");
    if (worldserver2 != null) {
        if (dimensionmanager2 == DimensionType.OVERWORLD && dimensionmanager == DimensionType.THE_NETHER) {
            this.enteredNetherPosition = new Vec3d(this.posX, this.posY, this.posZ);
            d0 /= 8.0;
            d3 /= 8.0;
        } else if (dimensionmanager2 == DimensionType.THE_NETHER && dimensionmanager == DimensionType.OVERWORLD) {
            d0 *= 8.0;
            d3 *= 8.0;
        } else if (dimensionmanager2 == DimensionType.OVERWORLD && dimensionmanager == DimensionType.THE_END) {
            BlockPos blockposition = worldserver2.getSpawnCoordinate();
            d0 = blockposition.getX();
            d2 = blockposition.getY();
            d3 = blockposition.getZ();
            f2 = 90.0f;
            f = 0.0f;
        }
    }
    Location enter = this.bridge$getBukkitEntity().getLocation();
    Location exit = (worldserver2 == null) ? null : new Location(((WorldBridge) worldserver2).bridge$getWorld(), d0, d2, d3, f2, f);
    PlayerPortalEvent event = new PlayerPortalEvent((Player) this.bridge$getBukkitEntity(), enter, exit, cause);
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled() || event.getTo() == null) {
        return null;
    }
    exit = event.getTo();
    if (exit == null) {
        return null;
    }
    PlayerTeleportEvent tpEvent = new PlayerTeleportEvent((Player) this.bridge$getBukkitEntity(), enter, exit, cause);
    Bukkit.getServer().getPluginManager().callEvent(tpEvent);
    if (tpEvent.isCancelled() || tpEvent.getTo() == null) {
        return null;
    }
    exit = tpEvent.getTo();
    if (exit == null) {
        return null;
    }
    worldserver2 = ((CraftWorld) exit.getWorld()).getHandle();
    d0 = exit.getX();
    d2 = exit.getY();
    d3 = exit.getZ();
    f2 = exit.getYaw();
    f = exit.getPitch();
    this.invulnerableDimensionChange = true;
    dimensionmanager = worldserver2.getDimension().getType();
    this.dimension = dimensionmanager;
    net.minecraftforge.fml.network.NetworkHooks.sendDimensionDataPacket(this.connection.netManager, (ServerPlayerEntity) (Object) this);
    this.connection.sendPacket(new SRespawnPacket(worldserver2.dimension.getType(), this.world.getWorldInfo().getGenerator(), this.interactionManager.getGameType()));
    this.connection.sendPacket(new SServerDifficultyPacket(this.world.getDifficulty(), this.world.getWorldInfo().isDifficultyLocked()));
    PlayerList playerlist = this.server.getPlayerList();
    playerlist.updatePermissionLevel((ServerPlayerEntity) (Object) this);
    worldserver.removePlayer((ServerPlayerEntity) (Object) this, true);
    this.removed = false;
    this.setLocationAndAngles(d0, d2, d3, f2, f);
    worldserver.getProfiler().endSection();
    worldserver.getProfiler().startSection("placing");
    double d5 = Math.min(-2.9999872E7, worldserver2.getWorldBorder().minX() + 16.0);
    double d6 = Math.min(-2.9999872E7, worldserver2.getWorldBorder().minZ() + 16.0);
    double d7 = Math.min(2.9999872E7, worldserver2.getWorldBorder().maxX() - 16.0);
    double d8 = Math.min(2.9999872E7, worldserver2.getWorldBorder().maxZ() - 16.0);
    d0 = MathHelper.clamp(d0, d5, d7);
    d3 = MathHelper.clamp(d3, d6, d8);
    this.setLocationAndAngles(d0, d2, d3, f2, f);
    if (((DimensionTypeBridge) dimensionmanager).bridge$getType() == DimensionType.THE_END) {
        int i = MathHelper.floor(this.posX);
        int j = MathHelper.floor(this.posY) - 1;
        int k = MathHelper.floor(this.posZ);
        boolean flag = true;
        boolean flag2 = false;
        BlockStateListPopulator blockList = new BlockStateListPopulator(worldserver2);
        for (int l = -2; l <= 2; ++l) {
            for (int i2 = -2; i2 <= 2; ++i2) {
                for (int j2 = -1; j2 < 3; ++j2) {
                    int k2 = i + i2 * 1 + l * 0;
                    int l2 = j + j2;
                    int i3 = k + i2 * 0 - l * 1;
                    boolean flag3 = j2 < 0;
                    blockList.setBlockState(new BlockPos(k2, l2, i3), flag3 ? Blocks.OBSIDIAN.getDefaultState() : Blocks.AIR.getDefaultState(), 3);
                }
            }
        }
        org.bukkit.World bworld = ((WorldBridge) worldserver2).bridge$getWorld();
        PortalCreateEvent portalEvent = new PortalCreateEvent((List) blockList.getList(), bworld, this.bridge$getBukkitEntity(), PortalCreateEvent.CreateReason.END_PLATFORM);
        Bukkit.getPluginManager().callEvent(portalEvent);
        if (!portalEvent.isCancelled()) {
            blockList.updateList();
        }
        this.setLocationAndAngles(i, j, k, f2, 0.0f);
        this.setMotion(Vec3d.ZERO);
    } else if (!worldserver2.getDefaultTeleporter().placeInPortal((ServerPlayerEntity) (Object) this, f3)) {
        worldserver2.getDefaultTeleporter().makePortal((ServerPlayerEntity) (Object) this);
        worldserver2.getDefaultTeleporter().placeInPortal((ServerPlayerEntity) (Object) this, f3);
    }
    worldserver.getProfiler().endSection();
    this.setWorld(worldserver2);
    worldserver2.func_217447_b((ServerPlayerEntity) (Object) this);
    this.func_213846_b(worldserver);
    this.connection.setPlayerLocation(this.posX, this.posY, this.posZ, f2, f);
    this.interactionManager.func_73080_a(worldserver2);
    this.connection.sendPacket(new SPlayerAbilitiesPacket(this.abilities));
    playerlist.func_72354_b((ServerPlayerEntity) (Object) this, worldserver2);
    playerlist.sendInventory((ServerPlayerEntity) (Object) this);
    for (EffectInstance mobeffect : this.getActivePotionEffects()) {
        this.connection.sendPacket(new SPlayEntityEffectPacket(this.getEntityId(), mobeffect));
    }
    this.connection.sendPacket(new SPlaySoundEventPacket(1032, BlockPos.ZERO, 0, false));
    this.lastExperience = -1;
    this.lastHealth = -1.0f;
    this.lastFoodLevel = -1;
    PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent((Player) this.bridge$getBukkitEntity(), ((WorldBridge) worldserver).bridge$getWorld());
    Bukkit.getPluginManager().callEvent(changeEvent);
    net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerChangedDimensionEvent((ServerPlayerEntity) (Object) this, dimensionmanager2, dimensionmanager);
    return (ServerPlayerEntity) (Object) this;
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) DimensionTypeBridge(io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge) PlayerList(net.minecraft.server.management.PlayerList) SPlayEntityEffectPacket(net.minecraft.network.play.server.SPlayEntityEffectPacket) PlayerPortalEvent(org.bukkit.event.player.PlayerPortalEvent) SPlaySoundEventPacket(net.minecraft.network.play.server.SPlaySoundEventPacket) SChangeGameStatePacket(net.minecraft.network.play.server.SChangeGameStatePacket) ServerWorld(net.minecraft.world.server.ServerWorld) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) SPlayerAbilitiesPacket(net.minecraft.network.play.server.SPlayerAbilitiesPacket) SRespawnPacket(net.minecraft.network.play.server.SRespawnPacket) WorldInfo(net.minecraft.world.storage.WorldInfo) BlockPos(net.minecraft.util.math.BlockPos) PortalCreateEvent(org.bukkit.event.world.PortalCreateEvent) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) BlockStateListPopulator(org.bukkit.craftbukkit.v.util.BlockStateListPopulator) Vec3d(net.minecraft.util.math.Vec3d) SServerDifficultyPacket(net.minecraft.network.play.server.SServerDifficultyPacket) PlayerChangedWorldEvent(org.bukkit.event.player.PlayerChangedWorldEvent) EffectInstance(net.minecraft.potion.EffectInstance) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite) Nullable(javax.annotation.Nullable)

Example 3 with DimensionTypeBridge

use of io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge in project Arclight by IzzelAliz.

the class MapDataMixin method arclight$customDimension.

@Redirect(method = "read", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/DimensionType;getById(I)Lnet/minecraft/world/dimension/DimensionType;"))
public DimensionType arclight$customDimension(int id, CompoundNBT nbt) {
    DimensionType type;
    long least = nbt.getLong("UUIDLeast");
    long most = nbt.getLong("UUIDMost");
    if (least != 0L && most != 0L) {
        this.uniqueId = new UUID(most, least);
        CraftWorld world = (CraftWorld) server.getWorld(this.uniqueId);
        // Check if the stored world details are correct.
        if (world == null) {
            type = DimensionType.getById(id);
            if (type == null) {
                /* All Maps which do not have their valid world loaded are set to a dimension which hopefully won't be reached.
                       This is to prevent them being corrupted with the wrong map data. */
                type = this.bridge$dimension(ArclightConstants.ARCLIGHT_DIMENSION, "", "", OverworldDimension::new, false);
                ((DimensionTypeBridge) type).bridge$setType(DimensionType.OVERWORLD);
            }
        } else {
            type = world.getHandle().dimension.getType();
        }
    } else {
        type = DimensionType.getById(id);
    }
    return type;
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) DimensionTypeBridge(io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge) UUID(java.util.UUID) CraftWorld(org.bukkit.craftbukkit.v.CraftWorld) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with DimensionTypeBridge

use of io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge in project Arclight by IzzelAliz.

the class PlayerListMixin method moveToWorld.

public ServerPlayerEntity moveToWorld(ServerPlayerEntity playerIn, DimensionType type, boolean flag, Location location, boolean avoidSuffocation) {
    if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(playerIn, type))
        return playerIn;
    playerIn.stopRiding();
    this.players.remove(playerIn);
    // this.playersByName.remove(playerIn.getScoreboardName().toLowerCase(Locale.ROOT));
    playerIn.getServerWorld().removePlayer(playerIn, true);
    BlockPos pos = playerIn.getBedLocation(type);
    boolean flag2 = playerIn.isSpawnForced(type);
    org.bukkit.World fromWorld = ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().getWorld();
    playerIn.queuedEndExit = false;
    playerIn.copyFrom(playerIn, flag);
    playerIn.setEntityId(playerIn.getEntityId());
    playerIn.setPrimaryHand(playerIn.getPrimaryHand());
    for (String s : playerIn.getTags()) {
        playerIn.addTag(s);
    }
    if (location == null) {
        boolean isBedSpawn = false;
        CraftWorld cworld = (CraftWorld) Bukkit.getServer().getWorld(((ServerPlayerEntityBridge) playerIn).bridge$getSpawnWorld());
        if (cworld != null && pos != null) {
            Optional<Vec3d> optional = PlayerEntity.checkBedValidRespawnPosition(cworld.getHandle(), pos, flag2);
            if (optional.isPresent()) {
                Vec3d vec3d = optional.get();
                isBedSpawn = true;
                location = new Location(cworld, vec3d.x, vec3d.y, vec3d.z);
            } else {
                this.bridge$setSpawnPoint(playerIn, null, true, playerIn.dimension, false);
                playerIn.connection.sendPacket(new SChangeGameStatePacket(0, 0.0f));
            }
        }
        if (location == null) {
            cworld = (CraftWorld) Bukkit.getServer().getWorlds().get(0);
            pos = ((ServerPlayerEntityBridge) playerIn).bridge$getSpawnPoint(cworld.getHandle());
            location = new Location(cworld, pos.getX() + 0.5f, pos.getY() + 0.1f, pos.getZ() + 0.5f);
        }
        Player respawnPlayer = this.cserver.getPlayer(playerIn);
        PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn);
        this.cserver.getPluginManager().callEvent(respawnEvent);
        if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
            return playerIn;
        }
        location = respawnEvent.getRespawnLocation();
        if (!flag) {
            ((ServerPlayerEntityBridge) playerIn).bridge$reset();
        }
    } else {
        location.setWorld(((WorldBridge) this.server.getWorld(type)).bridge$getWorld());
    }
    ServerWorld serverWorld = ((CraftWorld) location.getWorld()).getHandle();
    playerIn.setPositionAndRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    playerIn.connection.captureCurrentPosition();
    while (avoidSuffocation && !serverWorld.hasNoCollisions(playerIn) && playerIn.getPosY() < 256.0) {
        playerIn.setPosition(playerIn.getPosX(), playerIn.getPosY() + 1.0, playerIn.getPosZ());
    }
    if (fromWorld.getEnvironment() == ((WorldBridge) serverWorld).bridge$getWorld().getEnvironment()) {
        playerIn.connection.sendPacket(this.bridge$respawnPacket((serverWorld.dimension.getType().getId() >= 0) ? DimensionType.THE_NETHER : DimensionType.OVERWORLD, serverWorld.getWorldInfo().getSeed(), serverWorld.getWorldInfo().getGenerator(), playerIn.interactionManager.getGameType()));
    }
    WorldInfo worldInfo = serverWorld.getWorldInfo();
    net.minecraftforge.fml.network.NetworkHooks.sendDimensionDataPacket(playerIn.connection.netManager, playerIn);
    playerIn.connection.sendPacket(this.bridge$respawnPacket(((DimensionTypeBridge) serverWorld.dimension.getType()).bridge$getType(), serverWorld.getWorldInfo().getSeed(), serverWorld.getWorldInfo().getGenerator(), playerIn.interactionManager.getGameType()));
    playerIn.connection.sendPacket(new SUpdateViewDistancePacket(((ServerWorldBridge) serverWorld).bridge$spigotConfig().viewDistance));
    playerIn.setWorld(serverWorld);
    playerIn.interactionManager.setWorld(serverWorld);
    playerIn.revive();
    ((ServerPlayNetHandlerBridge) playerIn.connection).bridge$teleport(new Location(((WorldBridge) serverWorld).bridge$getWorld(), playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), playerIn.rotationYaw, playerIn.rotationPitch));
    playerIn.setSneaking(false);
    BlockPos pos1 = serverWorld.getSpawnPoint();
    playerIn.connection.sendPacket(new SSpawnPositionPacket(pos1));
    playerIn.connection.sendPacket(new SServerDifficultyPacket(worldInfo.getDifficulty(), worldInfo.isDifficultyLocked()));
    playerIn.connection.sendPacket(new SSetExperiencePacket(playerIn.experience, playerIn.experienceTotal, playerIn.experienceLevel));
    this.sendWorldInfo(playerIn, serverWorld);
    this.updatePermissionLevel(playerIn);
    if (!((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
        serverWorld.addRespawnedPlayer(playerIn);
        this.players.add(playerIn);
        // this.playersByName.put(entityplayer2.getScoreboardName().toLowerCase(Locale.ROOT), entityplayer2);
        this.uuidToPlayerMap.put(playerIn.getUniqueID(), playerIn);
    }
    playerIn.setHealth(playerIn.getHealth());
    this.sendInventory(playerIn);
    playerIn.sendPlayerAbilities();
    for (Object o1 : playerIn.getActivePotionEffects()) {
        EffectInstance mobEffect = (EffectInstance) o1;
        playerIn.connection.sendPacket(new SPlayEntityEffectPacket(playerIn.getEntityId(), mobEffect));
    }
    playerIn.func_213846_b(((CraftWorld) fromWorld).getHandle());
    if (fromWorld != location.getWorld()) {
        PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(), fromWorld);
        Bukkit.getPluginManager().callEvent(event);
    }
    if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
        this.writePlayerData(playerIn);
    }
    net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerRespawnEvent(playerIn, flag);
    return playerIn;
}
Also used : DimensionTypeBridge(io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge) ServerPlayNetHandlerBridge(io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) SPlayEntityEffectPacket(net.minecraft.network.play.server.SPlayEntityEffectPacket) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) SChangeGameStatePacket(net.minecraft.network.play.server.SChangeGameStatePacket) ServerWorld(net.minecraft.world.server.ServerWorld) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) ServerWorldBridge(io.izzel.arclight.common.bridge.world.server.ServerWorldBridge) WorldInfo(net.minecraft.world.storage.WorldInfo) BlockPos(net.minecraft.util.math.BlockPos) CraftWorld(org.bukkit.craftbukkit.v.CraftWorld) SSetExperiencePacket(net.minecraft.network.play.server.SSetExperiencePacket) Player(org.bukkit.entity.Player) SUpdateViewDistancePacket(net.minecraft.network.play.server.SUpdateViewDistancePacket) Vec3d(net.minecraft.util.math.Vec3d) SServerDifficultyPacket(net.minecraft.network.play.server.SServerDifficultyPacket) PlayerChangedWorldEvent(org.bukkit.event.player.PlayerChangedWorldEvent) SSpawnPositionPacket(net.minecraft.network.play.server.SSpawnPositionPacket) EffectInstance(net.minecraft.potion.EffectInstance) Location(org.bukkit.Location)

Example 5 with DimensionTypeBridge

use of io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge in project Arclight by IzzelAliz.

the class PlayerListMixin method recreatePlayerEntity.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public ServerPlayerEntity recreatePlayerEntity(ServerPlayerEntity playerIn, DimensionType dimension, boolean conqueredEnd) {
    Location location = arclight$loc;
    arclight$loc = null;
    boolean avoidSuffocation = arclight$suffo == null ? true : arclight$suffo;
    arclight$suffo = null;
    playerIn.stopRiding();
    org.bukkit.World fromWorld = ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().getWorld();
    ServerWorld world = server.getWorld(dimension);
    if (world == null)
        dimension = playerIn.getSpawnDimension();
    else if (!world.getDimension().canRespawnHere())
        dimension = world.getDimension().getRespawnDimension(playerIn);
    if (server.getWorld(dimension) == null)
        dimension = DimensionType.OVERWORLD;
    this.removePlayer(playerIn);
    // Forge: keep data until copyFrom called
    playerIn.getServerWorld().removePlayer(playerIn, true);
    BlockPos blockpos = playerIn.getBedLocation(dimension);
    boolean flag = playerIn.isSpawnForced(dimension);
    // playerIn.dimension = dimension;
    PlayerInteractionManager playerinteractionmanager;
    if (this.server.isDemo()) {
        playerinteractionmanager = new DemoPlayerInteractionManager(this.server.getWorld(playerIn.dimension));
    } else {
        playerinteractionmanager = new PlayerInteractionManager(this.server.getWorld(playerIn.dimension));
    }
    playerIn.queuedEndExit = false;
    if (location == null) {
        boolean isBedSpawn = false;
        CraftWorld cworld = (CraftWorld) Bukkit.getWorld(((PlayerEntityBridge) playerIn).bridge$getSpawnWorld());
        if (cworld != null && blockpos != null) {
            Optional<Vec3d> optional = PlayerEntity.checkBedValidRespawnPosition(cworld.getHandle(), blockpos, flag);
            if (optional.isPresent()) {
                Vec3d vec3d = optional.get();
                isBedSpawn = true;
                location = new Location(cworld, vec3d.x, vec3d.y, vec3d.z);
            } else {
                this.bridge$setSpawnPoint(playerIn, null, true, playerIn.dimension, false);
                playerIn.connection.sendPacket(new SChangeGameStatePacket(0, 0.0f));
            }
        }
        if (location == null) {
            cworld = (CraftWorld) Bukkit.getWorlds().get(0);
            blockpos = ((ServerPlayerEntityBridge) playerIn).bridge$getSpawnPoint(cworld.getHandle());
            location = new Location(cworld, blockpos.getX() + 0.5f, blockpos.getY() + 0.1f, blockpos.getZ() + 0.5f);
        }
        Player respawnPlayer = this.cserver.getPlayer(playerIn);
        PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn);
        this.cserver.getPluginManager().callEvent(respawnEvent);
        if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
            return playerIn;
        }
        location = respawnEvent.getRespawnLocation();
        if (location.getWorld() == null) {
            location.setWorld(((WorldBridge) this.server.getWorld(dimension)).bridge$getWorld());
        }
        dimension = ((CraftWorld) location.getWorld()).getHandle().dimension.getType();
        if (!flag) {
            ((ServerPlayerEntityBridge) playerIn).bridge$reset();
        }
    } else {
        location.setWorld(((WorldBridge) this.server.getWorld(dimension)).bridge$getWorld());
    }
    playerIn.dimension = dimension;
    ServerPlayerEntity serverplayerentity = new ServerPlayerEntity(this.server, this.server.getWorld(playerIn.dimension), playerIn.getGameProfile(), playerinteractionmanager);
    // Forward to new player instance
    ((InternalEntityBridge) playerIn).internal$getBukkitEntity().setHandle(serverplayerentity);
    ((EntityBridge) serverplayerentity).bridge$setBukkitEntity(((InternalEntityBridge) playerIn).internal$getBukkitEntity());
    if ((Object) serverplayerentity instanceof MobEntity) {
        ((MobEntity) (Object) serverplayerentity).clearLeashed(true, false);
    }
    serverplayerentity.connection = playerIn.connection;
    serverplayerentity.copyFrom(playerIn, conqueredEnd);
    // Forge: clone event had a chance to see old data, now discard it
    playerIn.remove(false);
    serverplayerentity.dimension = dimension;
    serverplayerentity.setEntityId(playerIn.getEntityId());
    serverplayerentity.setPrimaryHand(playerIn.getPrimaryHand());
    for (String s : playerIn.getTags()) {
        serverplayerentity.addTag(s);
    }
    ServerWorld serverworld = ((CraftWorld) location.getWorld()).getHandle();
    serverplayerentity.setPositionAndRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    serverplayerentity.connection.captureCurrentPosition();
    this.setPlayerGameTypeBasedOnOther(serverplayerentity, playerIn, serverworld);
    while (avoidSuffocation && !this.bridge$worldNoCollision(serverworld, serverplayerentity) && serverplayerentity.posY < 256.0D) {
        serverplayerentity.setPosition(serverplayerentity.posX, serverplayerentity.posY + 1.0D, serverplayerentity.posZ);
    }
    if (fromWorld.getEnvironment() == ((WorldBridge) serverworld).bridge$getWorld().getEnvironment()) {
        serverplayerentity.connection.sendPacket(this.bridge$respawnPacket((((DimensionTypeBridge) serverplayerentity.dimension).bridge$getType().getId() >= 0) ? DimensionType.THE_NETHER : DimensionType.OVERWORLD, serverworld.getWorldInfo().getSeed(), serverworld.getWorldInfo().getGenerator(), playerIn.interactionManager.getGameType()));
    }
    WorldInfo worldinfo = serverplayerentity.world.getWorldInfo();
    NetworkHooks.sendDimensionDataPacket(serverplayerentity.connection.netManager, serverplayerentity);
    serverplayerentity.connection.sendPacket(this.bridge$respawnPacket(((DimensionTypeBridge) serverplayerentity.dimension).bridge$getType(), worldinfo.getSeed(), worldinfo.getGenerator(), serverplayerentity.interactionManager.getGameType()));
    serverplayerentity.connection.sendPacket(new SUpdateViewDistancePacket(((WorldBridge) serverworld).bridge$spigotConfig().viewDistance));
    BlockPos blockpos1 = serverworld.getSpawnPoint();
    serverplayerentity.connection.setPlayerLocation(serverplayerentity.posX, serverplayerentity.posY, serverplayerentity.posZ, serverplayerentity.rotationYaw, serverplayerentity.rotationPitch);
    serverplayerentity.connection.sendPacket(new SSpawnPositionPacket(blockpos1));
    serverplayerentity.connection.sendPacket(new SServerDifficultyPacket(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
    serverplayerentity.connection.sendPacket(new SSetExperiencePacket(serverplayerentity.experience, serverplayerentity.experienceTotal, serverplayerentity.experienceLevel));
    this.sendWorldInfo(serverplayerentity, serverworld);
    this.updatePermissionLevel(serverplayerentity);
    if (!((ServerPlayNetHandlerBridge) serverplayerentity.connection).bridge$isDisconnected()) {
        serverworld.addRespawnedPlayer(serverplayerentity);
        this.addPlayer(serverplayerentity);
        this.uuidToPlayerMap.put(serverplayerentity.getUniqueID(), serverplayerentity);
    }
    serverplayerentity.addSelfToInternalCraftingInventory();
    serverplayerentity.setHealth(serverplayerentity.getHealth());
    this.sendInventory(serverplayerentity);
    serverplayerentity.sendPlayerAbilities();
    serverplayerentity.func_213846_b(((CraftWorld) fromWorld).getHandle());
    if (fromWorld != location.getWorld()) {
        PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(), fromWorld);
        Bukkit.getPluginManager().callEvent(event);
    }
    BasicEventHooks.firePlayerRespawnEvent(serverplayerentity, conqueredEnd);
    System.out.println("pos " + serverplayerentity.getBedLocation());
    return serverplayerentity;
}
Also used : DimensionTypeBridge(io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge) ServerPlayNetHandlerBridge(io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) SChangeGameStatePacket(net.minecraft.network.play.server.SChangeGameStatePacket) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) ServerWorld(net.minecraft.world.server.ServerWorld) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) ServerWorldBridge(io.izzel.arclight.common.bridge.world.server.ServerWorldBridge) WorldInfo(net.minecraft.world.storage.WorldInfo) BlockPos(net.minecraft.util.math.BlockPos) CraftWorld(org.bukkit.craftbukkit.v.CraftWorld) InternalEntityBridge(io.izzel.arclight.common.bridge.entity.InternalEntityBridge) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) SSetExperiencePacket(net.minecraft.network.play.server.SSetExperiencePacket) Player(org.bukkit.entity.Player) SUpdateViewDistancePacket(net.minecraft.network.play.server.SUpdateViewDistancePacket) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Vec3d(net.minecraft.util.math.Vec3d) SServerDifficultyPacket(net.minecraft.network.play.server.SServerDifficultyPacket) PlayerChangedWorldEvent(org.bukkit.event.player.PlayerChangedWorldEvent) PlayerInteractionManager(net.minecraft.server.management.PlayerInteractionManager) DemoPlayerInteractionManager(net.minecraft.server.management.DemoPlayerInteractionManager) DemoPlayerInteractionManager(net.minecraft.server.management.DemoPlayerInteractionManager) MobEntity(net.minecraft.entity.MobEntity) SSpawnPositionPacket(net.minecraft.network.play.server.SSpawnPositionPacket) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

DimensionTypeBridge (io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge)6 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)4 BlockPos (net.minecraft.util.math.BlockPos)4 DimensionType (net.minecraft.world.dimension.DimensionType)4 ServerWorld (net.minecraft.world.server.ServerWorld)4 SChangeGameStatePacket (net.minecraft.network.play.server.SChangeGameStatePacket)3 SServerDifficultyPacket (net.minecraft.network.play.server.SServerDifficultyPacket)3 Vec3d (net.minecraft.util.math.Vec3d)3 WorldInfo (net.minecraft.world.storage.WorldInfo)3 Location (org.bukkit.Location)3 CraftWorld (org.bukkit.craftbukkit.v.CraftWorld)3 PlayerChangedWorldEvent (org.bukkit.event.player.PlayerChangedWorldEvent)3 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)2 ServerPlayNetHandlerBridge (io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge)2 ServerWorldBridge (io.izzel.arclight.common.bridge.world.server.ServerWorldBridge)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 SPlayEntityEffectPacket (net.minecraft.network.play.server.SPlayEntityEffectPacket)2 SSetExperiencePacket (net.minecraft.network.play.server.SSetExperiencePacket)2 SSpawnPositionPacket (net.minecraft.network.play.server.SSpawnPositionPacket)2 SUpdateViewDistancePacket (net.minecraft.network.play.server.SUpdateViewDistancePacket)2