Search in sources :

Example 1 with ServerPlayNetHandlerBridge

use of io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge in project Arclight by IzzelAliz.

the class TeleportCommandMixin_1_15 method teleport.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
private static void teleport(CommandSource source, Entity entityIn, ServerWorld worldIn, double x, double y, double z, Set<SPlayerPositionLookPacket.Flags> relativeList, float yaw, float pitch, @Nullable TeleportCommand.Facing facing) {
    if (entityIn instanceof ServerPlayerEntity) {
        ChunkPos chunkpos = new ChunkPos(new BlockPos(x, y, z));
        worldIn.getChunkProvider().registerTicket(TicketType.POST_TELEPORT, chunkpos, 1, entityIn.getEntityId());
        entityIn.stopRiding();
        if (((ServerPlayerEntity) entityIn).isSleeping()) {
            ((ServerPlayerEntity) entityIn).stopSleepInBed(true, true);
        }
        ((ServerPlayNetHandlerBridge) ((ServerPlayerEntity) entityIn).connection).bridge$pushTeleportCause(PlayerTeleportEvent.TeleportCause.COMMAND);
        if (worldIn == entityIn.world) {
            ((ServerPlayerEntity) entityIn).connection.setPlayerLocation(x, y, z, yaw, pitch, relativeList);
        } else {
            ((ServerPlayerEntity) entityIn).teleport(worldIn, x, y, z, yaw, pitch);
        }
        entityIn.setRotationYawHead(yaw);
    } else {
        float f1 = MathHelper.wrapDegrees(yaw);
        float f = MathHelper.wrapDegrees(pitch);
        f = MathHelper.clamp(f, -90.0F, 90.0F);
        Location to = new Location(((ServerWorldBridge) worldIn).bridge$getWorld(), x, y, z, f1, f);
        EntityTeleportEvent event = new EntityTeleportEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), ((EntityBridge) entityIn).bridge$getBukkitEntity().getLocation(), to);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }
        to = event.getTo();
        x = to.getX();
        y = to.getY();
        z = to.getZ();
        f1 = to.getYaw();
        f = to.getPitch();
        worldIn = ((CraftWorld) to.getWorld()).getHandle();
        if (worldIn == entityIn.world) {
            entityIn.setLocationAndAngles(x, y, z, f1, f);
            entityIn.setRotationYawHead(f1);
        } else {
            entityIn.detach();
            entityIn.dimension = worldIn.dimension.getType();
            Entity entity = entityIn;
            entityIn = entityIn.getType().create(worldIn);
            if (entityIn == null) {
                return;
            }
            entityIn.copyDataFromOld(entity);
            entityIn.setLocationAndAngles(x, y, z, f1, f);
            entityIn.setRotationYawHead(f1);
            worldIn.addFromAnotherDimension(entityIn);
            entity.removed = true;
        }
    }
    if (facing != null) {
        facing.updateLook(source, entityIn);
    }
    if (!(entityIn instanceof LivingEntity) || !((LivingEntity) entityIn).isElytraFlying()) {
        entityIn.setMotion(entityIn.getMotion().mul(1.0D, 0.0D, 1.0D));
        entityIn.onGround = true;
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerPlayNetHandlerBridge(io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with ServerPlayNetHandlerBridge

use of io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge in project Arclight by IzzelAliz.

the class EndGatewayTileEntityMixin method arclight$portal.

// @formatter:on
@Inject(method = "teleportEntity", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;teleportKeepLoaded(DDD)V"))
public void arclight$portal(Entity entityIn, CallbackInfo ci) {
    if (entityIn instanceof ServerPlayerEntity) {
        CraftPlayer player = ((ServerPlayerEntityBridge) entityIn).bridge$getBukkitEntity();
        Location location = new Location(((WorldBridge) world).bridge$getWorld(), pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D);
        location.setPitch(player.getLocation().getPitch());
        location.setYaw(player.getLocation().getYaw());
        PlayerTeleportEvent event = new PlayerTeleportEvent(player, player.getLocation(), location, PlayerTeleportEvent.TeleportCause.END_GATEWAY);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            ci.cancel();
            return;
        }
        ((ServerPlayNetHandlerBridge) (((ServerPlayerEntity) entityIn)).connection).bridge$teleport(event.getTo());
        // CraftBukkit - call at end of method
        this.isCoolingDown();
        ci.cancel();
    }
}
Also used : ServerPlayNetHandlerBridge(io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CraftPlayer(org.bukkit.craftbukkit.v.entity.CraftPlayer) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) Location(org.bukkit.Location) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with ServerPlayNetHandlerBridge

use of io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge in project Arclight by IzzelAliz.

the class TeleportCommandMixin_1_14 method func_201127_a.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
private static void func_201127_a(CommandSource source, Entity entityIn, ServerWorld worldIn, double x, double y, double z, Set<SPlayerPositionLookPacket.Flags> relativeList, float yaw, float pitch, @Nullable TeleportCommand.Facing facing) {
    if (entityIn instanceof ServerPlayerEntity) {
        ChunkPos chunkpos = new ChunkPos(new BlockPos(x, y, z));
        worldIn.getChunkProvider().func_217228_a(TicketType.POST_TELEPORT, chunkpos, 1, entityIn.getEntityId());
        entityIn.stopRiding();
        if (((ServerPlayerEntity) entityIn).isSleeping()) {
            ((ServerPlayerEntity) entityIn).wakeUpPlayer(true, true, false);
        }
        ((ServerPlayNetHandlerBridge) ((ServerPlayerEntity) entityIn).connection).bridge$pushTeleportCause(PlayerTeleportEvent.TeleportCause.COMMAND);
        if (worldIn == entityIn.world) {
            ((ServerPlayerEntity) entityIn).connection.setPlayerLocation(x, y, z, yaw, pitch, relativeList);
        } else {
            ((ServerPlayerEntity) entityIn).func_200619_a(worldIn, x, y, z, yaw, pitch);
        }
        entityIn.setRotationYawHead(yaw);
    } else {
        float f1 = MathHelper.wrapDegrees(yaw);
        float f = MathHelper.wrapDegrees(pitch);
        f = MathHelper.clamp(f, -90.0F, 90.0F);
        Location to = new Location(((ServerWorldBridge) worldIn).bridge$getWorld(), x, y, z, f1, f);
        EntityTeleportEvent event = new EntityTeleportEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), ((EntityBridge) entityIn).bridge$getBukkitEntity().getLocation(), to);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }
        to = event.getTo();
        x = to.getX();
        y = to.getY();
        z = to.getZ();
        f1 = to.getYaw();
        f = to.getPitch();
        worldIn = ((CraftWorld) to.getWorld()).getHandle();
        if (worldIn == entityIn.world) {
            entityIn.setLocationAndAngles(x, y, z, f1, f);
            entityIn.setRotationYawHead(f1);
        } else {
            entityIn.detach();
            entityIn.dimension = worldIn.dimension.getType();
            Entity entity = entityIn;
            entityIn = entityIn.getType().create(worldIn);
            if (entityIn == null) {
                return;
            }
            entityIn.copyDataFromOld(entity);
            entityIn.setLocationAndAngles(x, y, z, f1, f);
            entityIn.setRotationYawHead(f1);
            worldIn.func_217460_e(entityIn);
            entity.removed = true;
        }
    }
    if (facing != null) {
        facing.updateLook(source, entityIn);
    }
    if (!(entityIn instanceof LivingEntity) || !((LivingEntity) entityIn).isElytraFlying()) {
        entityIn.setMotion(entityIn.getMotion().mul(1.0D, 0.0D, 1.0D));
        entityIn.onGround = true;
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerPlayNetHandlerBridge(io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with ServerPlayNetHandlerBridge

use of io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge in project Arclight by IzzelAliz.

the class ServerPlayerEntityMixin_1_15 method changeDimension.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite(remap = false)
@Nullable
public Entity changeDimension(DimensionType dim, ITeleporter teleporter) {
    DimensionType[] destination = { dim };
    if (this.isSleeping())
        return (ServerPlayerEntity) (Object) this;
    if (!ForgeHooks.onTravelToDimension((ServerPlayerEntity) (Object) this, destination[0]))
        return null;
    PlayerTeleportEvent.TeleportCause cause = bridge$getTeleportCause().orElse(PlayerTeleportEvent.TeleportCause.UNKNOWN);
    // this.invulnerableDimensionChange = true;
    DimensionType dimensiontype = this.dimension;
    if (((DimensionTypeBridge) dimensiontype).bridge$getType() == DimensionType.THE_END && ((DimensionTypeBridge) destination[0]).bridge$getType() == DimensionType.OVERWORLD && teleporter instanceof Teleporter) {
        // Forge: Fix non-vanilla teleporters triggering end credits
        this.invulnerableDimensionChange = true;
        this.detach();
        // Forge: The player entity is cloned so keep the data until after cloning calls copyFrom
        this.getServerWorld().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;
    } else {
        ServerWorld serverworld = this.server.getWorld(dimensiontype);
        // this.dimension = destination;
        ServerWorld[] serverworld1 = { this.server.getWorld(destination[0]) };
        /*
            WorldInfo worldinfo = serverworld1.getWorldInfo();
            NetworkHooks.sendDimensionDataPacket(this.connection.netManager, (ServerPlayerEntity) (Object) this);
            this.connection.sendPacket(new SRespawnPacket(destination, WorldInfo.byHashing(worldinfo.getSeed()), worldinfo.getGenerator(), this.interactionManager.getGameType()));
            this.connection.sendPacket(new SServerDifficultyPacket(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
            PlayerList playerlist = this.server.getPlayerList();
            playerlist.updatePermissionLevel((ServerPlayerEntity) (Object) this);
            serverworld.removeEntity((ServerPlayerEntity) (Object) this, true); //Forge: the player entity is moved to the new world, NOT cloned. So keep the data alive with no matching invalidate call.
            this.revive();
            */
        PlayerList[] playerlist = new PlayerList[1];
        Entity e = teleporter.placeEntity((ServerPlayerEntity) (Object) this, serverworld, serverworld1[0], this.rotationYaw, spawnPortal -> {
            // Forge: Start vanilla logic
            double d0 = this.getPosX();
            double d1 = this.getPosY();
            double d2 = this.getPosZ();
            float f = this.rotationPitch;
            float f1 = this.rotationYaw;
            double d3 = 8.0D;
            float f2 = f1;
            serverworld.getProfiler().startSection("moving");
            if (serverworld1[0] != null) {
                double moveFactor = serverworld.getDimension().getMovementFactor() / serverworld1[0].getDimension().getMovementFactor();
                d0 *= moveFactor;
                d2 *= moveFactor;
                if (dimensiontype == DimensionType.OVERWORLD && destination[0] == DimensionType.THE_NETHER) {
                    this.enteredNetherPosition = this.getPositionVec();
                } else if (dimensiontype == DimensionType.OVERWORLD && destination[0] == DimensionType.THE_END) {
                    BlockPos blockpos = serverworld1[0].getSpawnCoordinate();
                    d0 = blockpos.getX();
                    d1 = blockpos.getY();
                    d2 = blockpos.getZ();
                    f1 = 90.0F;
                    f = 0.0F;
                }
            }
            Location enter = this.bridge$getBukkitEntity().getLocation();
            Location exit = (serverworld1[0] == null) ? null : new Location(((ServerWorldBridge) serverworld1[0]).bridge$getWorld(), d0, d1, d2, f1, f);
            PlayerPortalEvent event = new PlayerPortalEvent(this.bridge$getBukkitEntity(), enter, exit, cause, 128, true, ((DimensionTypeBridge) destination[0]).bridge$getType() == DimensionType.THE_END ? 0 : 16);
            Bukkit.getServer().getPluginManager().callEvent(event);
            if (event.isCancelled() || event.getTo() == null) {
                return null;
            }
            exit = event.getTo();
            if (exit == null) {
                return null;
            }
            serverworld1[0] = ((CraftWorld) exit.getWorld()).getHandle();
            d0 = exit.getX();
            d1 = exit.getY();
            d2 = exit.getZ();
            // this.setLocationAndAngles(d0, d1, d2, f1, f);
            serverworld.getProfiler().endSection();
            serverworld.getProfiler().startSection("placing");
            double d7 = Math.max(-2.9999872E7D, serverworld1[0].getWorldBorder().minX() + 16.0D);
            double d4 = Math.max(-2.9999872E7D, serverworld1[0].getWorldBorder().minZ() + 16.0D);
            double d5 = Math.min(2.9999872E7D, serverworld1[0].getWorldBorder().maxX() - 16.0D);
            double d6 = Math.min(2.9999872E7D, serverworld1[0].getWorldBorder().maxZ() - 16.0D);
            d0 = MathHelper.clamp(d0, d7, d5);
            d2 = MathHelper.clamp(d2, d4, d6);
            // this.setLocationAndAngles(d0, d1, d2, f1, f);
            Vec3d exitVelocity = Vec3d.ZERO;
            BlockPos exitPosition = new BlockPos(d0, d1, d2);
            if (((DimensionTypeBridge) destination[0]).bridge$getType() == DimensionType.THE_END) {
                int i = exitPosition.getX();
                int j = exitPosition.getY() - 1;
                int k = exitPosition.getZ();
                if (event.getCanCreatePortal()) {
                    BlockStateListPopulator blockList = new BlockStateListPopulator(serverworld1[0]);
                    for (int j1 = -2; j1 <= 2; ++j1) {
                        for (int k1 = -2; k1 <= 2; ++k1) {
                            for (int l1 = -1; l1 < 3; ++l1) {
                                int i2 = i + k1 * 1 + j1 * 0;
                                int j2 = j + l1;
                                int k2 = k + k1 * 0 - j1 * 1;
                                boolean flag = l1 < 0;
                                blockList.setBlockState(new BlockPos(i2, j2, k2), flag ? Blocks.OBSIDIAN.getDefaultState() : Blocks.AIR.getDefaultState(), 3);
                            }
                        }
                    }
                    org.bukkit.World bworld = ((ServerWorldBridge) serverworld1[0]).bridge$getWorld();
                    PortalCreateEvent portalEvent = new PortalCreateEvent((List<BlockState>) (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, f1, 0.0F);
                exit.setX(i);
                exit.setY(j);
                exit.setZ(k);
                // this.setMotion(Vec3d.ZERO);
                exitVelocity = Vec3d.ZERO;
            } else {
                BlockPattern.PortalInfo portalInfo = ((TeleporterBridge) serverworld1[0].getDefaultTeleporter()).bridge$placeInPortal((ServerPlayerEntity) (Object) this, exitPosition, f2, event.getSearchRadius(), true);
                if (spawnPortal && portalInfo == null && event.getCanCreatePortal()) {
                    if (((TeleporterBridge) serverworld1[0].getDefaultTeleporter()).bridge$makePortal((ServerPlayerEntity) (Object) this, exitPosition, event.getCreationRadius())) {
                        // serverworld1.getDefaultTeleporter().placeInPortal((ServerPlayerEntity) (Object) this, f2);
                        portalInfo = ((TeleporterBridge) serverworld1[0].getDefaultTeleporter()).bridge$placeInPortal((ServerPlayerEntity) (Object) this, exitPosition, f2, event.getSearchRadius(), true);
                    }
                }
                if (portalInfo == null) {
                    return null;
                }
                exitVelocity = portalInfo.motion;
                exit.setX(portalInfo.pos.getX());
                exit.setY(portalInfo.pos.getY());
                exit.setZ(portalInfo.pos.getZ());
                exit.setYaw(f2 + (float) portalInfo.rotation);
            }
            serverworld.getProfiler().endSection();
            PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(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;
            }
            serverworld1[0] = ((CraftWorld) exit.getWorld()).getHandle();
            this.invulnerableDimensionChange = true;
            destination[0] = serverworld1[0].getDimension().getType();
            this.dimension = destination[0];
            WorldInfo worldinfo = serverworld1[0].getWorldInfo();
            NetworkHooks.sendDimensionDataPacket(this.connection.netManager, (ServerPlayerEntity) (Object) this);
            this.connection.sendPacket(new SRespawnPacket(destination[0], WorldInfo.byHashing(worldinfo.getSeed()), worldinfo.getGenerator(), this.interactionManager.getGameType()));
            this.connection.sendPacket(new SServerDifficultyPacket(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
            playerlist[0] = this.server.getPlayerList();
            playerlist[0].updatePermissionLevel((ServerPlayerEntity) (Object) this);
            // Forge: the player entity is moved to the new world, NOT cloned. So keep the data alive with no matching invalidate call.
            serverworld.removeEntity((ServerPlayerEntity) (Object) this, true);
            this.revive();
            this.setMotion(exitVelocity);
            this.setWorld(serverworld1[0]);
            serverworld1[0].addDuringPortalTeleport((ServerPlayerEntity) (Object) this);
            this.func_213846_b(serverworld);
            // this.connection.setPlayerLocation(this.getPosX(), this.getPosY(), this.getPosZ(), f1, f);
            ((ServerPlayNetHandlerBridge) this.connection).bridge$teleport(exit);
            this.connection.captureCurrentPosition();
            // forge: this is part of the ITeleporter patch
            return (ServerPlayerEntity) (Object) this;
        });
        // Forge: End vanilla logic
        if (e == null) {
            return (ServerPlayerEntity) (Object) this;
        } else if (e != (Object) this) {
            throw new IllegalArgumentException(String.format("Teleporter %s returned not the player entity but instead %s, expected PlayerEntity %s", teleporter, e, this));
        }
        this.interactionManager.setWorld(serverworld1[0]);
        this.connection.sendPacket(new SPlayerAbilitiesPacket(this.abilities));
        playerlist[0].sendWorldInfo((ServerPlayerEntity) (Object) this, serverworld1[0]);
        playerlist[0].sendInventory((ServerPlayerEntity) (Object) this);
        for (EffectInstance effectinstance : this.getActivePotionEffects()) {
            this.connection.sendPacket(new SPlayEntityEffectPacket(this.getEntityId(), effectinstance));
        }
        this.connection.sendPacket(new SPlaySoundEventPacket(1032, BlockPos.ZERO, 0, false));
        this.lastExperience = -1;
        this.lastHealth = -1.0F;
        this.lastFoodLevel = -1;
        BasicEventHooks.firePlayerChangedDimensionEvent((ServerPlayerEntity) (Object) this, dimensiontype, destination[0]);
        PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent(this.bridge$getBukkitEntity(), ((WorldBridge) serverworld).bridge$getWorld());
        Bukkit.getPluginManager().callEvent(changeEvent);
        return (ServerPlayerEntity) (Object) this;
    }
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Entity(net.minecraft.entity.Entity) PlayerList(net.minecraft.server.management.PlayerList) ServerPlayNetHandlerBridge(io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge) 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) 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) List(java.util.List) PlayerList(net.minecraft.server.management.PlayerList) TeleporterBridge(io.izzel.arclight.common.bridge.world.TeleporterBridge) PortalCreateEvent(org.bukkit.event.world.PortalCreateEvent) Teleporter(net.minecraft.world.Teleporter) ITeleporter(net.minecraftforge.common.util.ITeleporter) BlockPattern(net.minecraft.block.pattern.BlockPattern) 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) BlockState(org.bukkit.block.BlockState) PlayerChangedWorldEvent(org.bukkit.event.player.PlayerChangedWorldEvent) ServerWorldBridge(io.izzel.arclight.common.bridge.world.server.ServerWorldBridge) EffectInstance(net.minecraft.potion.EffectInstance) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite) Nullable(javax.annotation.Nullable)

Example 5 with ServerPlayNetHandlerBridge

use of io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge 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)

Aggregations

ServerPlayNetHandlerBridge (io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge)6 Location (org.bukkit.Location)6 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)5 BlockPos (net.minecraft.util.math.BlockPos)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)4 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)3 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)3 ServerWorldBridge (io.izzel.arclight.common.bridge.world.server.ServerWorldBridge)3 Entity (net.minecraft.entity.Entity)3 SChangeGameStatePacket (net.minecraft.network.play.server.SChangeGameStatePacket)3 SServerDifficultyPacket (net.minecraft.network.play.server.SServerDifficultyPacket)3 Vec3d (net.minecraft.util.math.Vec3d)3 ServerWorld (net.minecraft.world.server.ServerWorld)3 WorldInfo (net.minecraft.world.storage.WorldInfo)3 PlayerChangedWorldEvent (org.bukkit.event.player.PlayerChangedWorldEvent)3 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)2 DimensionTypeBridge (io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge)2 LivingEntity (net.minecraft.entity.LivingEntity)2 SPlayEntityEffectPacket (net.minecraft.network.play.server.SPlayEntityEffectPacket)2 SSetExperiencePacket (net.minecraft.network.play.server.SSetExperiencePacket)2