package net.minecraft.client.multiplayer;

import org.apache.logging.log4j.LogManager;
import com.mojang.datafixers.util.Pair;
import javax.annotation.Nullable;
import net.minecraft.network.protocol.game.ClientboundBlockBreakAckPacket;
import net.minecraft.network.protocol.game.ClientboundSetChunkCacheCenterPacket;
import net.minecraft.network.protocol.game.ClientboundSetChunkCacheRadiusPacket;
import net.minecraft.world.item.trading.MerchantOffers;
import net.minecraft.world.inventory.MerchantMenu;
import net.minecraft.network.protocol.game.ClientboundMerchantOffersPacket;
import net.minecraft.network.protocol.game.ClientboundLightUpdatePacket;
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
import net.minecraft.network.protocol.game.ClientboundPlaceGhostRecipePacket;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.AttributeMap;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.core.Registry;
import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket;
import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket;
import net.minecraft.world.scores.PlayerTeam;
import net.minecraft.world.scores.Team;
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
import net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket;
import net.minecraft.world.scores.Score;
import net.minecraft.network.protocol.game.ClientboundSetScorePacket;
import net.minecraft.world.scores.Objective;
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
import net.minecraft.network.protocol.game.ClientboundSetObjectivePacket;
import net.minecraft.core.Position;
import java.util.Collection;
import net.minecraft.client.renderer.debug.BeeDebugRenderer;
import net.minecraft.core.PositionImpl;
import net.minecraft.client.renderer.debug.GoalSelectorDebugRenderer;
import net.minecraft.client.renderer.debug.BrainDebugRenderer;
import net.minecraft.client.renderer.debug.WorldGenAttemptRenderer;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.client.renderer.debug.NeighborsUpdateRenderer;
import net.minecraft.world.level.pathfinder.Path;
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
import net.minecraft.client.gui.screens.inventory.BookViewScreen;
import net.minecraft.network.protocol.game.ClientboundOpenBookPacket;
import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket;
import net.minecraft.network.protocol.game.ClientboundMoveVehiclePacket;
import net.minecraft.network.protocol.game.ClientboundCooldownPacket;
import net.minecraft.network.protocol.game.ClientboundBossEventPacket;
import java.net.URISyntaxException;
import java.net.URI;
import java.util.concurrent.CompletableFuture;
import net.minecraft.client.gui.screens.ConfirmScreen;
import java.io.UnsupportedEncodingException;
import net.minecraft.server.packs.repository.PackSource;
import net.minecraft.network.protocol.game.ServerboundResourcePackPacket;
import java.io.File;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import net.minecraft.network.protocol.game.ClientboundResourcePackPacket;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.network.protocol.game.ClientboundCustomSoundPacket;
import net.minecraft.network.protocol.game.ClientboundSoundEntityPacket;
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket;
import net.minecraft.network.protocol.game.ServerboundKeepAlivePacket;
import net.minecraft.network.protocol.game.ClientboundKeepAlivePacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket;
import net.minecraft.network.protocol.game.ClientboundTabListPacket;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.game.ClientboundSetTitlesPacket;
import net.minecraft.network.protocol.game.ClientboundSetBorderPacket;
import net.minecraft.network.protocol.game.ClientboundSetCameraPacket;
import net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerCombatPacket;
import net.minecraft.network.protocol.game.ClientboundUpdateTagsPacket;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket;
import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener;
import net.minecraft.stats.RecipeBook;
import net.minecraft.client.gui.components.toasts.RecipeToast;
import net.minecraft.network.protocol.game.ClientboundRecipePacket;
import net.minecraft.client.gui.screens.achievement.StatsUpdateListener;
import net.minecraft.stats.Stat;
import net.minecraft.network.protocol.game.ClientboundAwardStatsPacket;
import net.minecraft.network.protocol.game.ClientboundTagQueryPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerLookAtPacket;
import net.minecraft.client.searchtree.MutableSearchTree;
import java.util.function.Consumer;
import net.minecraft.client.gui.screens.recipebook.RecipeCollection;
import net.minecraft.client.searchtree.SearchRegistry;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket;
import net.minecraft.network.protocol.game.ClientboundCommandSuggestionsPacket;
import net.minecraft.network.protocol.game.ClientboundStopSoundPacket;
import com.mojang.brigadier.tree.RootCommandNode;
import net.minecraft.network.protocol.game.ClientboundCommandsPacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.advancements.Advancement;
import net.minecraft.network.protocol.game.ClientboundSelectAdvancementsTabPacket;
import net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket;
import net.minecraft.network.protocol.game.ClientboundLevelEventPacket;
import net.minecraft.client.gui.MapRenderer;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
import net.minecraft.world.item.MapItem;
import net.minecraft.network.protocol.game.ClientboundMapItemDataPacket;
import net.minecraft.client.Options;
import net.minecraft.client.gui.screens.DemoIntroScreen;
import net.minecraft.client.gui.screens.WinScreen;
import net.minecraft.network.protocol.game.ServerboundClientCommandPacket;
import net.minecraft.world.level.GameType;
import net.minecraft.util.Mth;
import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket;
import net.minecraft.network.protocol.game.ClientboundBlockEventPacket;
import net.minecraft.network.protocol.game.ClientboundContainerClosePacket;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
import net.minecraft.network.protocol.game.ClientboundContainerSetDataPacket;
import net.minecraft.client.gui.screens.inventory.CommandBlockEditScreen;
import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
import net.minecraft.world.level.block.entity.CampfireBlockEntity;
import net.minecraft.world.level.block.entity.JigsawBlockEntity;
import net.minecraft.world.level.block.entity.ConduitBlockEntity;
import net.minecraft.world.level.block.entity.BedBlockEntity;
import net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity;
import net.minecraft.world.level.block.entity.StructureBlockEntity;
import net.minecraft.world.level.block.entity.BannerBlockEntity;
import net.minecraft.world.level.block.entity.SkullBlockEntity;
import net.minecraft.world.level.block.entity.BeaconBlockEntity;
import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
import net.minecraft.world.level.block.entity.CommandBlockEntity;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.world.level.block.entity.SignBlockEntity;
import net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket;
import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.network.protocol.game.ServerboundContainerAckPacket;
import net.minecraft.network.protocol.game.ClientboundContainerAckPacket;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen;
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
import net.minecraft.client.gui.screens.inventory.HorseInventoryScreen;
import net.minecraft.world.Container;
import net.minecraft.world.inventory.HorseInventoryMenu;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.animal.horse.AbstractHorse;
import net.minecraft.network.protocol.game.ClientboundHorseScreenOpenPacket;
import net.minecraft.world.level.Explosion;
import net.minecraft.network.protocol.game.ClientboundExplodePacket;
import net.minecraft.world.scores.Scoreboard;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.gui.screens.DeathScreen;
import net.minecraft.network.protocol.game.ClientboundRespawnPacket;
import net.minecraft.network.protocol.game.ClientboundSetExperiencePacket;
import net.minecraft.network.protocol.game.ClientboundSetHealthPacket;
import net.minecraft.client.resources.sounds.GuardianAttackSoundInstance;
import net.minecraft.world.entity.monster.Guardian;
import net.minecraft.network.protocol.game.ClientboundEntityEventPacket;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.item.Items;
import net.minecraft.world.entity.Mob;
import net.minecraft.network.protocol.game.ClientboundSetEntityLinkPacket;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.protocol.game.ClientboundSetPassengersPacket;
import net.minecraft.network.protocol.game.ClientboundSetDefaultSpawnPositionPacket;
import net.minecraft.network.protocol.game.ClientboundSetTimePacket;
import net.minecraft.client.resources.sounds.BeeSoundInstance;
import net.minecraft.world.entity.boss.EnderDragonPart;
import net.minecraft.client.resources.sounds.TickableSoundInstance;
import net.minecraft.client.resources.sounds.BeeFlyingSoundInstance;
import net.minecraft.client.resources.sounds.BeeAggressiveSoundInstance;
import net.minecraft.world.entity.animal.Bee;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraft.network.protocol.game.ClientboundAddMobPacket;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.InteractionHand;
import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.network.protocol.game.ClientboundChatPacket;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ItemPickupParticle;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.network.protocol.game.ClientboundTakeItemEntityPacket;
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.client.gui.screens.DisconnectedScreen;
import net.minecraft.realms.DisconnectedRealmsScreen;
import net.minecraft.realms.RealmsScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundDisconnectPacket;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
import net.minecraft.world.level.lighting.LevelLightEngine;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.network.protocol.game.ClientboundForgetLevelChunkPacket;
import net.minecraft.world.level.block.entity.BlockEntity;
import java.util.Iterator;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.DataLayer;
import net.minecraft.core.SectionPos;
import net.minecraft.world.level.LightLayer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacket;
import net.minecraft.network.protocol.game.ClientboundChunkBlocksUpdatePacket;
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
import net.minecraft.network.protocol.game.ServerboundAcceptTeleportationPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket;
import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket;
import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket;
import net.minecraft.world.phys.Vec3;
import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.network.protocol.game.ClientboundSetCarriedItemPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
import net.minecraft.client.player.RemotePlayer;
import net.minecraft.network.protocol.game.ClientboundAddPlayerPacket;
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket;
import net.minecraft.world.entity.decoration.Painting;
import net.minecraft.network.protocol.game.ClientboundAddPaintingPacket;
import net.minecraft.world.entity.ExperienceOrb;
import net.minecraft.network.protocol.game.ClientboundAddExperienceOrbPacket;
import net.minecraft.world.entity.Entity;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.client.resources.sounds.MinecartSoundInstance;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.entity.LightningBolt;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.entity.item.PrimedTnt;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.entity.projectile.ThrownExperienceBottle;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.EvokerFangs;
import net.minecraft.world.entity.projectile.ThrownEgg;
import net.minecraft.world.entity.projectile.ShulkerBullet;
import net.minecraft.world.entity.projectile.WitherSkull;
import net.minecraft.world.entity.projectile.SmallFireball;
import net.minecraft.world.entity.projectile.DragonFireball;
import net.minecraft.world.entity.projectile.LargeFireball;
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.entity.projectile.EyeOfEnder;
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
import net.minecraft.world.entity.decoration.LeashFenceKnotEntity;
import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.projectile.LlamaSpit;
import net.minecraft.world.entity.projectile.Snowball;
import net.minecraft.world.entity.projectile.ThrownTrident;
import net.minecraft.world.entity.projectile.SpectralArrow;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.Arrow;
import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.entity.vehicle.Minecart;
import net.minecraft.world.entity.vehicle.MinecartCommandBlock;
import net.minecraft.world.entity.vehicle.MinecartHopper;
import net.minecraft.world.entity.vehicle.MinecartSpawner;
import net.minecraft.world.entity.vehicle.MinecartTNT;
import net.minecraft.world.entity.vehicle.MinecartFurnace;
import net.minecraft.world.entity.vehicle.MinecartChest;
import net.minecraft.world.entity.EntityType;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import java.util.ArrayList;
import net.minecraft.client.ClientBrandRetriever;
import net.minecraft.network.FriendlyByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
import net.minecraft.client.gui.screens.ReceivingLevelScreen;
import net.minecraft.world.entity.player.Player;
import net.minecraft.client.player.KeyboardInput;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.ClientRecipeBook;
import net.minecraft.stats.StatsCounter;
import net.minecraft.world.Difficulty;
import net.minecraft.world.level.dimension.DimensionType;
import com.google.common.collect.Sets;
import java.util.List;
import java.util.Collections;
import com.google.common.collect.Lists;
import net.minecraft.tags.EntityTypeTags;
import net.minecraft.tags.FluidTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.thread.BlockableEventLoop;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketUtils;
import net.minecraft.network.protocol.game.ClientboundLoginPacket;
import com.google.common.collect.Maps;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.level.Level;
import net.minecraft.resources.ResourceKey;
import java.util.Set;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.commands.SharedSuggestionProvider;
import com.mojang.brigadier.CommandDispatcher;
import java.util.Random;
import net.minecraft.client.DebugQueryHandler;
import net.minecraft.tags.TagManager;
import java.util.UUID;
import java.util.Map;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import com.mojang.authlib.GameProfile;
import net.minecraft.network.Connection;
import org.apache.logging.log4j.Logger;
import net.minecraft.network.protocol.game.ClientGamePacketListener;

public class ClientPacketListener implements ClientGamePacketListener {
    private static final Logger LOGGER;
    private final Connection connection;
    private final GameProfile localGameProfile;
    private final Screen callbackScreen;
    private Minecraft minecraft;
    private ClientLevel level;
    private ClientLevel.ClientLevelData levelData;
    private boolean started;
    private final Map<UUID, PlayerInfo> playerInfoMap;
    private final ClientAdvancements advancements;
    private final ClientSuggestionProvider suggestionsProvider;
    private TagManager tags;
    private final DebugQueryHandler debugQueryHandler;
    private int serverChunkRadius;
    private final Random random;
    private CommandDispatcher<SharedSuggestionProvider> commands;
    private final RecipeManager recipeManager;
    private final UUID id;
    private Set<ResourceKey<Level>> levels;
    private RegistryAccess registryAccess;
    
    public ClientPacketListener(final Minecraft dlx, final Screen dqs, final Connection me, final GameProfile gameProfile) {
        this.playerInfoMap = Maps.newHashMap();
        this.tags = new TagManager();
        this.debugQueryHandler = new DebugQueryHandler(this);
        this.serverChunkRadius = 3;
        this.random = new Random();
        this.commands = (CommandDispatcher<SharedSuggestionProvider>)new CommandDispatcher();
        this.recipeManager = new RecipeManager();
        this.id = UUID.randomUUID();
        this.registryAccess = RegistryAccess.builtin();
        this.minecraft = dlx;
        this.callbackScreen = dqs;
        this.connection = me;
        this.localGameProfile = gameProfile;
        this.advancements = new ClientAdvancements(dlx);
        this.suggestionsProvider = new ClientSuggestionProvider(this, dlx);
    }
    
    public ClientSuggestionProvider getSuggestionsProvider() {
        return this.suggestionsProvider;
    }
    
    public void cleanup() {
        this.level = null;
    }
    
    public RecipeManager getRecipeManager() {
        return this.recipeManager;
    }
    
    @Override
    public void handleLogin(final ClientboundLoginPacket ox) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ox, this, this.minecraft);
        this.minecraft.gameMode = new MultiPlayerGameMode(this.minecraft, this);
        if (!this.connection.isMemoryConnection()) {
            BlockTags.resetToEmpty();
            ItemTags.resetToEmpty();
            FluidTags.resetToEmpty();
            EntityTypeTags.resetToEmpty();
        }
        final ArrayList<ResourceKey<Level>> arrayList3 = Lists.<ResourceKey<Level>>newArrayList(ox.levels());
        Collections.shuffle(arrayList3);
        this.levels = Sets.newLinkedHashSet(arrayList3);
        this.registryAccess = ox.registryAccess();
        final ResourceKey<DimensionType> ug4 = ox.getDimensionType();
        final ResourceKey<Level> ug5 = ox.getDimension();
        final DimensionType cif6 = this.registryAccess.dimensionTypes().get(ug4);
        this.serverChunkRadius = ox.getChunkRadius();
        final boolean boolean7 = ox.isDebug();
        final boolean boolean8 = ox.isFlat();
        final ClientLevel.ClientLevelData a9 = new ClientLevel.ClientLevelData(Difficulty.NORMAL, ox.isHardcore(), boolean8);
        this.levelData = a9;
        this.level = new ClientLevel(this, a9, ug5, ug4, cif6, this.serverChunkRadius, this.minecraft::getProfiler, this.minecraft.levelRenderer, boolean7, ox.getSeed());
        this.minecraft.setLevel(this.level);
        if (this.minecraft.player == null) {
            this.minecraft.player = this.minecraft.gameMode.createPlayer(this.level, new StatsCounter(), new ClientRecipeBook(this.level.getRecipeManager()));
            this.minecraft.player.yRot = -180.0f;
            if (this.minecraft.getSingleplayerServer() != null) {
                this.minecraft.getSingleplayerServer().setUUID(this.minecraft.player.getUUID());
            }
        }
        this.minecraft.debugRenderer.clear();
        this.minecraft.player.resetPos();
        final int integer10 = ox.getPlayerId();
        this.level.addPlayer(integer10, this.minecraft.player);
        this.minecraft.player.input = new KeyboardInput(this.minecraft.options);
        this.minecraft.gameMode.adjustPlayer(this.minecraft.player);
        this.minecraft.cameraEntity = this.minecraft.player;
        this.minecraft.setScreen(new ReceivingLevelScreen());
        this.minecraft.player.setId(integer10);
        this.minecraft.player.setReducedDebugInfo(ox.isReducedDebugInfo());
        this.minecraft.player.setShowDeathScreen(ox.shouldShowDeathScreen());
        this.minecraft.gameMode.setLocalMode(ox.getGameType());
        this.minecraft.gameMode.setPreviousLocalMode(ox.getPreviousGameType());
        this.minecraft.options.broadcastOptions();
        this.connection.send(new ServerboundCustomPayloadPacket(ServerboundCustomPayloadPacket.BRAND, new FriendlyByteBuf(Unpooled.buffer()).writeUtf(ClientBrandRetriever.getClientModName())));
        this.minecraft.getGame().onStartGameSession();
    }
    
    @Override
    public void handleAddEntity(final ClientboundAddEntityPacket nm) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nm, this, this.minecraft);
        final double double3 = nm.getX();
        final double double4 = nm.getY();
        final double double5 = nm.getZ();
        final EntityType<?> aoq10 = nm.getType();
        Entity aom9;
        if (aoq10 == EntityType.CHEST_MINECART) {
            aom9 = new MinecartChest(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.FURNACE_MINECART) {
            aom9 = new MinecartFurnace(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.TNT_MINECART) {
            aom9 = new MinecartTNT(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.SPAWNER_MINECART) {
            aom9 = new MinecartSpawner(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.HOPPER_MINECART) {
            aom9 = new MinecartHopper(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.COMMAND_BLOCK_MINECART) {
            aom9 = new MinecartCommandBlock(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.MINECART) {
            aom9 = new Minecart(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.FISHING_BOBBER) {
            final Entity aom10 = this.level.getEntity(nm.getData());
            if (aom10 instanceof Player) {
                aom9 = new FishingHook(this.level, (Player)aom10, double3, double4, double5);
            }
            else {
                aom9 = null;
            }
        }
        else if (aoq10 == EntityType.ARROW) {
            aom9 = new Arrow(this.level, double3, double4, double5);
            final Entity aom10 = this.level.getEntity(nm.getData());
            if (aom10 != null) {
                ((AbstractArrow)aom9).setOwner(aom10);
            }
        }
        else if (aoq10 == EntityType.SPECTRAL_ARROW) {
            aom9 = new SpectralArrow(this.level, double3, double4, double5);
            final Entity aom10 = this.level.getEntity(nm.getData());
            if (aom10 != null) {
                ((AbstractArrow)aom9).setOwner(aom10);
            }
        }
        else if (aoq10 == EntityType.TRIDENT) {
            aom9 = new ThrownTrident(this.level, double3, double4, double5);
            final Entity aom10 = this.level.getEntity(nm.getData());
            if (aom10 != null) {
                ((AbstractArrow)aom9).setOwner(aom10);
            }
        }
        else if (aoq10 == EntityType.SNOWBALL) {
            aom9 = new Snowball(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.LLAMA_SPIT) {
            aom9 = new LlamaSpit(this.level, double3, double4, double5, nm.getXa(), nm.getYa(), nm.getZa());
        }
        else if (aoq10 == EntityType.ITEM_FRAME) {
            aom9 = new ItemFrame(this.level, new BlockPos(double3, double4, double5), Direction.from3DDataValue(nm.getData()));
        }
        else if (aoq10 == EntityType.LEASH_KNOT) {
            aom9 = new LeashFenceKnotEntity(this.level, new BlockPos(double3, double4, double5));
        }
        else if (aoq10 == EntityType.ENDER_PEARL) {
            aom9 = new ThrownEnderpearl(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.EYE_OF_ENDER) {
            aom9 = new EyeOfEnder(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.FIREWORK_ROCKET) {
            aom9 = new FireworkRocketEntity(this.level, double3, double4, double5, ItemStack.EMPTY);
        }
        else if (aoq10 == EntityType.FIREBALL) {
            aom9 = new LargeFireball(this.level, double3, double4, double5, nm.getXa(), nm.getYa(), nm.getZa());
        }
        else if (aoq10 == EntityType.DRAGON_FIREBALL) {
            aom9 = new DragonFireball(this.level, double3, double4, double5, nm.getXa(), nm.getYa(), nm.getZa());
        }
        else if (aoq10 == EntityType.SMALL_FIREBALL) {
            aom9 = new SmallFireball(this.level, double3, double4, double5, nm.getXa(), nm.getYa(), nm.getZa());
        }
        else if (aoq10 == EntityType.WITHER_SKULL) {
            aom9 = new WitherSkull(this.level, double3, double4, double5, nm.getXa(), nm.getYa(), nm.getZa());
        }
        else if (aoq10 == EntityType.SHULKER_BULLET) {
            aom9 = new ShulkerBullet(this.level, double3, double4, double5, nm.getXa(), nm.getYa(), nm.getZa());
        }
        else if (aoq10 == EntityType.EGG) {
            aom9 = new ThrownEgg(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.EVOKER_FANGS) {
            aom9 = new EvokerFangs(this.level, double3, double4, double5, 0.0f, 0, null);
        }
        else if (aoq10 == EntityType.POTION) {
            aom9 = new ThrownPotion(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.EXPERIENCE_BOTTLE) {
            aom9 = new ThrownExperienceBottle(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.BOAT) {
            aom9 = new Boat(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.TNT) {
            aom9 = new PrimedTnt(this.level, double3, double4, double5, null);
        }
        else if (aoq10 == EntityType.ARMOR_STAND) {
            aom9 = new ArmorStand(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.END_CRYSTAL) {
            aom9 = new EndCrystal(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.ITEM) {
            aom9 = new ItemEntity(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.FALLING_BLOCK) {
            aom9 = new FallingBlockEntity(this.level, double3, double4, double5, Block.stateById(nm.getData()));
        }
        else if (aoq10 == EntityType.AREA_EFFECT_CLOUD) {
            aom9 = new AreaEffectCloud(this.level, double3, double4, double5);
        }
        else if (aoq10 == EntityType.LIGHTNING_BOLT) {
            aom9 = new LightningBolt(EntityType.LIGHTNING_BOLT, this.level);
        }
        else {
            aom9 = null;
        }
        if (aom9 != null) {
            final int integer11 = nm.getId();
            aom9.setPacketCoordinates(double3, double4, double5);
            aom9.moveTo(double3, double4, double5);
            aom9.xRot = nm.getxRot() * 360 / 256.0f;
            aom9.yRot = nm.getyRot() * 360 / 256.0f;
            aom9.setId(integer11);
            aom9.setUUID(nm.getUUID());
            this.level.putNonPlayerEntity(integer11, aom9);
            if (aom9 instanceof AbstractMinecart) {
                this.minecraft.getSoundManager().play(new MinecartSoundInstance((AbstractMinecart)aom9));
            }
        }
    }
    
    @Override
    public void handleAddExperienceOrb(final ClientboundAddExperienceOrbPacket nn) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nn, this, this.minecraft);
        final double double3 = nn.getX();
        final double double4 = nn.getY();
        final double double5 = nn.getZ();
        final Entity aom9 = new ExperienceOrb(this.level, double3, double4, double5, nn.getValue());
        aom9.setPacketCoordinates(double3, double4, double5);
        aom9.yRot = 0.0f;
        aom9.xRot = 0.0f;
        aom9.setId(nn.getId());
        this.level.putNonPlayerEntity(nn.getId(), aom9);
    }
    
    @Override
    public void handleAddPainting(final ClientboundAddPaintingPacket np) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)np, this, this.minecraft);
        final Painting bbd3 = new Painting(this.level, np.getPos(), np.getDirection(), np.getMotive());
        bbd3.setId(np.getId());
        bbd3.setUUID(np.getUUID());
        this.level.putNonPlayerEntity(np.getId(), bbd3);
    }
    
    @Override
    public void handleSetEntityMotion(final ClientboundSetEntityMotionPacket qb) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qb, this, this.minecraft);
        final Entity aom3 = this.level.getEntity(qb.getId());
        if (aom3 == null) {
            return;
        }
        aom3.lerpMotion(qb.getXa() / 8000.0, qb.getYa() / 8000.0, qb.getZa() / 8000.0);
    }
    
    @Override
    public void handleSetEntityData(final ClientboundSetEntityDataPacket pz) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pz, this, this.minecraft);
        final Entity aom3 = this.level.getEntity(pz.getId());
        if (aom3 != null && pz.getUnpackedData() != null) {
            aom3.getEntityData().assignValues(pz.getUnpackedData());
        }
    }
    
    @Override
    public void handleAddPlayer(final ClientboundAddPlayerPacket nq) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nq, this, this.minecraft);
        final double double3 = nq.getX();
        final double double4 = nq.getY();
        final double double5 = nq.getZ();
        final float float9 = nq.getyRot() * 360 / 256.0f;
        final float float10 = nq.getxRot() * 360 / 256.0f;
        final int integer11 = nq.getEntityId();
        final RemotePlayer ebg12 = new RemotePlayer(this.minecraft.level, this.getPlayerInfo(nq.getPlayerId()).getProfile());
        ebg12.setId(integer11);
        ebg12.setPosAndOldPos(double3, double4, double5);
        ebg12.setPacketCoordinates(double3, double4, double5);
        ebg12.absMoveTo(double3, double4, double5, float9, float10);
        this.level.addPlayer(integer11, ebg12);
    }
    
    @Override
    public void handleTeleportEntity(final ClientboundTeleportEntityPacket qr) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qr, this, this.minecraft);
        final Entity aom3 = this.level.getEntity(qr.getId());
        if (aom3 == null) {
            return;
        }
        final double double4 = qr.getX();
        final double double5 = qr.getY();
        final double double6 = qr.getZ();
        aom3.setPacketCoordinates(double4, double5, double6);
        if (!aom3.isControlledByLocalInstance()) {
            final float float10 = qr.getyRot() * 360 / 256.0f;
            final float float11 = qr.getxRot() * 360 / 256.0f;
            if (Math.abs(aom3.getX() - double4) >= 0.03125 || Math.abs(aom3.getY() - double5) >= 0.015625 || Math.abs(aom3.getZ() - double6) >= 0.03125) {
                aom3.lerpTo(double4, double5, double6, float10, float11, 3, true);
            }
            else {
                aom3.lerpTo(aom3.getX(), aom3.getY(), aom3.getZ(), float10, float11, 3, true);
            }
            aom3.setOnGround(qr.isOnGround());
        }
    }
    
    @Override
    public void handleSetCarriedItem(final ClientboundSetCarriedItemPacket pu) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pu, this, this.minecraft);
        if (Inventory.isHotbarSlot(pu.getSlot())) {
            this.minecraft.player.inventory.selected = pu.getSlot();
        }
    }
    
    @Override
    public void handleMoveEntity(final ClientboundMoveEntityPacket pa) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pa, this, this.minecraft);
        final Entity aom3 = pa.getEntity(this.level);
        if (aom3 == null) {
            return;
        }
        if (!aom3.isControlledByLocalInstance()) {
            if (pa.hasPosition()) {
                final Entity entity = aom3;
                entity.xp += pa.getXa();
                final Entity entity2 = aom3;
                entity2.yp += pa.getYa();
                final Entity entity3 = aom3;
                entity3.zp += pa.getZa();
                final Vec3 dem4 = ClientboundMoveEntityPacket.packetToEntity(aom3.xp, aom3.yp, aom3.zp);
                final float float5 = pa.hasRotation() ? (pa.getyRot() * 360 / 256.0f) : aom3.yRot;
                final float float6 = pa.hasRotation() ? (pa.getxRot() * 360 / 256.0f) : aom3.xRot;
                aom3.lerpTo(dem4.x, dem4.y, dem4.z, float5, float6, 3, false);
            }
            else if (pa.hasRotation()) {
                final float float7 = pa.getyRot() * 360 / 256.0f;
                final float float5 = pa.getxRot() * 360 / 256.0f;
                aom3.lerpTo(aom3.getX(), aom3.getY(), aom3.getZ(), float7, float5, 3, false);
            }
            aom3.setOnGround(pa.isOnGround());
        }
    }
    
    @Override
    public void handleRotateMob(final ClientboundRotateHeadPacket pq) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pq, this, this.minecraft);
        final Entity aom3 = pq.getEntity(this.level);
        if (aom3 == null) {
            return;
        }
        final float float4 = pq.getYHeadRot() * 360 / 256.0f;
        aom3.lerpHeadTo(float4, 3);
    }
    
    @Override
    public void handleRemoveEntity(final ClientboundRemoveEntitiesPacket pm) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pm, this, this.minecraft);
        for (int integer3 = 0; integer3 < pm.getEntityIds().length; ++integer3) {
            final int integer4 = pm.getEntityIds()[integer3];
            this.level.removeEntity(integer4);
        }
    }
    
    @Override
    public void handleMovePlayer(final ClientboundPlayerPositionPacket pk) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pk, this, this.minecraft);
        final Player bec3 = this.minecraft.player;
        final Vec3 dem4 = bec3.getDeltaMovement();
        final boolean boolean5 = pk.getRelativeArguments().contains(ClientboundPlayerPositionPacket.RelativeArgument.X);
        final boolean boolean6 = pk.getRelativeArguments().contains(ClientboundPlayerPositionPacket.RelativeArgument.Y);
        final boolean boolean7 = pk.getRelativeArguments().contains(ClientboundPlayerPositionPacket.RelativeArgument.Z);
        double double8;
        double double9;
        if (boolean5) {
            double8 = dem4.x();
            double9 = bec3.getX() + pk.getX();
            bec3.xOld += pk.getX();
        }
        else {
            double8 = 0.0;
            double9 = pk.getX();
            bec3.xOld = double9;
        }
        double double10;
        double double11;
        if (boolean6) {
            double10 = dem4.y();
            double11 = bec3.getY() + pk.getY();
            bec3.yOld += pk.getY();
        }
        else {
            double10 = 0.0;
            double11 = pk.getY();
            bec3.yOld = double11;
        }
        double double12;
        double double13;
        if (boolean7) {
            double12 = dem4.z();
            double13 = bec3.getZ() + pk.getZ();
            bec3.zOld += pk.getZ();
        }
        else {
            double12 = 0.0;
            double13 = pk.getZ();
            bec3.zOld = double13;
        }
        if (bec3.tickCount > 0 && bec3.getVehicle() != null) {
            bec3.removeVehicle();
        }
        bec3.setPosRaw(double9, double11, double13);
        bec3.xo = double9;
        bec3.yo = double11;
        bec3.zo = double13;
        bec3.setDeltaMovement(double8, double10, double12);
        float float20 = pk.getYRot();
        float float21 = pk.getXRot();
        if (pk.getRelativeArguments().contains(ClientboundPlayerPositionPacket.RelativeArgument.X_ROT)) {
            float21 += bec3.xRot;
        }
        if (pk.getRelativeArguments().contains(ClientboundPlayerPositionPacket.RelativeArgument.Y_ROT)) {
            float20 += bec3.yRot;
        }
        bec3.absMoveTo(double9, double11, double13, float20, float21);
        this.connection.send(new ServerboundAcceptTeleportationPacket(pk.getId()));
        this.connection.send(new ServerboundMovePlayerPacket.PosRot(bec3.getX(), bec3.getY(), bec3.getZ(), bec3.yRot, bec3.xRot, false));
        if (!this.started) {
            this.started = true;
            this.minecraft.setScreen(null);
        }
    }
    
    @Override
    public void handleChunkBlocksUpdate(final ClientboundChunkBlocksUpdatePacket ob) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ob, this, this.minecraft);
        for (final ClientboundChunkBlocksUpdatePacket.BlockUpdate a6 : ob.getUpdates()) {
            this.level.setKnownState(a6.getPos(), a6.getBlock());
        }
    }
    
    @Override
    public void handleLevelChunk(final ClientboundLevelChunkPacket ot) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ot, this, this.minecraft);
        final int integer3 = ot.getX();
        final int integer4 = ot.getZ();
        final LevelChunk chj5 = this.level.getChunkSource().replaceWithPacketData(integer3, integer4, ot.getBiomes(), ot.getReadBuffer(), ot.getHeightmaps(), ot.getAvailableSections(), ot.isFullChunk());
        if (chj5 != null && ot.isFullChunk()) {
            this.level.reAddEntitiesToChunk(chj5);
        }
        for (int integer5 = 0; integer5 < 16; ++integer5) {
            this.level.setSectionDirtyWithNeighbors(integer3, integer5, integer4);
        }
        for (final CompoundTag le7 : ot.getBlockEntitiesTags()) {
            final BlockPos fu2 = new BlockPos(le7.getInt("x"), le7.getInt("y"), le7.getInt("z"));
            final BlockEntity cdl9 = this.level.getBlockEntity(fu2);
            if (cdl9 != null) {
                cdl9.load(this.level.getBlockState(fu2), le7);
            }
        }
        if (!ot.forgetOldData()) {
            this.level.getLightEngine().enableLightSources(chj5.getPos(), false);
            final int integer5 = ot.getAvailableSections();
            for (int integer6 = 0; integer6 < 16; ++integer6) {
                if ((integer5 & 1 << integer6) != 0x0) {
                    this.level.getLightEngine().queueSectionData(LightLayer.BLOCK, SectionPos.of(chj5.getPos(), integer6), new DataLayer(), false);
                    this.level.getLightEngine().queueSectionData(LightLayer.SKY, SectionPos.of(chj5.getPos(), integer6), new DataLayer(), false);
                }
            }
            this.level.getLightEngine().runUpdates(Integer.MAX_VALUE, true, true);
            this.level.getLightEngine().enableLightSources(chj5.getPos(), true);
            chj5.getLights().forEach(fu -> this.level.getLightEngine().onBlockEmissionIncrease(fu, chj5.getLightEmission(fu)));
        }
    }
    
    @Override
    public void handleForgetLevelChunk(final ClientboundForgetLevelChunkPacket op) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)op, this, this.minecraft);
        final int integer3 = op.getX();
        final int integer4 = op.getZ();
        final ClientChunkCache dyk5 = this.level.getChunkSource();
        dyk5.drop(integer3, integer4);
        final LevelLightEngine cwr6 = dyk5.getLightEngine();
        for (int integer5 = 0; integer5 < 16; ++integer5) {
            this.level.setSectionDirtyWithNeighbors(integer3, integer5, integer4);
            cwr6.updateSectionStatus(SectionPos.of(integer3, integer5, integer4), true);
        }
        cwr6.enableLightSources(new ChunkPos(integer3, integer4), false);
    }
    
    @Override
    public void handleBlockUpdate(final ClientboundBlockUpdatePacket nx) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nx, this, this.minecraft);
        this.level.setKnownState(nx.getPos(), nx.getBlockState());
    }
    
    @Override
    public void handleDisconnect(final ClientboundDisconnectPacket om) {
        this.connection.disconnect(om.getReason());
    }
    
    @Override
    public void onDisconnect(final Component mr) {
        this.minecraft.clearLevel();
        if (this.callbackScreen != null) {
            if (this.callbackScreen instanceof RealmsScreen) {
                this.minecraft.setScreen(new DisconnectedRealmsScreen(this.callbackScreen, "disconnect.lost", mr));
            }
            else {
                this.minecraft.setScreen(new DisconnectedScreen(this.callbackScreen, "disconnect.lost", mr));
            }
        }
        else {
            this.minecraft.setScreen(new DisconnectedScreen(new JoinMultiplayerScreen(new TitleScreen()), "disconnect.lost", mr));
        }
    }
    
    public void send(final Packet<?> ni) {
        this.connection.send(ni);
    }
    
    @Override
    public void handleTakeItemEntity(final ClientboundTakeItemEntityPacket qq) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qq, this, this.minecraft);
        final Entity aom3 = this.level.getEntity(qq.getItemId());
        LivingEntity aoy4 = (LivingEntity)this.level.getEntity(qq.getPlayerId());
        if (aoy4 == null) {
            aoy4 = this.minecraft.player;
        }
        if (aom3 != null) {
            if (aom3 instanceof ExperienceOrb) {
                this.level.playLocalSound(aom3.getX(), aom3.getY(), aom3.getZ(), SoundEvents.EXPERIENCE_ORB_PICKUP, SoundSource.PLAYERS, 0.1f, (this.random.nextFloat() - this.random.nextFloat()) * 0.35f + 0.9f, false);
            }
            else {
                this.level.playLocalSound(aom3.getX(), aom3.getY(), aom3.getZ(), SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, 0.2f, (this.random.nextFloat() - this.random.nextFloat()) * 1.4f + 2.0f, false);
            }
            this.minecraft.particleEngine.add(new ItemPickupParticle(this.minecraft.getEntityRenderDispatcher(), this.minecraft.renderBuffers(), this.level, aom3, aoy4));
            if (aom3 instanceof ItemEntity) {
                final ItemEntity bbg5 = (ItemEntity)aom3;
                final ItemStack bki6 = bbg5.getItem();
                bki6.shrink(qq.getAmount());
                if (bki6.isEmpty()) {
                    this.level.removeEntity(qq.getItemId());
                }
            }
            else {
                this.level.removeEntity(qq.getItemId());
            }
        }
    }
    
    @Override
    public void handleChat(final ClientboundChatPacket oa) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oa, this, this.minecraft);
        this.minecraft.gui.handleChat(oa.getType(), oa.getMessage(), oa.getSender());
    }
    
    @Override
    public void handleAnimate(final ClientboundAnimatePacket nr) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nr, this, this.minecraft);
        final Entity aom3 = this.level.getEntity(nr.getId());
        if (aom3 == null) {
            return;
        }
        if (nr.getAction() == 0) {
            final LivingEntity aoy4 = (LivingEntity)aom3;
            aoy4.swing(InteractionHand.MAIN_HAND);
        }
        else if (nr.getAction() == 3) {
            final LivingEntity aoy4 = (LivingEntity)aom3;
            aoy4.swing(InteractionHand.OFF_HAND);
        }
        else if (nr.getAction() == 1) {
            aom3.animateHurt();
        }
        else if (nr.getAction() == 2) {
            final Player bec4 = (Player)aom3;
            bec4.stopSleepInBed(false, false);
        }
        else if (nr.getAction() == 4) {
            this.minecraft.particleEngine.createTrackingEmitter(aom3, ParticleTypes.CRIT);
        }
        else if (nr.getAction() == 5) {
            this.minecraft.particleEngine.createTrackingEmitter(aom3, ParticleTypes.ENCHANTED_HIT);
        }
    }
    
    @Override
    public void handleAddMob(final ClientboundAddMobPacket no) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)no, this, this.minecraft);
        final double double3 = no.getX();
        final double double4 = no.getY();
        final double double5 = no.getZ();
        final float float9 = no.getyRot() * 360 / 256.0f;
        final float float10 = no.getxRot() * 360 / 256.0f;
        final LivingEntity aoy11 = (LivingEntity)EntityType.create(no.getType(), this.minecraft.level);
        if (aoy11 != null) {
            aoy11.setPacketCoordinates(double3, double4, double5);
            aoy11.yBodyRot = no.getyHeadRot() * 360 / 256.0f;
            aoy11.yHeadRot = no.getyHeadRot() * 360 / 256.0f;
            if (aoy11 instanceof EnderDragon) {
                final EnderDragonPart[] arr12 = ((EnderDragon)aoy11).getSubEntities();
                for (int integer13 = 0; integer13 < arr12.length; ++integer13) {
                    arr12[integer13].setId(integer13 + no.getId());
                }
            }
            aoy11.setId(no.getId());
            aoy11.setUUID(no.getUUID());
            aoy11.absMoveTo(double3, double4, double5, float9, float10);
            aoy11.setDeltaMovement(no.getXd() / 8000.0f, no.getYd() / 8000.0f, no.getZd() / 8000.0f);
            this.level.putNonPlayerEntity(no.getId(), aoy11);
            if (aoy11 instanceof Bee) {
                final boolean boolean12 = ((Bee)aoy11).isAngry();
                BeeSoundInstance eoa13;
                if (boolean12) {
                    eoa13 = new BeeAggressiveSoundInstance((Bee)aoy11);
                }
                else {
                    eoa13 = new BeeFlyingSoundInstance((Bee)aoy11);
                }
                this.minecraft.getSoundManager().queueTickingSound(eoa13);
            }
        }
        else {
            ClientPacketListener.LOGGER.warn("Skipping Entity with id {}", no.getType());
        }
    }
    
    @Override
    public void handleSetTime(final ClientboundSetTimePacket qj) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qj, this, this.minecraft);
        this.minecraft.level.setGameTime(qj.getGameTime());
        this.minecraft.level.setDayTime(qj.getDayTime());
    }
    
    @Override
    public void handleSetSpawn(final ClientboundSetDefaultSpawnPositionPacket px) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)px, this, this.minecraft);
        this.minecraft.level.setDefaultSpawnPos(px.getPos());
    }
    
    @Override
    public void handleSetEntityPassengersPacket(final ClientboundSetPassengersPacket qg) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qg, this, this.minecraft);
        final Entity aom3 = this.level.getEntity(qg.getVehicle());
        if (aom3 == null) {
            ClientPacketListener.LOGGER.warn("Received passengers for unknown entity");
            return;
        }
        final boolean boolean4 = aom3.hasIndirectPassenger(this.minecraft.player);
        aom3.ejectPassengers();
        for (final int integer8 : qg.getPassengers()) {
            final Entity aom4 = this.level.getEntity(integer8);
            if (aom4 != null) {
                aom4.startRiding(aom3, true);
                if (aom4 == this.minecraft.player && !boolean4) {
                    this.minecraft.gui.setOverlayMessage(new TranslatableComponent("mount.onboard", new Object[] { this.minecraft.options.keyShift.getTranslatedKeyMessage() }), false);
                }
            }
        }
    }
    
    @Override
    public void handleEntityLinkPacket(final ClientboundSetEntityLinkPacket qa) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qa, this, this.minecraft);
        final Entity aom3 = this.level.getEntity(qa.getSourceId());
        if (aom3 instanceof Mob) {
            ((Mob)aom3).setDelayedLeashHolderId(qa.getDestId());
        }
    }
    
    private static ItemStack findTotem(final Player bec) {
        for (final InteractionHand anf5 : InteractionHand.values()) {
            final ItemStack bki6 = bec.getItemInHand(anf5);
            if (bki6.getItem() == Items.TOTEM_OF_UNDYING) {
                return bki6;
            }
        }
        return new ItemStack(Items.TOTEM_OF_UNDYING);
    }
    
    @Override
    public void handleEntityEvent(final ClientboundEntityEventPacket on) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)on, this, this.minecraft);
        final Entity aom3 = on.getEntity(this.level);
        if (aom3 != null) {
            if (on.getEventId() == 21) {
                this.minecraft.getSoundManager().play(new GuardianAttackSoundInstance((Guardian)aom3));
            }
            else if (on.getEventId() == 35) {
                final int integer4 = 40;
                this.minecraft.particleEngine.createTrackingEmitter(aom3, ParticleTypes.TOTEM_OF_UNDYING, 30);
                this.level.playLocalSound(aom3.getX(), aom3.getY(), aom3.getZ(), SoundEvents.TOTEM_USE, aom3.getSoundSource(), 1.0f, 1.0f, false);
                if (aom3 == this.minecraft.player) {
                    this.minecraft.gameRenderer.displayItemActivation(findTotem(this.minecraft.player));
                }
            }
            else {
                aom3.handleEntityEvent(on.getEventId());
            }
        }
    }
    
    @Override
    public void handleSetHealth(final ClientboundSetHealthPacket qe) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qe, this, this.minecraft);
        this.minecraft.player.hurtTo(qe.getHealth());
        this.minecraft.player.getFoodData().setFoodLevel(qe.getFood());
        this.minecraft.player.getFoodData().setSaturation(qe.getSaturation());
    }
    
    @Override
    public void handleSetExperience(final ClientboundSetExperiencePacket qd) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qd, this, this.minecraft);
        this.minecraft.player.setExperienceValues(qd.getExperienceProgress(), qd.getTotalExperience(), qd.getExperienceLevel());
    }
    
    @Override
    public void handleRespawn(final ClientboundRespawnPacket pp) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pp, this, this.minecraft);
        final ResourceKey<DimensionType> ug3 = pp.getDimensionType();
        final ResourceKey<Level> ug4 = pp.getDimension();
        final DimensionType cif5 = this.registryAccess.dimensionTypes().get(ug3);
        final LocalPlayer ebf6 = this.minecraft.player;
        final int integer7 = ebf6.getId();
        this.started = false;
        if (ug4 != ebf6.level.dimension()) {
            final Scoreboard dfm8 = this.level.getScoreboard();
            final boolean boolean9 = pp.isDebug();
            final boolean boolean10 = pp.isFlat();
            final ClientLevel.ClientLevelData a11 = new ClientLevel.ClientLevelData(this.levelData.getDifficulty(), this.levelData.isHardcore(), boolean10);
            this.levelData = a11;
            (this.level = new ClientLevel(this, a11, ug4, ug3, cif5, this.serverChunkRadius, this.minecraft::getProfiler, this.minecraft.levelRenderer, boolean9, pp.getSeed())).setScoreboard(dfm8);
            this.minecraft.setLevel(this.level);
            this.minecraft.setScreen(new ReceivingLevelScreen());
        }
        this.level.removeAllPendingEntityRemovals();
        final String string8 = ebf6.getServerBrand();
        this.minecraft.cameraEntity = null;
        final LocalPlayer ebf7 = this.minecraft.gameMode.createPlayer(this.level, ebf6.getStats(), ebf6.getRecipeBook(), ebf6.isShiftKeyDown(), ebf6.isSprinting());
        ebf7.setId(integer7);
        this.minecraft.player = ebf7;
        if (ug4 != ebf6.level.dimension()) {
            this.minecraft.getMusicManager().stopPlaying();
        }
        this.minecraft.cameraEntity = ebf7;
        ebf7.getEntityData().assignValues(ebf6.getEntityData().getAll());
        if (pp.shouldKeepAllPlayerData()) {
            ebf7.getAttributes().assignValues(ebf6.getAttributes());
        }
        ebf7.resetPos();
        ebf7.setServerBrand(string8);
        this.level.addPlayer(integer7, ebf7);
        ebf7.yRot = -180.0f;
        ebf7.input = new KeyboardInput(this.minecraft.options);
        this.minecraft.gameMode.adjustPlayer(ebf7);
        ebf7.setReducedDebugInfo(ebf6.isReducedDebugInfo());
        ebf7.setShowDeathScreen(ebf6.shouldShowDeathScreen());
        if (this.minecraft.screen instanceof DeathScreen) {
            this.minecraft.setScreen(null);
        }
        this.minecraft.gameMode.setLocalMode(pp.getPlayerGameType());
        this.minecraft.gameMode.setPreviousLocalMode(pp.getPreviousPlayerGameType());
    }
    
    @Override
    public void handleExplosion(final ClientboundExplodePacket oo) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oo, this, this.minecraft);
        final Explosion bpt3 = new Explosion(this.minecraft.level, null, oo.getX(), oo.getY(), oo.getZ(), oo.getPower(), oo.getToBlow());
        bpt3.finalizeExplosion(true);
        this.minecraft.player.setDeltaMovement(this.minecraft.player.getDeltaMovement().add(oo.getKnockbackX(), oo.getKnockbackY(), oo.getKnockbackZ()));
    }
    
    @Override
    public void handleHorseScreenOpen(final ClientboundHorseScreenOpenPacket or) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)or, this, this.minecraft);
        final Entity aom3 = this.level.getEntity(or.getEntityId());
        if (aom3 instanceof AbstractHorse) {
            final LocalPlayer ebf4 = this.minecraft.player;
            final AbstractHorse azm5 = (AbstractHorse)aom3;
            final SimpleContainer anm6 = new SimpleContainer(or.getSize());
            final HorseInventoryMenu bhe7 = new HorseInventoryMenu(or.getContainerId(), ebf4.inventory, anm6, azm5);
            ebf4.containerMenu = bhe7;
            this.minecraft.setScreen(new HorseInventoryScreen(bhe7, ebf4.inventory, azm5));
        }
    }
    
    @Override
    public void handleOpenScreen(final ClientboundOpenScreenPacket pd) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pd, this, this.minecraft);
        MenuScreens.create(pd.getType(), this.minecraft, pd.getContainerId(), pd.getTitle());
    }
    
    @Override
    public void handleContainerSetSlot(final ClientboundContainerSetSlotPacket oi) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oi, this, this.minecraft);
        final Player bec3 = this.minecraft.player;
        final ItemStack bki4 = oi.getItem();
        final int integer5 = oi.getSlot();
        this.minecraft.getTutorial().onGetItem(bki4);
        if (oi.getContainerId() == -1) {
            if (!(this.minecraft.screen instanceof CreativeModeInventoryScreen)) {
                bec3.inventory.setCarried(bki4);
            }
        }
        else if (oi.getContainerId() == -2) {
            bec3.inventory.setItem(integer5, bki4);
        }
        else {
            boolean boolean6 = false;
            if (this.minecraft.screen instanceof CreativeModeInventoryScreen) {
                final CreativeModeInventoryScreen dsa7 = (CreativeModeInventoryScreen)this.minecraft.screen;
                boolean6 = (dsa7.getSelectedTab() != CreativeModeTab.TAB_INVENTORY.getId());
            }
            if (oi.getContainerId() == 0 && oi.getSlot() >= 36 && integer5 < 45) {
                if (!bki4.isEmpty()) {
                    final ItemStack bki5 = bec3.inventoryMenu.getSlot(integer5).getItem();
                    if (bki5.isEmpty() || bki5.getCount() < bki4.getCount()) {
                        bki4.setPopTime(5);
                    }
                }
                bec3.inventoryMenu.setItem(integer5, bki4);
            }
            else if (oi.getContainerId() == bec3.containerMenu.containerId && (oi.getContainerId() != 0 || !boolean6)) {
                bec3.containerMenu.setItem(integer5, bki4);
            }
        }
    }
    
    @Override
    public void handleContainerAck(final ClientboundContainerAckPacket oe) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oe, this, this.minecraft);
        AbstractContainerMenu bgi3 = null;
        final Player bec4 = this.minecraft.player;
        if (oe.getContainerId() == 0) {
            bgi3 = bec4.inventoryMenu;
        }
        else if (oe.getContainerId() == bec4.containerMenu.containerId) {
            bgi3 = bec4.containerMenu;
        }
        if (bgi3 != null && !oe.isAccepted()) {
            this.send(new ServerboundContainerAckPacket(oe.getContainerId(), oe.getUid(), true));
        }
    }
    
    @Override
    public void handleContainerContent(final ClientboundContainerSetContentPacket og) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)og, this, this.minecraft);
        final Player bec3 = this.minecraft.player;
        if (og.getContainerId() == 0) {
            bec3.inventoryMenu.setAll(og.getItems());
        }
        else if (og.getContainerId() == bec3.containerMenu.containerId) {
            bec3.containerMenu.setAll(og.getItems());
        }
    }
    
    @Override
    public void handleOpenSignEditor(final ClientboundOpenSignEditorPacket pe) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pe, this, this.minecraft);
        BlockEntity cdl3 = this.level.getBlockEntity(pe.getPos());
        if (!(cdl3 instanceof SignBlockEntity)) {
            cdl3 = new SignBlockEntity();
            cdl3.setLevelAndPosition(this.level, pe.getPos());
        }
        this.minecraft.player.openTextEdit((SignBlockEntity)cdl3);
    }
    
    @Override
    public void handleBlockEntityData(final ClientboundBlockEntityDataPacket nv) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nv, this, this.minecraft);
        final BlockPos fu3 = nv.getPos();
        final BlockEntity cdl4 = this.minecraft.level.getBlockEntity(fu3);
        final int integer5 = nv.getType();
        final boolean boolean6 = integer5 == 2 && cdl4 instanceof CommandBlockEntity;
        if ((integer5 == 1 && cdl4 instanceof SpawnerBlockEntity) || boolean6 || (integer5 == 3 && cdl4 instanceof BeaconBlockEntity) || (integer5 == 4 && cdl4 instanceof SkullBlockEntity) || (integer5 == 6 && cdl4 instanceof BannerBlockEntity) || (integer5 == 7 && cdl4 instanceof StructureBlockEntity) || (integer5 == 8 && cdl4 instanceof TheEndGatewayBlockEntity) || (integer5 == 9 && cdl4 instanceof SignBlockEntity) || (integer5 == 11 && cdl4 instanceof BedBlockEntity) || (integer5 == 5 && cdl4 instanceof ConduitBlockEntity) || (integer5 == 12 && cdl4 instanceof JigsawBlockEntity) || (integer5 == 13 && cdl4 instanceof CampfireBlockEntity) || (integer5 == 14 && cdl4 instanceof BeehiveBlockEntity)) {
            cdl4.load(this.minecraft.level.getBlockState(fu3), nv.getTag());
        }
        if (boolean6 && this.minecraft.screen instanceof CommandBlockEditScreen) {
            ((CommandBlockEditScreen)this.minecraft.screen).updateGui();
        }
    }
    
    @Override
    public void handleContainerSetData(final ClientboundContainerSetDataPacket oh) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oh, this, this.minecraft);
        final Player bec3 = this.minecraft.player;
        if (bec3.containerMenu != null && bec3.containerMenu.containerId == oh.getContainerId()) {
            bec3.containerMenu.setData(oh.getId(), oh.getValue());
        }
    }
    
    @Override
    public void handleSetEquipment(final ClientboundSetEquipmentPacket qc) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qc, this, this.minecraft);
        final Entity aom3 = this.level.getEntity(qc.getEntity());
        if (aom3 != null) {
            qc.getSlots().forEach(pair -> aom3.setItemSlot((EquipmentSlot)pair.getFirst(), (ItemStack)pair.getSecond()));
        }
    }
    
    @Override
    public void handleContainerClose(final ClientboundContainerClosePacket of) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)of, this, this.minecraft);
        this.minecraft.player.clientSideCloseContainer();
    }
    
    @Override
    public void handleBlockEvent(final ClientboundBlockEventPacket nw) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nw, this, this.minecraft);
        this.minecraft.level.blockEvent(nw.getPos(), nw.getBlock(), nw.getB0(), nw.getB1());
    }
    
    @Override
    public void handleBlockDestruction(final ClientboundBlockDestructionPacket nu) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nu, this, this.minecraft);
        this.minecraft.level.destroyBlockProgress(nu.getId(), nu.getPos(), nu.getProgress());
    }
    
    @Override
    public void handleGameEvent(final ClientboundGameEventPacket oq) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oq, this, this.minecraft);
        final Player bec3 = this.minecraft.player;
        final ClientboundGameEventPacket.Type a4 = oq.getEvent();
        final float float5 = oq.getParam();
        final int integer6 = Mth.floor(float5 + 0.5f);
        if (a4 == ClientboundGameEventPacket.NO_RESPAWN_BLOCK_AVAILABLE) {
            bec3.displayClientMessage(new TranslatableComponent("block.minecraft.spawn.not_valid"), false);
        }
        else if (a4 == ClientboundGameEventPacket.START_RAINING) {
            this.level.getLevelData().setRaining(true);
            this.level.setRainLevel(0.0f);
        }
        else if (a4 == ClientboundGameEventPacket.STOP_RAINING) {
            this.level.getLevelData().setRaining(false);
            this.level.setRainLevel(1.0f);
        }
        else if (a4 == ClientboundGameEventPacket.CHANGE_GAME_MODE) {
            this.minecraft.gameMode.setLocalMode(GameType.byId(integer6));
        }
        else if (a4 == ClientboundGameEventPacket.WIN_GAME) {
            if (integer6 == 0) {
                this.minecraft.player.connection.send(new ServerboundClientCommandPacket(ServerboundClientCommandPacket.Action.PERFORM_RESPAWN));
                this.minecraft.setScreen(new ReceivingLevelScreen());
            }
            else if (integer6 == 1) {
                this.minecraft.setScreen(new WinScreen(true, () -> this.minecraft.player.connection.send(new ServerboundClientCommandPacket(ServerboundClientCommandPacket.Action.PERFORM_RESPAWN))));
            }
        }
        else if (a4 == ClientboundGameEventPacket.DEMO_EVENT) {
            final Options dmb7 = this.minecraft.options;
            if (float5 == 0.0f) {
                this.minecraft.setScreen(new DemoIntroScreen());
            }
            else if (float5 == 101.0f) {
                this.minecraft.gui.getChat().addMessage(new TranslatableComponent("demo.help.movement", new Object[] { dmb7.keyUp.getTranslatedKeyMessage(), dmb7.keyLeft.getTranslatedKeyMessage(), dmb7.keyDown.getTranslatedKeyMessage(), dmb7.keyRight.getTranslatedKeyMessage() }));
            }
            else if (float5 == 102.0f) {
                this.minecraft.gui.getChat().addMessage(new TranslatableComponent("demo.help.jump", new Object[] { dmb7.keyJump.getTranslatedKeyMessage() }));
            }
            else if (float5 == 103.0f) {
                this.minecraft.gui.getChat().addMessage(new TranslatableComponent("demo.help.inventory", new Object[] { dmb7.keyInventory.getTranslatedKeyMessage() }));
            }
            else if (float5 == 104.0f) {
                this.minecraft.gui.getChat().addMessage(new TranslatableComponent("demo.day.6", new Object[] { dmb7.keyScreenshot.getTranslatedKeyMessage() }));
            }
        }
        else if (a4 == ClientboundGameEventPacket.ARROW_HIT_PLAYER) {
            this.level.playSound(bec3, bec3.getX(), bec3.getEyeY(), bec3.getZ(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.18f, 0.45f);
        }
        else if (a4 == ClientboundGameEventPacket.RAIN_LEVEL_CHANGE) {
            this.level.setRainLevel(float5);
        }
        else if (a4 == ClientboundGameEventPacket.THUNDER_LEVEL_CHANGE) {
            this.level.setThunderLevel(float5);
        }
        else if (a4 == ClientboundGameEventPacket.PUFFER_FISH_STING) {
            this.level.playSound(bec3, bec3.getX(), bec3.getY(), bec3.getZ(), SoundEvents.PUFFER_FISH_STING, SoundSource.NEUTRAL, 1.0f, 1.0f);
        }
        else if (a4 == ClientboundGameEventPacket.GUARDIAN_ELDER_EFFECT) {
            this.level.addParticle(ParticleTypes.ELDER_GUARDIAN, bec3.getX(), bec3.getY(), bec3.getZ(), 0.0, 0.0, 0.0);
            if (integer6 == 1) {
                this.level.playSound(bec3, bec3.getX(), bec3.getY(), bec3.getZ(), SoundEvents.ELDER_GUARDIAN_CURSE, SoundSource.HOSTILE, 1.0f, 1.0f);
            }
        }
        else if (a4 == ClientboundGameEventPacket.IMMEDIATE_RESPAWN) {
            this.minecraft.player.setShowDeathScreen(float5 == 0.0f);
        }
    }
    
    @Override
    public void handleMapItemData(final ClientboundMapItemDataPacket oy) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oy, this, this.minecraft);
        final MapRenderer dmw3 = this.minecraft.gameRenderer.getMapRenderer();
        final String string4 = MapItem.makeKey(oy.getMapId());
        MapItemSavedData czv5 = this.minecraft.level.getMapData(string4);
        if (czv5 == null) {
            czv5 = new MapItemSavedData(string4);
            if (dmw3.getMapInstanceIfExists(string4) != null) {
                final MapItemSavedData czv6 = dmw3.getData(dmw3.getMapInstanceIfExists(string4));
                if (czv6 != null) {
                    czv5 = czv6;
                }
            }
            this.minecraft.level.setMapData(czv5);
        }
        oy.applyToMap(czv5);
        dmw3.update(czv5);
    }
    
    @Override
    public void handleLevelEvent(final ClientboundLevelEventPacket ou) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ou, this, this.minecraft);
        if (ou.isGlobalEvent()) {
            this.minecraft.level.globalLevelEvent(ou.getType(), ou.getPos(), ou.getData());
        }
        else {
            this.minecraft.level.levelEvent(ou.getType(), ou.getPos(), ou.getData());
        }
    }
    
    @Override
    public void handleUpdateAdvancementsPacket(final ClientboundUpdateAdvancementsPacket qs) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qs, this, this.minecraft);
        this.advancements.update(qs);
    }
    
    @Override
    public void handleSelectAdvancementsTab(final ClientboundSelectAdvancementsTabPacket pr) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pr, this, this.minecraft);
        final ResourceLocation uh3 = pr.getTab();
        if (uh3 == null) {
            this.advancements.setSelectedTab(null, false);
        }
        else {
            final Advancement w4 = this.advancements.getAdvancements().get(uh3);
            this.advancements.setSelectedTab(w4, false);
        }
    }
    
    @Override
    public void handleCommands(final ClientboundCommandsPacket od) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)od, this, this.minecraft);
        this.commands = (CommandDispatcher<SharedSuggestionProvider>)new CommandDispatcher((RootCommandNode)od.getRoot());
    }
    
    @Override
    public void handleStopSoundEvent(final ClientboundStopSoundPacket qn) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qn, this, this.minecraft);
        this.minecraft.getSoundManager().stop(qn.getName(), qn.getSource());
    }
    
    @Override
    public void handleCommandSuggestions(final ClientboundCommandSuggestionsPacket oc) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oc, this, this.minecraft);
        this.suggestionsProvider.completeCustomSuggestions(oc.getId(), oc.getSuggestions());
    }
    
    @Override
    public void handleUpdateRecipes(final ClientboundUpdateRecipesPacket qv) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qv, this, this.minecraft);
        this.recipeManager.replaceRecipes(qv.getRecipes());
        final MutableSearchTree<RecipeCollection> eor3 = this.minecraft.<RecipeCollection>getSearchTree(SearchRegistry.RECIPE_COLLECTIONS);
        eor3.clear();
        final ClientRecipeBook dlk4 = this.minecraft.player.getRecipeBook();
        dlk4.setupCollections();
        dlk4.getCollections().forEach(eor3::add);
        eor3.refresh();
    }
    
    @Override
    public void handleLookAt(final ClientboundPlayerLookAtPacket pj) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pj, this, this.minecraft);
        final Vec3 dem3 = pj.getPosition(this.level);
        if (dem3 != null) {
            this.minecraft.player.lookAt(pj.getFromAnchor(), dem3);
        }
    }
    
    @Override
    public void handleTagQueryPacket(final ClientboundTagQueryPacket qp) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qp, this, this.minecraft);
        if (!this.debugQueryHandler.handleResponse(qp.getTransactionId(), qp.getTag())) {
            ClientPacketListener.LOGGER.debug("Got unhandled response to tag query {}", qp.getTransactionId());
        }
    }
    
    @Override
    public void handleAwardStats(final ClientboundAwardStatsPacket ns) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ns, this, this.minecraft);
        for (final Map.Entry<Stat<?>, Integer> entry4 : ns.getStats().entrySet()) {
            final Stat<?> acr5 = entry4.getKey();
            final int integer6 = entry4.getValue();
            this.minecraft.player.getStats().setValue(this.minecraft.player, acr5, integer6);
        }
        if (this.minecraft.screen instanceof StatsUpdateListener) {
            ((StatsUpdateListener)this.minecraft.screen).onStatsUpdated();
        }
    }
    
    @Override
    public void handleAddOrRemoveRecipes(final ClientboundRecipePacket pl) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pl, this, this.minecraft);
        final ClientRecipeBook dlk3 = this.minecraft.player.getRecipeBook();
        dlk3.setGuiOpen(pl.isGuiOpen());
        dlk3.setFilteringCraftable(pl.isFilteringCraftable());
        dlk3.setFurnaceGuiOpen(pl.isFurnaceGuiOpen());
        dlk3.setFurnaceFilteringCraftable(pl.isFurnaceFilteringCraftable());
        final ClientboundRecipePacket.State a4 = pl.getState();
        switch (a4) {
            case REMOVE: {
                for (final ResourceLocation uh6 : pl.getRecipes()) {
                    this.recipeManager.byKey(uh6).ifPresent(dlk3::remove);
                }
                break;
            }
            case INIT: {
                for (final ResourceLocation uh6 : pl.getRecipes()) {
                    this.recipeManager.byKey(uh6).ifPresent(dlk3::add);
                }
                for (final ResourceLocation uh6 : pl.getHighlights()) {
                    this.recipeManager.byKey(uh6).ifPresent(dlk3::addHighlight);
                }
                break;
            }
            case ADD: {
                for (final ResourceLocation uh6 : pl.getRecipes()) {
                    final RecipeBook recipeBook;
                    this.recipeManager.byKey(uh6).ifPresent(bmu -> {
                        recipeBook.add(bmu);
                        recipeBook.addHighlight(bmu);
                        RecipeToast.addOrUpdate(this.minecraft.getToasts(), bmu);
                        return;
                    });
                }
                break;
            }
        }
        dlk3.getCollections().forEach(dtr -> dtr.updateKnownRecipes(dlk3));
        if (this.minecraft.screen instanceof RecipeUpdateListener) {
            ((RecipeUpdateListener)this.minecraft.screen).recipesUpdated();
        }
    }
    
    @Override
    public void handleUpdateMobEffect(final ClientboundUpdateMobEffectPacket qu) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qu, this, this.minecraft);
        final Entity aom3 = this.level.getEntity(qu.getEntityId());
        if (!(aom3 instanceof LivingEntity)) {
            return;
        }
        final MobEffect aoe4 = MobEffect.byId(qu.getEffectId());
        if (aoe4 == null) {
            return;
        }
        final MobEffectInstance aog5 = new MobEffectInstance(aoe4, qu.getEffectDurationTicks(), qu.getEffectAmplifier(), qu.isEffectAmbient(), qu.isEffectVisible(), qu.effectShowsIcon());
        aog5.setNoCounter(qu.isSuperLongDuration());
        ((LivingEntity)aom3).forceAddEffect(aog5);
    }
    
    @Override
    public void handleUpdateTags(final ClientboundUpdateTagsPacket qw) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qw, this, this.minecraft);
        this.tags = qw.getTags();
        if (!this.connection.isMemoryConnection()) {
            this.tags.bindToGlobal();
        }
        this.minecraft.<ItemStack>getSearchTree(SearchRegistry.CREATIVE_TAGS).refresh();
    }
    
    @Override
    public void handlePlayerCombat(final ClientboundPlayerCombatPacket ph) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ph, this, this.minecraft);
        if (ph.event == ClientboundPlayerCombatPacket.Event.ENTITY_DIED) {
            final Entity aom3 = this.level.getEntity(ph.playerId);
            if (aom3 == this.minecraft.player) {
                if (this.minecraft.player.shouldShowDeathScreen()) {
                    this.minecraft.setScreen(new DeathScreen(ph.message, this.level.getLevelData().isHardcore()));
                }
                else {
                    this.minecraft.player.respawn();
                }
            }
        }
    }
    
    @Override
    public void handleChangeDifficulty(final ClientboundChangeDifficultyPacket nz) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nz, this, this.minecraft);
        this.levelData.setDifficulty(nz.getDifficulty());
        this.levelData.setDifficultyLocked(nz.isLocked());
    }
    
    @Override
    public void handleSetCamera(final ClientboundSetCameraPacket pt) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pt, this, this.minecraft);
        final Entity aom3 = pt.getEntity(this.level);
        if (aom3 != null) {
            this.minecraft.setCameraEntity(aom3);
        }
    }
    
    @Override
    public void handleSetBorder(final ClientboundSetBorderPacket ps) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ps, this, this.minecraft);
        ps.applyChanges(this.level.getWorldBorder());
    }
    
    @Override
    public void handleSetTitles(final ClientboundSetTitlesPacket qk) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qk, this, this.minecraft);
        final ClientboundSetTitlesPacket.Type a3 = qk.getType();
        Component mr4 = null;
        Component mr5 = null;
        final Component mr6 = (qk.getText() != null) ? qk.getText() : TextComponent.EMPTY;
        switch (a3) {
            case TITLE: {
                mr4 = mr6;
                break;
            }
            case SUBTITLE: {
                mr5 = mr6;
                break;
            }
            case ACTIONBAR: {
                this.minecraft.gui.setOverlayMessage(mr6, false);
                return;
            }
            case RESET: {
                this.minecraft.gui.setTitles(null, null, -1, -1, -1);
                this.minecraft.gui.resetTitleTimes();
                return;
            }
        }
        this.minecraft.gui.setTitles(mr4, mr5, qk.getFadeInTime(), qk.getStayTime(), qk.getFadeOutTime());
    }
    
    @Override
    public void handleTabListCustomisation(final ClientboundTabListPacket qo) {
        this.minecraft.gui.getTabList().setHeader(qo.getHeader().getString().isEmpty() ? null : qo.getHeader());
        this.minecraft.gui.getTabList().setFooter(qo.getFooter().getString().isEmpty() ? null : qo.getFooter());
    }
    
    @Override
    public void handleRemoveMobEffect(final ClientboundRemoveMobEffectPacket pn) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pn, this, this.minecraft);
        final Entity aom3 = pn.getEntity(this.level);
        if (aom3 instanceof LivingEntity) {
            ((LivingEntity)aom3).removeEffectNoUpdate(pn.getEffect());
        }
    }
    
    @Override
    public void handlePlayerInfo(final ClientboundPlayerInfoPacket pi) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pi, this, this.minecraft);
        for (final ClientboundPlayerInfoPacket.PlayerUpdate b4 : pi.getEntries()) {
            if (pi.getAction() == ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER) {
                this.playerInfoMap.remove(b4.getProfile().getId());
            }
            else {
                PlayerInfo dyq5 = this.playerInfoMap.get(b4.getProfile().getId());
                if (pi.getAction() == ClientboundPlayerInfoPacket.Action.ADD_PLAYER) {
                    dyq5 = new PlayerInfo(b4);
                    this.playerInfoMap.put(dyq5.getProfile().getId(), dyq5);
                }
                if (dyq5 == null) {
                    continue;
                }
                switch (pi.getAction()) {
                    case ADD_PLAYER: {
                        dyq5.setGameMode(b4.getGameMode());
                        dyq5.setLatency(b4.getLatency());
                        dyq5.setTabListDisplayName(b4.getDisplayName());
                        continue;
                    }
                    case UPDATE_GAME_MODE: {
                        dyq5.setGameMode(b4.getGameMode());
                        continue;
                    }
                    case UPDATE_LATENCY: {
                        dyq5.setLatency(b4.getLatency());
                        continue;
                    }
                    case UPDATE_DISPLAY_NAME: {
                        dyq5.setTabListDisplayName(b4.getDisplayName());
                        continue;
                    }
                }
            }
        }
    }
    
    @Override
    public void handleKeepAlive(final ClientboundKeepAlivePacket os) {
        this.send(new ServerboundKeepAlivePacket(os.getId()));
    }
    
    @Override
    public void handlePlayerAbilities(final ClientboundPlayerAbilitiesPacket pg) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pg, this, this.minecraft);
        final Player bec3 = this.minecraft.player;
        bec3.abilities.flying = pg.isFlying();
        bec3.abilities.instabuild = pg.canInstabuild();
        bec3.abilities.invulnerable = pg.isInvulnerable();
        bec3.abilities.mayfly = pg.canFly();
        bec3.abilities.setFlyingSpeed(pg.getFlyingSpeed());
        bec3.abilities.setWalkingSpeed(pg.getWalkingSpeed());
    }
    
    @Override
    public void handleSoundEvent(final ClientboundSoundPacket qm) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qm, this, this.minecraft);
        this.minecraft.level.playSound(this.minecraft.player, qm.getX(), qm.getY(), qm.getZ(), qm.getSound(), qm.getSource(), qm.getVolume(), qm.getPitch());
    }
    
    @Override
    public void handleSoundEntityEvent(final ClientboundSoundEntityPacket ql) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ql, this, this.minecraft);
        final Entity aom3 = this.level.getEntity(ql.getId());
        if (aom3 == null) {
            return;
        }
        this.minecraft.level.playSound(this.minecraft.player, aom3, ql.getSound(), ql.getSource(), ql.getVolume(), ql.getPitch());
    }
    
    @Override
    public void handleCustomSoundEvent(final ClientboundCustomSoundPacket ol) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ol, this, this.minecraft);
        this.minecraft.getSoundManager().play(new SimpleSoundInstance(ol.getName(), ol.getSource(), ol.getVolume(), ol.getPitch(), false, 0, SoundInstance.Attenuation.LINEAR, ol.getX(), ol.getY(), ol.getZ(), false));
    }
    
    @Override
    public void handleResourcePack(final ClientboundResourcePackPacket po) {
        final String string3 = po.getUrl();
        final String string4 = po.getHash();
        if (!this.validateResourcePackUrl(string3)) {
            return;
        }
        if (string3.startsWith("level://")) {
            try {
                final String string5 = URLDecoder.decode(string3.substring("level://".length()), StandardCharsets.UTF_8.toString());
                final File file6 = new File(this.minecraft.gameDirectory, "saves");
                final File file7 = new File(file6, string5);
                if (file7.isFile()) {
                    this.send(ServerboundResourcePackPacket.Action.ACCEPTED);
                    final CompletableFuture<?> completableFuture8 = this.minecraft.getClientPackSource().setServerPack(file7, PackSource.WORLD);
                    this.downloadCallback(completableFuture8);
                    return;
                }
            }
            catch (UnsupportedEncodingException ex) {}
            this.send(ServerboundResourcePackPacket.Action.FAILED_DOWNLOAD);
            return;
        }
        final ServerData dys5 = this.minecraft.getCurrentServer();
        if (dys5 != null && dys5.getResourcePackStatus() == ServerData.ServerPackStatus.ENABLED) {
            this.send(ServerboundResourcePackPacket.Action.ACCEPTED);
            this.downloadCallback(this.minecraft.getClientPackSource().downloadAndSelectResourcePack(string3, string4));
        }
        else if (dys5 == null || dys5.getResourcePackStatus() == ServerData.ServerPackStatus.PROMPT) {
            final Minecraft minecraft;
            final Screen screen;
            final Object o;
            final Object o2;
            this.minecraft.execute(() -> {
                minecraft = this.minecraft;
                new ConfirmScreen(boolean3 -> {
                    this.minecraft = Minecraft.getInstance();
                    final ServerData dys5 = this.minecraft.getCurrentServer();
                    if (boolean3) {
                        if (dys5 != null) {
                            dys5.setResourcePackStatus(ServerData.ServerPackStatus.ENABLED);
                        }
                        this.send(ServerboundResourcePackPacket.Action.ACCEPTED);
                        this.downloadCallback(this.minecraft.getClientPackSource().downloadAndSelectResourcePack(o, o2));
                    }
                    else {
                        if (dys5 != null) {
                            dys5.setResourcePackStatus(ServerData.ServerPackStatus.DISABLED);
                        }
                        this.send(ServerboundResourcePackPacket.Action.DECLINED);
                    }
                    ServerList.saveSingleServer(dys5);
                    this.minecraft.setScreen(null);
                }, new TranslatableComponent("multiplayer.texturePrompt.line1"), new TranslatableComponent("multiplayer.texturePrompt.line2"));
                minecraft.setScreen(screen);
            });
        }
        else {
            this.send(ServerboundResourcePackPacket.Action.DECLINED);
        }
    }
    
    private boolean validateResourcePackUrl(final String string) {
        try {
            final URI uRI3 = new URI(string);
            final String string2 = uRI3.getScheme();
            final boolean boolean5 = "level".equals(string2);
            if (!"http".equals(string2) && !"https".equals(string2) && !boolean5) {
                throw new URISyntaxException(string, "Wrong protocol");
            }
            if (boolean5 && (string.contains("..") || !string.endsWith("/resources.zip"))) {
                throw new URISyntaxException(string, "Invalid levelstorage resourcepack path");
            }
        }
        catch (URISyntaxException uRISyntaxException3) {
            this.send(ServerboundResourcePackPacket.Action.FAILED_DOWNLOAD);
            return false;
        }
        return true;
    }
    
    private void downloadCallback(final CompletableFuture<?> completableFuture) {
        completableFuture.thenRun(() -> this.send(ServerboundResourcePackPacket.Action.SUCCESSFULLY_LOADED)).exceptionally(throwable -> {
            this.send(ServerboundResourcePackPacket.Action.FAILED_DOWNLOAD);
            return null;
        });
    }
    
    private void send(final ServerboundResourcePackPacket.Action a) {
        this.connection.send(new ServerboundResourcePackPacket(a));
    }
    
    @Override
    public void handleBossUpdate(final ClientboundBossEventPacket ny) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ny, this, this.minecraft);
        this.minecraft.gui.getBossOverlay().update(ny);
    }
    
    @Override
    public void handleItemCooldown(final ClientboundCooldownPacket oj) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oj, this, this.minecraft);
        if (oj.getDuration() == 0) {
            this.minecraft.player.getCooldowns().removeCooldown(oj.getItem());
        }
        else {
            this.minecraft.player.getCooldowns().addCooldown(oj.getItem(), oj.getDuration());
        }
    }
    
    @Override
    public void handleMoveVehicle(final ClientboundMoveVehiclePacket pb) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pb, this, this.minecraft);
        final Entity aom3 = this.minecraft.player.getRootVehicle();
        if (aom3 != this.minecraft.player && aom3.isControlledByLocalInstance()) {
            aom3.absMoveTo(pb.getX(), pb.getY(), pb.getZ(), pb.getYRot(), pb.getXRot());
            this.connection.send(new ServerboundMoveVehiclePacket(aom3));
        }
    }
    
    @Override
    public void handleOpenBook(final ClientboundOpenBookPacket pc) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pc, this, this.minecraft);
        final ItemStack bki3 = this.minecraft.player.getItemInHand(pc.getHand());
        if (bki3.getItem() == Items.WRITTEN_BOOK) {
            this.minecraft.setScreen(new BookViewScreen(new BookViewScreen.WrittenBookAccess(bki3)));
        }
    }
    
    @Override
    public void handleCustomPayload(final ClientboundCustomPayloadPacket ok) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ok, this, this.minecraft);
        final ResourceLocation uh3 = ok.getIdentifier();
        FriendlyByteBuf mg4 = null;
        try {
            mg4 = ok.getData();
            if (ClientboundCustomPayloadPacket.BRAND.equals(uh3)) {
                this.minecraft.player.setServerBrand(mg4.readUtf(32767));
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_PATHFINDING_PACKET.equals(uh3)) {
                final int integer5 = mg4.readInt();
                final float float6 = mg4.readFloat();
                final Path czf7 = Path.createFromStream(mg4);
                this.minecraft.debugRenderer.pathfindingRenderer.addPath(integer5, czf7, float6);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_NEIGHBORSUPDATE_PACKET.equals(uh3)) {
                final long long5 = mg4.readVarLong();
                final BlockPos fu7 = mg4.readBlockPos();
                ((NeighborsUpdateRenderer)this.minecraft.debugRenderer.neighborsUpdateRenderer).addUpdate(long5, fu7);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_CAVES_PACKET.equals(uh3)) {
                final BlockPos fu8 = mg4.readBlockPos();
                final int integer6 = mg4.readInt();
                final List<BlockPos> list7 = Lists.newArrayList();
                final List<Float> list8 = Lists.newArrayList();
                for (int integer7 = 0; integer7 < integer6; ++integer7) {
                    list7.add(mg4.readBlockPos());
                    list8.add(mg4.readFloat());
                }
                this.minecraft.debugRenderer.caveRenderer.addTunnel(fu8, list7, list8);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_STRUCTURES_PACKET.equals(uh3)) {
                final DimensionType cif5 = this.registryAccess.dimensionTypes().get(mg4.readResourceLocation());
                final BoundingBox ctd6 = new BoundingBox(mg4.readInt(), mg4.readInt(), mg4.readInt(), mg4.readInt(), mg4.readInt(), mg4.readInt());
                final int integer8 = mg4.readInt();
                final List<BoundingBox> list9 = Lists.newArrayList();
                final List<Boolean> list10 = Lists.newArrayList();
                for (int integer9 = 0; integer9 < integer8; ++integer9) {
                    list9.add(new BoundingBox(mg4.readInt(), mg4.readInt(), mg4.readInt(), mg4.readInt(), mg4.readInt(), mg4.readInt()));
                    list10.add(mg4.readBoolean());
                }
                this.minecraft.debugRenderer.structureRenderer.addBoundingBox(ctd6, list9, list10, cif5);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_WORLDGENATTEMPT_PACKET.equals(uh3)) {
                ((WorldGenAttemptRenderer)this.minecraft.debugRenderer.worldGenAttemptRenderer).addPos(mg4.readBlockPos(), mg4.readFloat(), mg4.readFloat(), mg4.readFloat(), mg4.readFloat(), mg4.readFloat());
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_VILLAGE_SECTIONS.equals(uh3)) {
                for (int integer5 = mg4.readInt(), integer6 = 0; integer6 < integer5; ++integer6) {
                    this.minecraft.debugRenderer.villageSectionsDebugRenderer.setVillageSection(mg4.readSectionPos());
                }
                for (int integer6 = mg4.readInt(), integer8 = 0; integer8 < integer6; ++integer8) {
                    this.minecraft.debugRenderer.villageSectionsDebugRenderer.setNotVillageSection(mg4.readSectionPos());
                }
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_POI_ADDED_PACKET.equals(uh3)) {
                final BlockPos fu8 = mg4.readBlockPos();
                final String string6 = mg4.readUtf();
                final int integer8 = mg4.readInt();
                final BrainDebugRenderer.PoiInfo b8 = new BrainDebugRenderer.PoiInfo(fu8, string6, integer8);
                this.minecraft.debugRenderer.brainDebugRenderer.addPoi(b8);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_POI_REMOVED_PACKET.equals(uh3)) {
                final BlockPos fu8 = mg4.readBlockPos();
                this.minecraft.debugRenderer.brainDebugRenderer.removePoi(fu8);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_POI_TICKET_COUNT_PACKET.equals(uh3)) {
                final BlockPos fu8 = mg4.readBlockPos();
                final int integer6 = mg4.readInt();
                this.minecraft.debugRenderer.brainDebugRenderer.setFreeTicketCount(fu8, integer6);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_GOAL_SELECTOR.equals(uh3)) {
                final BlockPos fu8 = mg4.readBlockPos();
                final int integer6 = mg4.readInt();
                final int integer8 = mg4.readInt();
                final List<GoalSelectorDebugRenderer.DebugGoal> list11 = Lists.newArrayList();
                for (int integer7 = 0; integer7 < integer8; ++integer7) {
                    final int integer9 = mg4.readInt();
                    final boolean boolean11 = mg4.readBoolean();
                    final String string7 = mg4.readUtf(255);
                    list11.add(new GoalSelectorDebugRenderer.DebugGoal(fu8, integer9, string7, boolean11));
                }
                this.minecraft.debugRenderer.goalSelectorRenderer.addGoalSelector(integer6, list11);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_RAIDS.equals(uh3)) {
                final int integer5 = mg4.readInt();
                final Collection<BlockPos> collection6 = Lists.newArrayList();
                for (int integer8 = 0; integer8 < integer5; ++integer8) {
                    collection6.add(mg4.readBlockPos());
                }
                this.minecraft.debugRenderer.raidDebugRenderer.setRaidCenters(collection6);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_BRAIN.equals(uh3)) {
                final double double5 = mg4.readDouble();
                final double double6 = mg4.readDouble();
                final double double7 = mg4.readDouble();
                final Position gj11 = new PositionImpl(double5, double6, double7);
                final UUID uUID12 = mg4.readUUID();
                final int integer10 = mg4.readInt();
                final String string8 = mg4.readUtf();
                final String string9 = mg4.readUtf();
                final int integer11 = mg4.readInt();
                final float float7 = mg4.readFloat();
                final float float8 = mg4.readFloat();
                final String string10 = mg4.readUtf();
                final boolean boolean12 = mg4.readBoolean();
                Path czf8;
                if (boolean12) {
                    czf8 = Path.createFromStream(mg4);
                }
                else {
                    czf8 = null;
                }
                final boolean boolean13 = mg4.readBoolean();
                final BrainDebugRenderer.BrainDump a23 = new BrainDebugRenderer.BrainDump(uUID12, integer10, string8, string9, integer11, float7, float8, gj11, string10, czf8, boolean13);
                for (int integer12 = mg4.readInt(), integer13 = 0; integer13 < integer12; ++integer13) {
                    final String string11 = mg4.readUtf();
                    a23.activities.add(string11);
                }
                for (int integer13 = mg4.readInt(), integer14 = 0; integer14 < integer13; ++integer14) {
                    final String string12 = mg4.readUtf();
                    a23.behaviors.add(string12);
                }
                for (int integer14 = mg4.readInt(), integer15 = 0; integer15 < integer14; ++integer15) {
                    final String string13 = mg4.readUtf();
                    a23.memories.add(string13);
                }
                for (int integer15 = mg4.readInt(), integer16 = 0; integer16 < integer15; ++integer16) {
                    final BlockPos fu9 = mg4.readBlockPos();
                    a23.pois.add(fu9);
                }
                for (int integer16 = mg4.readInt(), integer17 = 0; integer17 < integer16; ++integer17) {
                    final BlockPos fu10 = mg4.readBlockPos();
                    a23.potentialPois.add(fu10);
                }
                for (int integer17 = mg4.readInt(), integer18 = 0; integer18 < integer17; ++integer18) {
                    final String string14 = mg4.readUtf();
                    a23.gossips.add(string14);
                }
                this.minecraft.debugRenderer.brainDebugRenderer.addOrUpdateBrainDump(a23);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_BEE.equals(uh3)) {
                final double double5 = mg4.readDouble();
                final double double6 = mg4.readDouble();
                final double double7 = mg4.readDouble();
                final Position gj11 = new PositionImpl(double5, double6, double7);
                final UUID uUID12 = mg4.readUUID();
                final int integer10 = mg4.readInt();
                final boolean boolean14 = mg4.readBoolean();
                BlockPos fu11 = null;
                if (boolean14) {
                    fu11 = mg4.readBlockPos();
                }
                final boolean boolean15 = mg4.readBoolean();
                BlockPos fu12 = null;
                if (boolean15) {
                    fu12 = mg4.readBlockPos();
                }
                final int integer19 = mg4.readInt();
                final boolean boolean16 = mg4.readBoolean();
                Path czf9 = null;
                if (boolean16) {
                    czf9 = Path.createFromStream(mg4);
                }
                final BeeDebugRenderer.BeeInfo a24 = new BeeDebugRenderer.BeeInfo(uUID12, integer10, gj11, czf9, fu11, fu12, integer19);
                for (int integer20 = mg4.readInt(), integer21 = 0; integer21 < integer20; ++integer21) {
                    final String string15 = mg4.readUtf();
                    a24.goals.add(string15);
                }
                for (int integer21 = mg4.readInt(), integer12 = 0; integer12 < integer21; ++integer12) {
                    final BlockPos fu13 = mg4.readBlockPos();
                    a24.blacklistedHives.add(fu13);
                }
                this.minecraft.debugRenderer.beeDebugRenderer.addOrUpdateBeeInfo(a24);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_HIVE.equals(uh3)) {
                final BlockPos fu8 = mg4.readBlockPos();
                final String string6 = mg4.readUtf();
                final int integer8 = mg4.readInt();
                final int integer22 = mg4.readInt();
                final boolean boolean17 = mg4.readBoolean();
                final BeeDebugRenderer.HiveInfo b9 = new BeeDebugRenderer.HiveInfo(fu8, string6, integer8, integer22, boolean17, this.level.getGameTime());
                this.minecraft.debugRenderer.beeDebugRenderer.addOrUpdateHiveInfo(b9);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_GAME_TEST_CLEAR.equals(uh3)) {
                this.minecraft.debugRenderer.gameTestDebugRenderer.clear();
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_GAME_TEST_ADD_MARKER.equals(uh3)) {
                final BlockPos fu8 = mg4.readBlockPos();
                final int integer6 = mg4.readInt();
                final String string16 = mg4.readUtf();
                final int integer22 = mg4.readInt();
                this.minecraft.debugRenderer.gameTestDebugRenderer.addMarker(fu8, integer6, string16, integer22);
            }
            else {
                ClientPacketListener.LOGGER.warn("Unknown custom packed identifier: {}", uh3);
            }
        }
        finally {
            if (mg4 != null) {
                mg4.release();
            }
        }
    }
    
    @Override
    public void handleAddObjective(final ClientboundSetObjectivePacket qf) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qf, this, this.minecraft);
        final Scoreboard dfm3 = this.level.getScoreboard();
        final String string4 = qf.getObjectiveName();
        if (qf.getMethod() == 0) {
            dfm3.addObjective(string4, ObjectiveCriteria.DUMMY, qf.getDisplayName(), qf.getRenderType());
        }
        else if (dfm3.hasObjective(string4)) {
            final Objective dfj5 = dfm3.getObjective(string4);
            if (qf.getMethod() == 1) {
                dfm3.removeObjective(dfj5);
            }
            else if (qf.getMethod() == 2) {
                dfj5.setRenderType(qf.getRenderType());
                dfj5.setDisplayName(qf.getDisplayName());
            }
        }
    }
    
    @Override
    public void handleSetScore(final ClientboundSetScorePacket qi) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qi, this, this.minecraft);
        final Scoreboard dfm3 = this.level.getScoreboard();
        final String string4 = qi.getObjectiveName();
        switch (qi.getMethod()) {
            case CHANGE: {
                final Objective dfj5 = dfm3.getOrCreateObjective(string4);
                final Score dfl6 = dfm3.getOrCreatePlayerScore(qi.getOwner(), dfj5);
                dfl6.setScore(qi.getScore());
                break;
            }
            case REMOVE: {
                dfm3.resetPlayerScore(qi.getOwner(), dfm3.getObjective(string4));
                break;
            }
        }
    }
    
    @Override
    public void handleSetDisplayObjective(final ClientboundSetDisplayObjectivePacket py) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)py, this, this.minecraft);
        final Scoreboard dfm3 = this.level.getScoreboard();
        final String string4 = py.getObjectiveName();
        final Objective dfj5 = (string4 == null) ? null : dfm3.getOrCreateObjective(string4);
        dfm3.setDisplayObjective(py.getSlot(), dfj5);
    }
    
    @Override
    public void handleSetPlayerTeamPacket(final ClientboundSetPlayerTeamPacket qh) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qh, this, this.minecraft);
        final Scoreboard dfm3 = this.level.getScoreboard();
        PlayerTeam dfk4;
        if (qh.getMethod() == 0) {
            dfk4 = dfm3.addPlayerTeam(qh.getName());
        }
        else {
            dfk4 = dfm3.getPlayerTeam(qh.getName());
        }
        if (qh.getMethod() == 0 || qh.getMethod() == 2) {
            dfk4.setDisplayName(qh.getDisplayName());
            dfk4.setColor(qh.getColor());
            dfk4.unpackOptions(qh.getOptions());
            final Team.Visibility b5 = Team.Visibility.byName(qh.getNametagVisibility());
            if (b5 != null) {
                dfk4.setNameTagVisibility(b5);
            }
            final Team.CollisionRule a6 = Team.CollisionRule.byName(qh.getCollisionRule());
            if (a6 != null) {
                dfk4.setCollisionRule(a6);
            }
            dfk4.setPlayerPrefix(qh.getPlayerPrefix());
            dfk4.setPlayerSuffix(qh.getPlayerSuffix());
        }
        if (qh.getMethod() == 0 || qh.getMethod() == 3) {
            for (final String string6 : qh.getPlayers()) {
                dfm3.addPlayerToTeam(string6, dfk4);
            }
        }
        if (qh.getMethod() == 4) {
            for (final String string6 : qh.getPlayers()) {
                dfm3.removePlayerFromTeam(string6, dfk4);
            }
        }
        if (qh.getMethod() == 1) {
            dfm3.removePlayerTeam(dfk4);
        }
    }
    
    @Override
    public void handleParticleEvent(final ClientboundLevelParticlesPacket ov) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ov, this, this.minecraft);
        if (ov.getCount() == 0) {
            final double double3 = ov.getMaxSpeed() * ov.getXDist();
            final double double4 = ov.getMaxSpeed() * ov.getYDist();
            final double double5 = ov.getMaxSpeed() * ov.getZDist();
            try {
                this.level.addParticle(ov.getParticle(), ov.isOverrideLimiter(), ov.getX(), ov.getY(), ov.getZ(), double3, double4, double5);
            }
            catch (Throwable throwable9) {
                ClientPacketListener.LOGGER.warn("Could not spawn particle effect {}", ov.getParticle());
            }
        }
        else {
            for (int integer3 = 0; integer3 < ov.getCount(); ++integer3) {
                final double double6 = this.random.nextGaussian() * ov.getXDist();
                final double double7 = this.random.nextGaussian() * ov.getYDist();
                final double double8 = this.random.nextGaussian() * ov.getZDist();
                final double double9 = this.random.nextGaussian() * ov.getMaxSpeed();
                final double double10 = this.random.nextGaussian() * ov.getMaxSpeed();
                final double double11 = this.random.nextGaussian() * ov.getMaxSpeed();
                try {
                    this.level.addParticle(ov.getParticle(), ov.isOverrideLimiter(), ov.getX() + double6, ov.getY() + double7, ov.getZ() + double8, double9, double10, double11);
                }
                catch (Throwable throwable10) {
                    ClientPacketListener.LOGGER.warn("Could not spawn particle effect {}", ov.getParticle());
                    return;
                }
            }
        }
    }
    
    @Override
    public void handleUpdateAttributes(final ClientboundUpdateAttributesPacket qt) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)qt, this, this.minecraft);
        final Entity aom3 = this.level.getEntity(qt.getEntityId());
        if (aom3 == null) {
            return;
        }
        if (!(aom3 instanceof LivingEntity)) {
            throw new IllegalStateException("Server tried to update attributes of a non-living entity (actually: " + aom3 + ")");
        }
        final AttributeMap apu4 = ((LivingEntity)aom3).getAttributes();
        for (final ClientboundUpdateAttributesPacket.AttributeSnapshot a6 : qt.getValues()) {
            final AttributeInstance apt7 = apu4.getInstance(a6.getAttribute());
            if (apt7 == null) {
                ClientPacketListener.LOGGER.warn("Entity {} does not have attribute {}", aom3, Registry.ATTRIBUTE.getKey(a6.getAttribute()));
            }
            else {
                apt7.setBaseValue(a6.getBase());
                apt7.removeModifiers();
                for (final AttributeModifier apv9 : a6.getModifiers()) {
                    apt7.addTransientModifier(apv9);
                }
            }
        }
    }
    
    @Override
    public void handlePlaceRecipe(final ClientboundPlaceGhostRecipePacket pf) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pf, this, this.minecraft);
        final AbstractContainerMenu bgi3 = this.minecraft.player.containerMenu;
        if (bgi3.containerId != pf.getContainerId() || !bgi3.isSynched(this.minecraft.player)) {
            return;
        }
        RecipeBookComponent dtn4;
        final AbstractContainerMenu abstractContainerMenu;
        this.recipeManager.byKey(pf.getRecipe()).ifPresent(bmu -> {
            if (this.minecraft.screen instanceof RecipeUpdateListener) {
                dtn4 = ((RecipeUpdateListener)this.minecraft.screen).getRecipeBookComponent();
                dtn4.setupGhostRecipe(bmu, abstractContainerMenu.slots);
            }
        });
    }
    
    @Override
    public void handleLightUpdatePacked(final ClientboundLightUpdatePacket ow) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ow, this, this.minecraft);
        final int integer3 = ow.getX();
        final int integer4 = ow.getZ();
        final LevelLightEngine cwr5 = this.level.getChunkSource().getLightEngine();
        final int integer5 = ow.getSkyYMask();
        final int integer6 = ow.getEmptySkyYMask();
        final Iterator<byte[]> iterator8 = ow.getSkyUpdates().iterator();
        this.readSectionList(integer3, integer4, cwr5, LightLayer.SKY, integer5, integer6, iterator8, ow.getTrustEdges());
        final int integer7 = ow.getBlockYMask();
        final int integer8 = ow.getEmptyBlockYMask();
        final Iterator<byte[]> iterator9 = ow.getBlockUpdates().iterator();
        this.readSectionList(integer3, integer4, cwr5, LightLayer.BLOCK, integer7, integer8, iterator9, ow.getTrustEdges());
    }
    
    @Override
    public void handleMerchantOffers(final ClientboundMerchantOffersPacket oz) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oz, this, this.minecraft);
        final AbstractContainerMenu bgi3 = this.minecraft.player.containerMenu;
        if (oz.getContainerId() == bgi3.containerId && bgi3 instanceof MerchantMenu) {
            ((MerchantMenu)bgi3).setOffers(new MerchantOffers(oz.getOffers().createTag()));
            ((MerchantMenu)bgi3).setXp(oz.getVillagerXp());
            ((MerchantMenu)bgi3).setMerchantLevel(oz.getVillagerLevel());
            ((MerchantMenu)bgi3).setShowProgressBar(oz.showProgress());
            ((MerchantMenu)bgi3).setCanRestock(oz.canRestock());
        }
    }
    
    @Override
    public void handleSetChunkCacheRadius(final ClientboundSetChunkCacheRadiusPacket pw) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pw, this, this.minecraft);
        this.serverChunkRadius = pw.getRadius();
        this.level.getChunkSource().updateViewRadius(pw.getRadius());
    }
    
    @Override
    public void handleSetChunkCacheCenter(final ClientboundSetChunkCacheCenterPacket pv) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pv, this, this.minecraft);
        this.level.getChunkSource().updateViewCenter(pv.getX(), pv.getZ());
    }
    
    @Override
    public void handleBlockBreakAck(final ClientboundBlockBreakAckPacket nt) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nt, this, this.minecraft);
        this.minecraft.gameMode.handleBlockBreakAck(this.level, nt.getPos(), nt.getState(), nt.action(), nt.allGood());
    }
    
    private void readSectionList(final int integer1, final int integer2, final LevelLightEngine cwr, final LightLayer bqi, final int integer5, final int integer6, final Iterator<byte[]> iterator, final boolean boolean8) {
        for (int integer7 = 0; integer7 < 18; ++integer7) {
            final int integer8 = -1 + integer7;
            final boolean boolean9 = (integer5 & 1 << integer7) != 0x0;
            final boolean boolean10 = (integer6 & 1 << integer7) != 0x0;
            if (boolean9 || boolean10) {
                cwr.queueSectionData(bqi, SectionPos.of(integer1, integer8, integer2), boolean9 ? new DataLayer(iterator.next().clone()) : new DataLayer(), boolean8);
                this.level.setSectionDirtyWithNeighbors(integer1, integer8, integer2);
            }
        }
    }
    
    @Override
    public Connection getConnection() {
        return this.connection;
    }
    
    public Collection<PlayerInfo> getOnlinePlayers() {
        return this.playerInfoMap.values();
    }
    
    @Nullable
    public PlayerInfo getPlayerInfo(final UUID uUID) {
        return this.playerInfoMap.get(uUID);
    }
    
    @Nullable
    public PlayerInfo getPlayerInfo(final String string) {
        for (final PlayerInfo dyq4 : this.playerInfoMap.values()) {
            if (dyq4.getProfile().getName().equals(string)) {
                return dyq4;
            }
        }
        return null;
    }
    
    public GameProfile getLocalGameProfile() {
        return this.localGameProfile;
    }
    
    public ClientAdvancements getAdvancements() {
        return this.advancements;
    }
    
    public CommandDispatcher<SharedSuggestionProvider> getCommands() {
        return this.commands;
    }
    
    public ClientLevel getLevel() {
        return this.level;
    }
    
    public TagManager getTags() {
        return this.tags;
    }
    
    public DebugQueryHandler getDebugQueryHandler() {
        return this.debugQueryHandler;
    }
    
    public UUID getId() {
        return this.id;
    }
    
    public Set<ResourceKey<Level>> levels() {
        return this.levels;
    }
    
    public RegistryAccess registryAccess() {
        return this.registryAccess;
    }
    
    static {
        LOGGER = LogManager.getLogger();
    }
}
