package net.minecraft.client.multiplayer;

import org.apache.logging.log4j.LogManager;
import javax.annotation.Nullable;
import net.minecraft.world.level.chunk.DataLayer;
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.world.level.LightLayer;
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.BaseAttributeMap;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.RangedAttribute;
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 java.util.List;
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.VillageDebugRenderer;
import net.minecraft.client.renderer.debug.WorldGenAttemptRenderer;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import com.google.common.collect.Lists;
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.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.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.tags.EntityTypeTags;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.item.Item;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagCollection;
import net.minecraft.tags.BlockTags;
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.network.chat.TranslatableComponent;
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.network.protocol.game.ClientboundSetEquippedItemPacket;
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.world.level.dimension.DimensionType;
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.client.resources.language.I18n;
import net.minecraft.network.protocol.game.ClientboundSetPassengersPacket;
import net.minecraft.network.protocol.game.ClientboundSetSpawnPositionPacket;
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.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.RealmsScreenProxy;
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.core.SectionPos;
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.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.global.LightningBolt;
import net.minecraft.network.protocol.game.ClientboundAddGlobalEntityPacket;
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.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.fishing.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.level.Level;
import net.minecraft.world.entity.vehicle.MinecartChest;
import net.minecraft.world.entity.EntityType;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
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.level.LevelSettings;
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.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 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;
    
    public ClientPacketListener(final Minecraft dbn, final Screen dgb, final Connection kt, 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.minecraft = dbn;
        this.callbackScreen = dgb;
        this.connection = kt;
        this.localGameProfile = gameProfile;
        this.advancements = new ClientAdvancements(dbn);
        this.suggestionsProvider = new ClientSuggestionProvider(this, dbn);
    }
    
    public ClientSuggestionProvider getSuggestionsProvider() {
        return this.suggestionsProvider;
    }
    
    public void cleanup() {
        this.level = null;
    }
    
    public RecipeManager getRecipeManager() {
        return this.recipeManager;
    }
    
    @Override
    public void handleLogin(final ClientboundLoginPacket nj) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nj, this, this.minecraft);
        this.minecraft.gameMode = new MultiPlayerGameMode(this.minecraft, this);
        this.serverChunkRadius = nj.getChunkRadius();
        this.level = new ClientLevel(this, new LevelSettings(nj.getSeed(), nj.getGameType(), false, nj.isHardcore(), nj.getLevelType()), nj.getDimension(), this.serverChunkRadius, this.minecraft.getProfiler(), this.minecraft.levelRenderer);
        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 integer3 = nj.getPlayerId();
        this.level.addPlayer(integer3, 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.player.dimension = nj.getDimension();
        this.minecraft.setScreen(new ReceivingLevelScreen());
        this.minecraft.player.setId(integer3);
        this.minecraft.player.setReducedDebugInfo(nj.isReducedDebugInfo());
        this.minecraft.player.setShowDeathScreen(nj.shouldShowDeathScreen());
        this.minecraft.gameMode.setLocalMode(nj.getGameType());
        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 lx) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)lx, this, this.minecraft);
        final double double3 = lx.getX();
        final double double4 = lx.getY();
        final double double5 = lx.getZ();
        final EntityType<?> aku10 = lx.getType();
        Entity akq9;
        if (aku10 == EntityType.CHEST_MINECART) {
            akq9 = new MinecartChest(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.FURNACE_MINECART) {
            akq9 = new MinecartFurnace(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.TNT_MINECART) {
            akq9 = new MinecartTNT(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.SPAWNER_MINECART) {
            akq9 = new MinecartSpawner(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.HOPPER_MINECART) {
            akq9 = new MinecartHopper(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.COMMAND_BLOCK_MINECART) {
            akq9 = new MinecartCommandBlock(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.MINECART) {
            akq9 = new Minecart(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.FISHING_BOBBER) {
            final Entity akq10 = this.level.getEntity(lx.getData());
            if (akq10 instanceof Player) {
                akq9 = new FishingHook(this.level, (Player)akq10, double3, double4, double5);
            }
            else {
                akq9 = null;
            }
        }
        else if (aku10 == EntityType.ARROW) {
            akq9 = new Arrow(this.level, double3, double4, double5);
            final Entity akq10 = this.level.getEntity(lx.getData());
            if (akq10 != null) {
                ((AbstractArrow)akq9).setOwner(akq10);
            }
        }
        else if (aku10 == EntityType.SPECTRAL_ARROW) {
            akq9 = new SpectralArrow(this.level, double3, double4, double5);
            final Entity akq10 = this.level.getEntity(lx.getData());
            if (akq10 != null) {
                ((AbstractArrow)akq9).setOwner(akq10);
            }
        }
        else if (aku10 == EntityType.TRIDENT) {
            akq9 = new ThrownTrident(this.level, double3, double4, double5);
            final Entity akq10 = this.level.getEntity(lx.getData());
            if (akq10 != null) {
                ((AbstractArrow)akq9).setOwner(akq10);
            }
        }
        else if (aku10 == EntityType.SNOWBALL) {
            akq9 = new Snowball(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.LLAMA_SPIT) {
            akq9 = new LlamaSpit(this.level, double3, double4, double5, lx.getXa(), lx.getYa(), lx.getZa());
        }
        else if (aku10 == EntityType.ITEM_FRAME) {
            akq9 = new ItemFrame(this.level, new BlockPos(double3, double4, double5), Direction.from3DDataValue(lx.getData()));
        }
        else if (aku10 == EntityType.LEASH_KNOT) {
            akq9 = new LeashFenceKnotEntity(this.level, new BlockPos(double3, double4, double5));
        }
        else if (aku10 == EntityType.ENDER_PEARL) {
            akq9 = new ThrownEnderpearl(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.EYE_OF_ENDER) {
            akq9 = new EyeOfEnder(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.FIREWORK_ROCKET) {
            akq9 = new FireworkRocketEntity(this.level, double3, double4, double5, ItemStack.EMPTY);
        }
        else if (aku10 == EntityType.FIREBALL) {
            akq9 = new LargeFireball(this.level, double3, double4, double5, lx.getXa(), lx.getYa(), lx.getZa());
        }
        else if (aku10 == EntityType.DRAGON_FIREBALL) {
            akq9 = new DragonFireball(this.level, double3, double4, double5, lx.getXa(), lx.getYa(), lx.getZa());
        }
        else if (aku10 == EntityType.SMALL_FIREBALL) {
            akq9 = new SmallFireball(this.level, double3, double4, double5, lx.getXa(), lx.getYa(), lx.getZa());
        }
        else if (aku10 == EntityType.WITHER_SKULL) {
            akq9 = new WitherSkull(this.level, double3, double4, double5, lx.getXa(), lx.getYa(), lx.getZa());
        }
        else if (aku10 == EntityType.SHULKER_BULLET) {
            akq9 = new ShulkerBullet(this.level, double3, double4, double5, lx.getXa(), lx.getYa(), lx.getZa());
        }
        else if (aku10 == EntityType.EGG) {
            akq9 = new ThrownEgg(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.EVOKER_FANGS) {
            akq9 = new EvokerFangs(this.level, double3, double4, double5, 0.0f, 0, null);
        }
        else if (aku10 == EntityType.POTION) {
            akq9 = new ThrownPotion(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.EXPERIENCE_BOTTLE) {
            akq9 = new ThrownExperienceBottle(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.BOAT) {
            akq9 = new Boat(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.TNT) {
            akq9 = new PrimedTnt(this.level, double3, double4, double5, null);
        }
        else if (aku10 == EntityType.ARMOR_STAND) {
            akq9 = new ArmorStand(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.END_CRYSTAL) {
            akq9 = new EndCrystal(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.ITEM) {
            akq9 = new ItemEntity(this.level, double3, double4, double5);
        }
        else if (aku10 == EntityType.FALLING_BLOCK) {
            akq9 = new FallingBlockEntity(this.level, double3, double4, double5, Block.stateById(lx.getData()));
        }
        else if (aku10 == EntityType.AREA_EFFECT_CLOUD) {
            akq9 = new AreaEffectCloud(this.level, double3, double4, double5);
        }
        else {
            akq9 = null;
        }
        if (akq9 != null) {
            final int integer11 = lx.getId();
            akq9.setPacketCoordinates(double3, double4, double5);
            akq9.xRot = lx.getxRot() * 360 / 256.0f;
            akq9.yRot = lx.getyRot() * 360 / 256.0f;
            akq9.setId(integer11);
            akq9.setUUID(lx.getUUID());
            this.level.putNonPlayerEntity(integer11, akq9);
            if (akq9 instanceof AbstractMinecart) {
                this.minecraft.getSoundManager().play(new MinecartSoundInstance((AbstractMinecart)akq9));
            }
        }
    }
    
    @Override
    public void handleAddExperienceOrb(final ClientboundAddExperienceOrbPacket ly) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ly, this, this.minecraft);
        final double double3 = ly.getX();
        final double double4 = ly.getY();
        final double double5 = ly.getZ();
        final Entity akq9 = new ExperienceOrb(this.level, double3, double4, double5, ly.getValue());
        akq9.setPacketCoordinates(double3, double4, double5);
        akq9.yRot = 0.0f;
        akq9.xRot = 0.0f;
        akq9.setId(ly.getId());
        this.level.putNonPlayerEntity(ly.getId(), akq9);
    }
    
    @Override
    public void handleAddGlobalEntity(final ClientboundAddGlobalEntityPacket lz) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)lz, this, this.minecraft);
        final double double3 = lz.getX();
        final double double4 = lz.getY();
        final double double5 = lz.getZ();
        if (lz.getType() == 1) {
            final LightningBolt avy9 = new LightningBolt(this.level, double3, double4, double5, false);
            avy9.setPacketCoordinates(double3, double4, double5);
            avy9.yRot = 0.0f;
            avy9.xRot = 0.0f;
            avy9.setId(lz.getId());
            this.level.addLightning(avy9);
        }
    }
    
    @Override
    public void handleAddPainting(final ClientboundAddPaintingPacket mb) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mb, this, this.minecraft);
        final Painting avu3 = new Painting(this.level, mb.getPos(), mb.getDirection(), mb.getMotive());
        avu3.setId(mb.getId());
        avu3.setUUID(mb.getUUID());
        this.level.putNonPlayerEntity(mb.getId(), avu3);
    }
    
    @Override
    public void handleSetEntityMotion(final ClientboundSetEntityMotionPacket om) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)om, this, this.minecraft);
        final Entity akq3 = this.level.getEntity(om.getId());
        if (akq3 == null) {
            return;
        }
        akq3.lerpMotion(om.getXa() / 8000.0, om.getYa() / 8000.0, om.getZa() / 8000.0);
    }
    
    @Override
    public void handleSetEntityData(final ClientboundSetEntityDataPacket ok) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ok, this, this.minecraft);
        final Entity akq3 = this.level.getEntity(ok.getId());
        if (akq3 != null && ok.getUnpackedData() != null) {
            akq3.getEntityData().assignValues(ok.getUnpackedData());
        }
    }
    
    @Override
    public void handleAddPlayer(final ClientboundAddPlayerPacket mc) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mc, this, this.minecraft);
        final double double3 = mc.getX();
        final double double4 = mc.getY();
        final double double5 = mc.getZ();
        final float float9 = mc.getyRot() * 360 / 256.0f;
        final float float10 = mc.getxRot() * 360 / 256.0f;
        final int integer11 = mc.getEntityId();
        final RemotePlayer dqc12 = new RemotePlayer(this.minecraft.level, this.getPlayerInfo(mc.getPlayerId()).getProfile());
        dqc12.setId(integer11);
        dqc12.setPosAndOldPos(double3, double4, double5);
        dqc12.setPacketCoordinates(double3, double4, double5);
        dqc12.absMoveTo(double3, double4, double5, float9, float10);
        this.level.addPlayer(integer11, dqc12);
    }
    
    @Override
    public void handleTeleportEntity(final ClientboundTeleportEntityPacket pd) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pd, this, this.minecraft);
        final Entity akq3 = this.level.getEntity(pd.getId());
        if (akq3 == null) {
            return;
        }
        final double double4 = pd.getX();
        final double double5 = pd.getY();
        final double double6 = pd.getZ();
        akq3.setPacketCoordinates(double4, double5, double6);
        if (!akq3.isControlledByLocalInstance()) {
            final float float10 = pd.getyRot() * 360 / 256.0f;
            final float float11 = pd.getxRot() * 360 / 256.0f;
            if (Math.abs(akq3.getX() - double4) >= 0.03125 || Math.abs(akq3.getY() - double5) >= 0.015625 || Math.abs(akq3.getZ() - double6) >= 0.03125) {
                akq3.lerpTo(double4, double5, double6, float10, float11, 3, true);
            }
            else {
                akq3.lerpTo(akq3.getX(), akq3.getY(), akq3.getZ(), float10, float11, 3, true);
            }
            akq3.onGround = pd.isOnGround();
        }
    }
    
    @Override
    public void handleSetCarriedItem(final ClientboundSetCarriedItemPacket og) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)og, this, this.minecraft);
        if (Inventory.isHotbarSlot(og.getSlot())) {
            this.minecraft.player.inventory.selected = og.getSlot();
        }
    }
    
    @Override
    public void handleMoveEntity(final ClientboundMoveEntityPacket nm) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nm, this, this.minecraft);
        final Entity akq3 = nm.getEntity(this.level);
        if (akq3 == null) {
            return;
        }
        if (!akq3.isControlledByLocalInstance()) {
            if (nm.hasPosition()) {
                final Entity entity = akq3;
                entity.xp += nm.getXa();
                final Entity entity2 = akq3;
                entity2.yp += nm.getYa();
                final Entity entity3 = akq3;
                entity3.zp += nm.getZa();
                final Vec3 cvl4 = ClientboundMoveEntityPacket.packetToEntity(akq3.xp, akq3.yp, akq3.zp);
                final float float5 = nm.hasRotation() ? (nm.getyRot() * 360 / 256.0f) : akq3.yRot;
                final float float6 = nm.hasRotation() ? (nm.getxRot() * 360 / 256.0f) : akq3.xRot;
                akq3.lerpTo(cvl4.x, cvl4.y, cvl4.z, float5, float6, 3, false);
            }
            else if (nm.hasRotation()) {
                final float float7 = nm.getyRot() * 360 / 256.0f;
                final float float5 = nm.getxRot() * 360 / 256.0f;
                akq3.lerpTo(akq3.getX(), akq3.getY(), akq3.getZ(), float7, float5, 3, false);
            }
            akq3.onGround = nm.isOnGround();
        }
    }
    
    @Override
    public void handleRotateMob(final ClientboundRotateHeadPacket oc) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oc, this, this.minecraft);
        final Entity akq3 = oc.getEntity(this.level);
        if (akq3 == null) {
            return;
        }
        final float float4 = oc.getYHeadRot() * 360 / 256.0f;
        akq3.lerpHeadTo(float4, 3);
    }
    
    @Override
    public void handleRemoveEntity(final ClientboundRemoveEntitiesPacket ny) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ny, this, this.minecraft);
        for (int integer3 = 0; integer3 < ny.getEntityIds().length; ++integer3) {
            final int integer4 = ny.getEntityIds()[integer3];
            this.level.removeEntity(integer4);
        }
    }
    
    @Override
    public void handleMovePlayer(final ClientboundPlayerPositionPacket nw) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nw, this, this.minecraft);
        final Player ayj3 = this.minecraft.player;
        final Vec3 cvl4 = ayj3.getDeltaMovement();
        final boolean boolean5 = nw.getRelativeArguments().contains(ClientboundPlayerPositionPacket.RelativeArgument.X);
        final boolean boolean6 = nw.getRelativeArguments().contains(ClientboundPlayerPositionPacket.RelativeArgument.Y);
        final boolean boolean7 = nw.getRelativeArguments().contains(ClientboundPlayerPositionPacket.RelativeArgument.Z);
        double double8;
        double double9;
        if (boolean5) {
            double8 = cvl4.x();
            double9 = ayj3.getX() + nw.getX();
            ayj3.xOld += nw.getX();
        }
        else {
            double8 = 0.0;
            double9 = nw.getX();
            ayj3.xOld = double9;
        }
        double double10;
        double double11;
        if (boolean6) {
            double10 = cvl4.y();
            double11 = ayj3.getY() + nw.getY();
            ayj3.yOld += nw.getY();
        }
        else {
            double10 = 0.0;
            double11 = nw.getY();
            ayj3.yOld = double11;
        }
        double double12;
        double double13;
        if (boolean7) {
            double12 = cvl4.z();
            double13 = ayj3.getZ() + nw.getZ();
            ayj3.zOld += nw.getZ();
        }
        else {
            double12 = 0.0;
            double13 = nw.getZ();
            ayj3.zOld = double13;
        }
        ayj3.setPosRaw(double9, double11, double13);
        ayj3.xo = double9;
        ayj3.yo = double11;
        ayj3.zo = double13;
        ayj3.setDeltaMovement(double8, double10, double12);
        float float20 = nw.getYRot();
        float float21 = nw.getXRot();
        if (nw.getRelativeArguments().contains(ClientboundPlayerPositionPacket.RelativeArgument.X_ROT)) {
            float21 += ayj3.xRot;
        }
        if (nw.getRelativeArguments().contains(ClientboundPlayerPositionPacket.RelativeArgument.Y_ROT)) {
            float20 += ayj3.yRot;
        }
        ayj3.absMoveTo(double9, double11, double13, float20, float21);
        this.connection.send(new ServerboundAcceptTeleportationPacket(nw.getId()));
        this.connection.send(new ServerboundMovePlayerPacket.PosRot(ayj3.getX(), ayj3.getY(), ayj3.getZ(), ayj3.yRot, ayj3.xRot, false));
        if (!this.started) {
            this.started = true;
            this.minecraft.setScreen(null);
        }
    }
    
    @Override
    public void handleChunkBlocksUpdate(final ClientboundChunkBlocksUpdatePacket mn) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mn, this, this.minecraft);
        for (final ClientboundChunkBlocksUpdatePacket.BlockUpdate a6 : mn.getUpdates()) {
            this.level.setKnownState(a6.getPos(), a6.getBlock());
        }
    }
    
    @Override
    public void handleLevelChunk(final ClientboundLevelChunkPacket nf) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nf, this, this.minecraft);
        final int integer3 = nf.getX();
        final int integer4 = nf.getZ();
        final LevelChunk cal5 = this.level.getChunkSource().replaceWithPacketData(integer3, integer4, nf.getBiomes(), nf.getReadBuffer(), nf.getHeightmaps(), nf.getAvailableSections());
        if (cal5 != null && nf.isFullChunk()) {
            this.level.reAddEntitiesToChunk(cal5);
        }
        for (int integer5 = 0; integer5 < 16; ++integer5) {
            this.level.setSectionDirtyWithNeighbors(integer3, integer5, integer4);
        }
        for (final CompoundTag jt7 : nf.getBlockEntitiesTags()) {
            final BlockPos fk8 = new BlockPos(jt7.getInt("x"), jt7.getInt("y"), jt7.getInt("z"));
            final BlockEntity bwl9 = this.level.getBlockEntity(fk8);
            if (bwl9 != null) {
                bwl9.load(jt7);
            }
        }
    }
    
    @Override
    public void handleForgetLevelChunk(final ClientboundForgetLevelChunkPacket nb) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nb, this, this.minecraft);
        final int integer3 = nb.getX();
        final int integer4 = nb.getZ();
        final ClientChunkCache dnm5 = this.level.getChunkSource();
        dnm5.drop(integer3, integer4);
        final LevelLightEngine coa6 = dnm5.getLightEngine();
        for (int integer5 = 0; integer5 < 16; ++integer5) {
            this.level.setSectionDirtyWithNeighbors(integer3, integer5, integer4);
            coa6.updateSectionStatus(SectionPos.of(integer3, integer5, integer4), true);
        }
        coa6.enableLightSources(new ChunkPos(integer3, integer4), false);
    }
    
    @Override
    public void handleBlockUpdate(final ClientboundBlockUpdatePacket mj) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mj, this, this.minecraft);
        this.level.setKnownState(mj.getPos(), mj.getBlockState());
    }
    
    @Override
    public void handleDisconnect(final ClientboundDisconnectPacket my) {
        this.connection.disconnect(my.getReason());
    }
    
    @Override
    public void onDisconnect(final Component lf) {
        this.minecraft.clearLevel();
        if (this.callbackScreen != null) {
            if (this.callbackScreen instanceof RealmsScreenProxy) {
                this.minecraft.setScreen(new DisconnectedRealmsScreen(((RealmsScreenProxy)this.callbackScreen).getScreen(), "disconnect.lost", lf).getProxy());
            }
            else {
                this.minecraft.setScreen(new DisconnectedScreen(this.callbackScreen, "disconnect.lost", lf));
            }
        }
        else {
            this.minecraft.setScreen(new DisconnectedScreen(new JoinMultiplayerScreen(new TitleScreen()), "disconnect.lost", lf));
        }
    }
    
    public void send(final Packet<?> lt) {
        this.connection.send(lt);
    }
    
    @Override
    public void handleTakeItemEntity(final ClientboundTakeItemEntityPacket pc) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pc, this, this.minecraft);
        final Entity akq3 = this.level.getEntity(pc.getItemId());
        LivingEntity akz4 = (LivingEntity)this.level.getEntity(pc.getPlayerId());
        if (akz4 == null) {
            akz4 = this.minecraft.player;
        }
        if (akq3 != null) {
            if (akq3 instanceof ExperienceOrb) {
                this.level.playLocalSound(akq3.getX(), akq3.getY(), akq3.getZ(), SoundEvents.EXPERIENCE_ORB_PICKUP, SoundSource.PLAYERS, 0.1f, (this.random.nextFloat() - this.random.nextFloat()) * 0.35f + 0.9f, false);
            }
            else {
                this.level.playLocalSound(akq3.getX(), akq3.getY(), akq3.getZ(), SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, 0.2f, (this.random.nextFloat() - this.random.nextFloat()) * 1.4f + 2.0f, false);
            }
            if (akq3 instanceof ItemEntity) {
                ((ItemEntity)akq3).getItem().setCount(pc.getAmount());
            }
            this.minecraft.particleEngine.add(new ItemPickupParticle(this.minecraft.getEntityRenderDispatcher(), this.minecraft.renderBuffers(), this.level, akq3, akz4));
            this.level.removeEntity(pc.getItemId());
        }
    }
    
    @Override
    public void handleChat(final ClientboundChatPacket mm) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mm, this, this.minecraft);
        this.minecraft.gui.handleChat(mm.getType(), mm.getMessage());
    }
    
    @Override
    public void handleAnimate(final ClientboundAnimatePacket md) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)md, this, this.minecraft);
        final Entity akq3 = this.level.getEntity(md.getId());
        if (akq3 == null) {
            return;
        }
        if (md.getAction() == 0) {
            final LivingEntity akz4 = (LivingEntity)akq3;
            akz4.swing(InteractionHand.MAIN_HAND);
        }
        else if (md.getAction() == 3) {
            final LivingEntity akz4 = (LivingEntity)akq3;
            akz4.swing(InteractionHand.OFF_HAND);
        }
        else if (md.getAction() == 1) {
            akq3.animateHurt();
        }
        else if (md.getAction() == 2) {
            final Player ayj4 = (Player)akq3;
            ayj4.stopSleepInBed(false, false);
        }
        else if (md.getAction() == 4) {
            this.minecraft.particleEngine.createTrackingEmitter(akq3, ParticleTypes.CRIT);
        }
        else if (md.getAction() == 5) {
            this.minecraft.particleEngine.createTrackingEmitter(akq3, ParticleTypes.ENCHANTED_HIT);
        }
    }
    
    @Override
    public void handleAddMob(final ClientboundAddMobPacket ma) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ma, this, this.minecraft);
        final double double3 = ma.getX();
        final double double4 = ma.getY();
        final double double5 = ma.getZ();
        final float float9 = ma.getyRot() * 360 / 256.0f;
        final float float10 = ma.getxRot() * 360 / 256.0f;
        final LivingEntity akz11 = (LivingEntity)EntityType.create(ma.getType(), this.minecraft.level);
        if (akz11 != null) {
            akz11.setPacketCoordinates(double3, double4, double5);
            akz11.yBodyRot = ma.getyHeadRot() * 360 / 256.0f;
            akz11.yHeadRot = ma.getyHeadRot() * 360 / 256.0f;
            if (akz11 instanceof EnderDragon) {
                final EnderDragonPart[] arr12 = ((EnderDragon)akz11).getSubEntities();
                for (int integer13 = 0; integer13 < arr12.length; ++integer13) {
                    arr12[integer13].setId(integer13 + ma.getId());
                }
            }
            akz11.setId(ma.getId());
            akz11.setUUID(ma.getUUID());
            akz11.absMoveTo(double3, double4, double5, float9, float10);
            akz11.setDeltaMovement(ma.getXd() / 8000.0f, ma.getYd() / 8000.0f, ma.getZd() / 8000.0f);
            this.level.putNonPlayerEntity(ma.getId(), akz11);
            if (akz11 instanceof Bee) {
                final boolean boolean12 = ((Bee)akz11).isAngry();
                BeeSoundInstance eco13;
                if (boolean12) {
                    eco13 = new BeeAggressiveSoundInstance((Bee)akz11);
                }
                else {
                    eco13 = new BeeFlyingSoundInstance((Bee)akz11);
                }
                this.minecraft.getSoundManager().play(eco13);
            }
        }
        else {
            ClientPacketListener.LOGGER.warn("Skipping Entity with id {}", ma.getType());
        }
    }
    
    @Override
    public void handleSetTime(final ClientboundSetTimePacket ov) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ov, this, this.minecraft);
        this.minecraft.level.setGameTime(ov.getGameTime());
        this.minecraft.level.setDayTime(ov.getDayTime());
    }
    
    @Override
    public void handleSetSpawn(final ClientboundSetSpawnPositionPacket ou) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ou, this, this.minecraft);
        this.minecraft.player.setRespawnPosition(ou.getPos(), true, false);
        this.minecraft.level.getLevelData().setSpawn(ou.getPos());
    }
    
    @Override
    public void handleSetEntityPassengersPacket(final ClientboundSetPassengersPacket or) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)or, this, this.minecraft);
        final Entity akq3 = this.level.getEntity(or.getVehicle());
        if (akq3 == null) {
            ClientPacketListener.LOGGER.warn("Received passengers for unknown entity");
            return;
        }
        final boolean boolean4 = akq3.hasIndirectPassenger(this.minecraft.player);
        akq3.ejectPassengers();
        for (final int integer8 : or.getPassengers()) {
            final Entity akq4 = this.level.getEntity(integer8);
            if (akq4 != null) {
                akq4.startRiding(akq3, true);
                if (akq4 == this.minecraft.player && !boolean4) {
                    this.minecraft.gui.setOverlayMessage(I18n.get("mount.onboard", this.minecraft.options.keyShift.getTranslatedKeyMessage()), false);
                }
            }
        }
    }
    
    @Override
    public void handleEntityLinkPacket(final ClientboundSetEntityLinkPacket ol) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ol, this, this.minecraft);
        final Entity akq3 = this.level.getEntity(ol.getSourceId());
        if (akq3 instanceof Mob) {
            ((Mob)akq3).setDelayedLeashHolderId(ol.getDestId());
        }
    }
    
    private static ItemStack findTotem(final Player ayj) {
        for (final InteractionHand ajk5 : InteractionHand.values()) {
            final ItemStack ben6 = ayj.getItemInHand(ajk5);
            if (ben6.getItem() == Items.TOTEM_OF_UNDYING) {
                return ben6;
            }
        }
        return new ItemStack(Items.TOTEM_OF_UNDYING);
    }
    
    @Override
    public void handleEntityEvent(final ClientboundEntityEventPacket mz) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mz, this, this.minecraft);
        final Entity akq3 = mz.getEntity(this.level);
        if (akq3 != null) {
            if (mz.getEventId() == 21) {
                this.minecraft.getSoundManager().play(new GuardianAttackSoundInstance((Guardian)akq3));
            }
            else if (mz.getEventId() == 35) {
                final int integer4 = 40;
                this.minecraft.particleEngine.createTrackingEmitter(akq3, ParticleTypes.TOTEM_OF_UNDYING, 30);
                this.level.playLocalSound(akq3.getX(), akq3.getY(), akq3.getZ(), SoundEvents.TOTEM_USE, akq3.getSoundSource(), 1.0f, 1.0f, false);
                if (akq3 == this.minecraft.player) {
                    this.minecraft.gameRenderer.displayItemActivation(findTotem(this.minecraft.player));
                }
            }
            else {
                akq3.handleEntityEvent(mz.getEventId());
            }
        }
    }
    
    @Override
    public void handleSetHealth(final ClientboundSetHealthPacket op) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)op, this, this.minecraft);
        this.minecraft.player.hurtTo(op.getHealth());
        this.minecraft.player.getFoodData().setFoodLevel(op.getFood());
        this.minecraft.player.getFoodData().setSaturation(op.getSaturation());
    }
    
    @Override
    public void handleSetExperience(final ClientboundSetExperiencePacket oo) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oo, this, this.minecraft);
        this.minecraft.player.setExperienceValues(oo.getExperienceProgress(), oo.getTotalExperience(), oo.getExperienceLevel());
    }
    
    @Override
    public void handleRespawn(final ClientboundRespawnPacket ob) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ob, this, this.minecraft);
        final DimensionType cbi3 = ob.getDimension();
        final LocalPlayer dqb4 = this.minecraft.player;
        final int integer5 = dqb4.getId();
        if (cbi3 != dqb4.dimension) {
            this.started = false;
            final Scoreboard cwl6 = this.level.getScoreboard();
            (this.level = new ClientLevel(this, new LevelSettings(ob.getSeed(), ob.getPlayerGameType(), false, this.minecraft.level.getLevelData().isHardcore(), ob.getLevelType()), ob.getDimension(), this.serverChunkRadius, this.minecraft.getProfiler(), this.minecraft.levelRenderer)).setScoreboard(cwl6);
            this.minecraft.setLevel(this.level);
            this.minecraft.setScreen(new ReceivingLevelScreen());
        }
        this.level.validateSpawn();
        this.level.removeAllPendingEntityRemovals();
        final String string6 = dqb4.getServerBrand();
        this.minecraft.cameraEntity = null;
        final LocalPlayer dqb5 = this.minecraft.gameMode.createPlayer(this.level, dqb4.getStats(), dqb4.getRecipeBook());
        dqb5.setId(integer5);
        dqb5.dimension = cbi3;
        this.minecraft.player = dqb5;
        this.minecraft.cameraEntity = dqb5;
        dqb5.getEntityData().assignValues(dqb4.getEntityData().getAll());
        dqb5.getAttributes().assignValues(dqb4.getAttributes());
        dqb5.resetPos();
        dqb5.setServerBrand(string6);
        this.level.addPlayer(integer5, dqb5);
        dqb5.yRot = -180.0f;
        dqb5.input = new KeyboardInput(this.minecraft.options);
        this.minecraft.gameMode.adjustPlayer(dqb5);
        dqb5.setReducedDebugInfo(dqb4.isReducedDebugInfo());
        dqb5.setShowDeathScreen(dqb4.shouldShowDeathScreen());
        if (this.minecraft.screen instanceof DeathScreen) {
            this.minecraft.setScreen(null);
        }
        this.minecraft.gameMode.setLocalMode(ob.getPlayerGameType());
    }
    
    @Override
    public void handleExplosion(final ClientboundExplodePacket na) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)na, this, this.minecraft);
        final Explosion bjp3 = new Explosion(this.minecraft.level, null, na.getX(), na.getY(), na.getZ(), na.getPower(), na.getToBlow());
        bjp3.finalizeExplosion(true);
        this.minecraft.player.setDeltaMovement(this.minecraft.player.getDeltaMovement().add(na.getKnockbackX(), na.getKnockbackY(), na.getKnockbackZ()));
    }
    
    @Override
    public void handleHorseScreenOpen(final ClientboundHorseScreenOpenPacket nd) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nd, this, this.minecraft);
        final Entity akq3 = this.level.getEntity(nd.getEntityId());
        if (akq3 instanceof AbstractHorse) {
            final LocalPlayer dqb4 = this.minecraft.player;
            final AbstractHorse aue5 = (AbstractHorse)akq3;
            final SimpleContainer ajq6 = new SimpleContainer(nd.getSize());
            final HorseInventoryMenu bbj7 = new HorseInventoryMenu(nd.getContainerId(), dqb4.inventory, ajq6, aue5);
            dqb4.containerMenu = bbj7;
            this.minecraft.setScreen(new HorseInventoryScreen(bbj7, dqb4.inventory, aue5));
        }
    }
    
    @Override
    public void handleOpenScreen(final ClientboundOpenScreenPacket np) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)np, this, this.minecraft);
        MenuScreens.create(np.getType(), this.minecraft, np.getContainerId(), np.getTitle());
    }
    
    @Override
    public void handleContainerSetSlot(final ClientboundContainerSetSlotPacket mu) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mu, this, this.minecraft);
        final Player ayj3 = this.minecraft.player;
        final ItemStack ben4 = mu.getItem();
        final int integer5 = mu.getSlot();
        this.minecraft.getTutorial().onGetItem(ben4);
        if (mu.getContainerId() == -1) {
            if (!(this.minecraft.screen instanceof CreativeModeInventoryScreen)) {
                ayj3.inventory.setCarried(ben4);
            }
        }
        else if (mu.getContainerId() == -2) {
            ayj3.inventory.setItem(integer5, ben4);
        }
        else {
            boolean boolean6 = false;
            if (this.minecraft.screen instanceof CreativeModeInventoryScreen) {
                final CreativeModeInventoryScreen dhi7 = (CreativeModeInventoryScreen)this.minecraft.screen;
                boolean6 = (dhi7.getSelectedTab() != CreativeModeTab.TAB_INVENTORY.getId());
            }
            if (mu.getContainerId() == 0 && mu.getSlot() >= 36 && integer5 < 45) {
                if (!ben4.isEmpty()) {
                    final ItemStack ben5 = ayj3.inventoryMenu.getSlot(integer5).getItem();
                    if (ben5.isEmpty() || ben5.getCount() < ben4.getCount()) {
                        ben4.setPopTime(5);
                    }
                }
                ayj3.inventoryMenu.setItem(integer5, ben4);
            }
            else if (mu.getContainerId() == ayj3.containerMenu.containerId && (mu.getContainerId() != 0 || !boolean6)) {
                ayj3.containerMenu.setItem(integer5, ben4);
            }
        }
    }
    
    @Override
    public void handleContainerAck(final ClientboundContainerAckPacket mq) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mq, this, this.minecraft);
        AbstractContainerMenu ban3 = null;
        final Player ayj4 = this.minecraft.player;
        if (mq.getContainerId() == 0) {
            ban3 = ayj4.inventoryMenu;
        }
        else if (mq.getContainerId() == ayj4.containerMenu.containerId) {
            ban3 = ayj4.containerMenu;
        }
        if (ban3 != null && !mq.isAccepted()) {
            this.send(new ServerboundContainerAckPacket(mq.getContainerId(), mq.getUid(), true));
        }
    }
    
    @Override
    public void handleContainerContent(final ClientboundContainerSetContentPacket ms) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ms, this, this.minecraft);
        final Player ayj3 = this.minecraft.player;
        if (ms.getContainerId() == 0) {
            ayj3.inventoryMenu.setAll(ms.getItems());
        }
        else if (ms.getContainerId() == ayj3.containerMenu.containerId) {
            ayj3.containerMenu.setAll(ms.getItems());
        }
    }
    
    @Override
    public void handleOpenSignEditor(final ClientboundOpenSignEditorPacket nq) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nq, this, this.minecraft);
        BlockEntity bwl3 = this.level.getBlockEntity(nq.getPos());
        if (!(bwl3 instanceof SignBlockEntity)) {
            bwl3 = new SignBlockEntity();
            bwl3.setLevelAndPosition(this.level, nq.getPos());
        }
        this.minecraft.player.openTextEdit((SignBlockEntity)bwl3);
    }
    
    @Override
    public void handleBlockEntityData(final ClientboundBlockEntityDataPacket mh) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mh, this, this.minecraft);
        if (this.minecraft.level.hasChunkAt(mh.getPos())) {
            final BlockEntity bwl3 = this.minecraft.level.getBlockEntity(mh.getPos());
            final int integer4 = mh.getType();
            final boolean boolean5 = integer4 == 2 && bwl3 instanceof CommandBlockEntity;
            if ((integer4 == 1 && bwl3 instanceof SpawnerBlockEntity) || boolean5 || (integer4 == 3 && bwl3 instanceof BeaconBlockEntity) || (integer4 == 4 && bwl3 instanceof SkullBlockEntity) || (integer4 == 6 && bwl3 instanceof BannerBlockEntity) || (integer4 == 7 && bwl3 instanceof StructureBlockEntity) || (integer4 == 8 && bwl3 instanceof TheEndGatewayBlockEntity) || (integer4 == 9 && bwl3 instanceof SignBlockEntity) || (integer4 == 11 && bwl3 instanceof BedBlockEntity) || (integer4 == 5 && bwl3 instanceof ConduitBlockEntity) || (integer4 == 12 && bwl3 instanceof JigsawBlockEntity) || (integer4 == 13 && bwl3 instanceof CampfireBlockEntity) || (integer4 == 14 && bwl3 instanceof BeehiveBlockEntity)) {
                bwl3.load(mh.getTag());
            }
            if (boolean5 && this.minecraft.screen instanceof CommandBlockEditScreen) {
                ((CommandBlockEditScreen)this.minecraft.screen).updateGui();
            }
        }
    }
    
    @Override
    public void handleContainerSetData(final ClientboundContainerSetDataPacket mt) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mt, this, this.minecraft);
        final Player ayj3 = this.minecraft.player;
        if (ayj3.containerMenu != null && ayj3.containerMenu.containerId == mt.getContainerId()) {
            ayj3.containerMenu.setData(mt.getId(), mt.getValue());
        }
    }
    
    @Override
    public void handleSetEquippedItem(final ClientboundSetEquippedItemPacket on) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)on, this, this.minecraft);
        final Entity akq3 = this.level.getEntity(on.getEntity());
        if (akq3 != null) {
            akq3.setItemSlot(on.getSlot(), on.getItem());
        }
    }
    
    @Override
    public void handleContainerClose(final ClientboundContainerClosePacket mr) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mr, this, this.minecraft);
        this.minecraft.player.clientSideCloseContainer();
    }
    
    @Override
    public void handleBlockEvent(final ClientboundBlockEventPacket mi) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mi, this, this.minecraft);
        this.minecraft.level.blockEvent(mi.getPos(), mi.getBlock(), mi.getB0(), mi.getB1());
    }
    
    @Override
    public void handleBlockDestruction(final ClientboundBlockDestructionPacket mg) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mg, this, this.minecraft);
        this.minecraft.level.destroyBlockProgress(mg.getId(), mg.getPos(), mg.getProgress());
    }
    
    @Override
    public void handleGameEvent(final ClientboundGameEventPacket nc) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nc, this, this.minecraft);
        final Player ayj3 = this.minecraft.player;
        final int integer4 = nc.getEvent();
        final float float5 = nc.getParam();
        final int integer5 = Mth.floor(float5 + 0.5f);
        if (integer4 >= 0 && integer4 < ClientboundGameEventPacket.EVENT_LANGUAGE_ID.length && ClientboundGameEventPacket.EVENT_LANGUAGE_ID[integer4] != null) {
            ayj3.displayClientMessage(new TranslatableComponent(ClientboundGameEventPacket.EVENT_LANGUAGE_ID[integer4], new Object[0]), false);
        }
        if (integer4 == 1) {
            this.level.getLevelData().setRaining(true);
            this.level.setRainLevel(0.0f);
        }
        else if (integer4 == 2) {
            this.level.getLevelData().setRaining(false);
            this.level.setRainLevel(1.0f);
        }
        else if (integer4 == 3) {
            this.minecraft.gameMode.setLocalMode(GameType.byId(integer5));
        }
        else if (integer4 == 4) {
            if (integer5 == 0) {
                this.minecraft.player.connection.send(new ServerboundClientCommandPacket(ServerboundClientCommandPacket.Action.PERFORM_RESPAWN));
                this.minecraft.setScreen(new ReceivingLevelScreen());
            }
            else if (integer5 == 1) {
                this.minecraft.setScreen(new WinScreen(true, () -> this.minecraft.player.connection.send(new ServerboundClientCommandPacket(ServerboundClientCommandPacket.Action.PERFORM_RESPAWN))));
            }
        }
        else if (integer4 == 5) {
            final Options dbr7 = 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[] { dbr7.keyUp.getTranslatedKeyMessage(), dbr7.keyLeft.getTranslatedKeyMessage(), dbr7.keyDown.getTranslatedKeyMessage(), dbr7.keyRight.getTranslatedKeyMessage() }));
            }
            else if (float5 == 102.0f) {
                this.minecraft.gui.getChat().addMessage(new TranslatableComponent("demo.help.jump", new Object[] { dbr7.keyJump.getTranslatedKeyMessage() }));
            }
            else if (float5 == 103.0f) {
                this.minecraft.gui.getChat().addMessage(new TranslatableComponent("demo.help.inventory", new Object[] { dbr7.keyInventory.getTranslatedKeyMessage() }));
            }
            else if (float5 == 104.0f) {
                this.minecraft.gui.getChat().addMessage(new TranslatableComponent("demo.day.6", new Object[] { dbr7.keyScreenshot.getTranslatedKeyMessage() }));
            }
        }
        else if (integer4 == 6) {
            this.level.playSound(ayj3, ayj3.getX(), ayj3.getEyeY(), ayj3.getZ(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.18f, 0.45f);
        }
        else if (integer4 == 7) {
            this.level.setRainLevel(float5);
        }
        else if (integer4 == 8) {
            this.level.setThunderLevel(float5);
        }
        else if (integer4 == 9) {
            this.level.playSound(ayj3, ayj3.getX(), ayj3.getY(), ayj3.getZ(), SoundEvents.PUFFER_FISH_STING, SoundSource.NEUTRAL, 1.0f, 1.0f);
        }
        else if (integer4 == 10) {
            this.level.addParticle(ParticleTypes.ELDER_GUARDIAN, ayj3.getX(), ayj3.getY(), ayj3.getZ(), 0.0, 0.0, 0.0);
            this.level.playSound(ayj3, ayj3.getX(), ayj3.getY(), ayj3.getZ(), SoundEvents.ELDER_GUARDIAN_CURSE, SoundSource.HOSTILE, 1.0f, 1.0f);
        }
        else if (integer4 == 11) {
            this.minecraft.player.setShowDeathScreen(float5 == 0.0f);
        }
    }
    
    @Override
    public void handleMapItemData(final ClientboundMapItemDataPacket nk) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nk, this, this.minecraft);
        final MapRenderer dck3 = this.minecraft.gameRenderer.getMapRenderer();
        final String string4 = MapItem.makeKey(nk.getMapId());
        MapItemSavedData crg5 = this.minecraft.level.getMapData(string4);
        if (crg5 == null) {
            crg5 = new MapItemSavedData(string4);
            if (dck3.getMapInstanceIfExists(string4) != null) {
                final MapItemSavedData crg6 = dck3.getData(dck3.getMapInstanceIfExists(string4));
                if (crg6 != null) {
                    crg5 = crg6;
                }
            }
            this.minecraft.level.setMapData(crg5);
        }
        nk.applyToMap(crg5);
        dck3.update(crg5);
    }
    
    @Override
    public void handleLevelEvent(final ClientboundLevelEventPacket ng) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ng, this, this.minecraft);
        if (ng.isGlobalEvent()) {
            this.minecraft.level.globalLevelEvent(ng.getType(), ng.getPos(), ng.getData());
        }
        else {
            this.minecraft.level.levelEvent(ng.getType(), ng.getPos(), ng.getData());
        }
    }
    
    @Override
    public void handleUpdateAdvancementsPacket(final ClientboundUpdateAdvancementsPacket pe) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pe, this, this.minecraft);
        this.advancements.update(pe);
    }
    
    @Override
    public void handleSelectAdvancementsTab(final ClientboundSelectAdvancementsTabPacket od) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)od, this, this.minecraft);
        final ResourceLocation sm3 = od.getTab();
        if (sm3 == null) {
            this.advancements.setSelectedTab(null, false);
        }
        else {
            final Advancement u4 = this.advancements.getAdvancements().get(sm3);
            this.advancements.setSelectedTab(u4, false);
        }
    }
    
    @Override
    public void handleCommands(final ClientboundCommandsPacket mp) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mp, this, this.minecraft);
        this.commands = (CommandDispatcher<SharedSuggestionProvider>)new CommandDispatcher((RootCommandNode)mp.getRoot());
    }
    
    @Override
    public void handleStopSoundEvent(final ClientboundStopSoundPacket oz) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oz, this, this.minecraft);
        this.minecraft.getSoundManager().stop(oz.getName(), oz.getSource());
    }
    
    @Override
    public void handleCommandSuggestions(final ClientboundCommandSuggestionsPacket mo) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mo, this, this.minecraft);
        this.suggestionsProvider.completeCustomSuggestions(mo.getId(), mo.getSuggestions());
    }
    
    @Override
    public void handleUpdateRecipes(final ClientboundUpdateRecipesPacket ph) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ph, this, this.minecraft);
        this.recipeManager.replaceRecipes(ph.getRecipes());
        final MutableSearchTree<RecipeCollection> ede3 = this.minecraft.<RecipeCollection>getSearchTree(SearchRegistry.RECIPE_COLLECTIONS);
        ede3.clear();
        final ClientRecipeBook dbc4 = this.minecraft.player.getRecipeBook();
        dbc4.setupCollections();
        dbc4.getCollections().forEach(ede3::add);
        ede3.refresh();
    }
    
    @Override
    public void handleLookAt(final ClientboundPlayerLookAtPacket nv) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nv, this, this.minecraft);
        final Vec3 cvl3 = nv.getPosition(this.level);
        if (cvl3 != null) {
            this.minecraft.player.lookAt(nv.getFromAnchor(), cvl3);
        }
    }
    
    @Override
    public void handleTagQueryPacket(final ClientboundTagQueryPacket pb) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pb, this, this.minecraft);
        if (!this.debugQueryHandler.handleResponse(pb.getTransactionId(), pb.getTag())) {
            ClientPacketListener.LOGGER.debug("Got unhandled response to tag query {}", pb.getTransactionId());
        }
    }
    
    @Override
    public void handleAwardStats(final ClientboundAwardStatsPacket me) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)me, this, this.minecraft);
        for (final Map.Entry<Stat<?>, Integer> entry4 : me.getStats().entrySet()) {
            final Stat<?> aao5 = entry4.getKey();
            final int integer6 = entry4.getValue();
            this.minecraft.player.getStats().setValue(this.minecraft.player, aao5, integer6);
        }
        if (this.minecraft.screen instanceof StatsUpdateListener) {
            ((StatsUpdateListener)this.minecraft.screen).onStatsUpdated();
        }
    }
    
    @Override
    public void handleAddOrRemoveRecipes(final ClientboundRecipePacket nx) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nx, this, this.minecraft);
        final ClientRecipeBook dbc3 = this.minecraft.player.getRecipeBook();
        dbc3.setGuiOpen(nx.isGuiOpen());
        dbc3.setFilteringCraftable(nx.isFilteringCraftable());
        dbc3.setFurnaceGuiOpen(nx.isFurnaceGuiOpen());
        dbc3.setFurnaceFilteringCraftable(nx.isFurnaceFilteringCraftable());
        final ClientboundRecipePacket.State a4 = nx.getState();
        switch (a4) {
            case REMOVE: {
                for (final ResourceLocation sm6 : nx.getRecipes()) {
                    this.recipeManager.byKey(sm6).ifPresent(dbc3::remove);
                }
                break;
            }
            case INIT: {
                for (final ResourceLocation sm6 : nx.getRecipes()) {
                    this.recipeManager.byKey(sm6).ifPresent(dbc3::add);
                }
                for (final ResourceLocation sm6 : nx.getHighlights()) {
                    this.recipeManager.byKey(sm6).ifPresent(dbc3::addHighlight);
                }
                break;
            }
            case ADD: {
                for (final ResourceLocation sm6 : nx.getRecipes()) {
                    final RecipeBook recipeBook;
                    this.recipeManager.byKey(sm6).ifPresent(bgw -> {
                        recipeBook.add(bgw);
                        recipeBook.addHighlight(bgw);
                        RecipeToast.addOrUpdate(this.minecraft.getToasts(), bgw);
                        return;
                    });
                }
                break;
            }
        }
        dbc3.getCollections().forEach(dit -> dit.updateKnownRecipes(dbc3));
        if (this.minecraft.screen instanceof RecipeUpdateListener) {
            ((RecipeUpdateListener)this.minecraft.screen).recipesUpdated();
        }
    }
    
    @Override
    public void handleUpdateMobEffect(final ClientboundUpdateMobEffectPacket pg) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pg, this, this.minecraft);
        final Entity akq3 = this.level.getEntity(pg.getEntityId());
        if (!(akq3 instanceof LivingEntity)) {
            return;
        }
        final MobEffect aki4 = MobEffect.byId(pg.getEffectId());
        if (aki4 == null) {
            return;
        }
        final MobEffectInstance akk5 = new MobEffectInstance(aki4, pg.getEffectDurationTicks(), pg.getEffectAmplifier(), pg.isEffectAmbient(), pg.isEffectVisible(), pg.effectShowsIcon());
        akk5.setNoCounter(pg.isSuperLongDuration());
        ((LivingEntity)akq3).addEffect(akk5);
    }
    
    @Override
    public void handleUpdateTags(final ClientboundUpdateTagsPacket pi) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pi, this, this.minecraft);
        this.tags = pi.getTags();
        if (!this.connection.isMemoryConnection()) {
            BlockTags.reset(this.tags.getBlocks());
            ItemTags.reset(this.tags.getItems());
            FluidTags.reset(this.tags.getFluids());
            EntityTypeTags.reset(this.tags.getEntityTypes());
        }
        this.minecraft.<ItemStack>getSearchTree(SearchRegistry.CREATIVE_TAGS).refresh();
    }
    
    @Override
    public void handlePlayerCombat(final ClientboundPlayerCombatPacket nt) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nt, this, this.minecraft);
        if (nt.event == ClientboundPlayerCombatPacket.Event.ENTITY_DIED) {
            final Entity akq3 = this.level.getEntity(nt.playerId);
            if (akq3 == this.minecraft.player) {
                if (this.minecraft.player.shouldShowDeathScreen()) {
                    this.minecraft.setScreen(new DeathScreen(nt.message, this.level.getLevelData().isHardcore()));
                }
                else {
                    this.minecraft.player.respawn();
                }
            }
        }
    }
    
    @Override
    public void handleChangeDifficulty(final ClientboundChangeDifficultyPacket ml) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ml, this, this.minecraft);
        this.minecraft.level.getLevelData().setDifficulty(ml.getDifficulty());
        this.minecraft.level.getLevelData().setDifficultyLocked(ml.isLocked());
    }
    
    @Override
    public void handleSetCamera(final ClientboundSetCameraPacket of) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)of, this, this.minecraft);
        final Entity akq3 = of.getEntity(this.level);
        if (akq3 != null) {
            this.minecraft.setCameraEntity(akq3);
        }
    }
    
    @Override
    public void handleSetBorder(final ClientboundSetBorderPacket oe) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oe, this, this.minecraft);
        oe.applyChanges(this.level.getWorldBorder());
    }
    
    @Override
    public void handleSetTitles(final ClientboundSetTitlesPacket ow) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ow, this, this.minecraft);
        final ClientboundSetTitlesPacket.Type a3 = ow.getType();
        String string4 = null;
        String string5 = null;
        final String string6 = (ow.getText() != null) ? ow.getText().getColoredString() : "";
        switch (a3) {
            case TITLE: {
                string4 = string6;
                break;
            }
            case SUBTITLE: {
                string5 = string6;
                break;
            }
            case ACTIONBAR: {
                this.minecraft.gui.setOverlayMessage(string6, false);
                return;
            }
            case RESET: {
                this.minecraft.gui.setTitles("", "", -1, -1, -1);
                this.minecraft.gui.resetTitleTimes();
                return;
            }
        }
        this.minecraft.gui.setTitles(string4, string5, ow.getFadeInTime(), ow.getStayTime(), ow.getFadeOutTime());
    }
    
    @Override
    public void handleTabListCustomisation(final ClientboundTabListPacket pa) {
        this.minecraft.gui.getTabList().setHeader(pa.getHeader().getColoredString().isEmpty() ? null : pa.getHeader());
        this.minecraft.gui.getTabList().setFooter(pa.getFooter().getColoredString().isEmpty() ? null : pa.getFooter());
    }
    
    @Override
    public void handleRemoveMobEffect(final ClientboundRemoveMobEffectPacket nz) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nz, this, this.minecraft);
        final Entity akq3 = nz.getEntity(this.level);
        if (akq3 instanceof LivingEntity) {
            ((LivingEntity)akq3).removeEffectNoUpdate(nz.getEffect());
        }
    }
    
    @Override
    public void handlePlayerInfo(final ClientboundPlayerInfoPacket nu) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nu, this, this.minecraft);
        for (final ClientboundPlayerInfoPacket.PlayerUpdate b4 : nu.getEntries()) {
            if (nu.getAction() == ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER) {
                this.playerInfoMap.remove(b4.getProfile().getId());
            }
            else {
                PlayerInfo dns5 = this.playerInfoMap.get(b4.getProfile().getId());
                if (nu.getAction() == ClientboundPlayerInfoPacket.Action.ADD_PLAYER) {
                    dns5 = new PlayerInfo(b4);
                    this.playerInfoMap.put(dns5.getProfile().getId(), dns5);
                }
                if (dns5 == null) {
                    continue;
                }
                switch (nu.getAction()) {
                    case ADD_PLAYER: {
                        dns5.setGameMode(b4.getGameMode());
                        dns5.setLatency(b4.getLatency());
                        dns5.setTabListDisplayName(b4.getDisplayName());
                        continue;
                    }
                    case UPDATE_GAME_MODE: {
                        dns5.setGameMode(b4.getGameMode());
                        continue;
                    }
                    case UPDATE_LATENCY: {
                        dns5.setLatency(b4.getLatency());
                        continue;
                    }
                    case UPDATE_DISPLAY_NAME: {
                        dns5.setTabListDisplayName(b4.getDisplayName());
                        continue;
                    }
                }
            }
        }
    }
    
    @Override
    public void handleKeepAlive(final ClientboundKeepAlivePacket ne) {
        this.send(new ServerboundKeepAlivePacket(ne.getId()));
    }
    
    @Override
    public void handlePlayerAbilities(final ClientboundPlayerAbilitiesPacket ns) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ns, this, this.minecraft);
        final Player ayj3 = this.minecraft.player;
        ayj3.abilities.flying = ns.isFlying();
        ayj3.abilities.instabuild = ns.canInstabuild();
        ayj3.abilities.invulnerable = ns.isInvulnerable();
        ayj3.abilities.mayfly = ns.canFly();
        ayj3.abilities.setFlyingSpeed(ns.getFlyingSpeed());
        ayj3.abilities.setWalkingSpeed(ns.getWalkingSpeed());
    }
    
    @Override
    public void handleSoundEvent(final ClientboundSoundPacket oy) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oy, this, this.minecraft);
        this.minecraft.level.playSound(this.minecraft.player, oy.getX(), oy.getY(), oy.getZ(), oy.getSound(), oy.getSource(), oy.getVolume(), oy.getPitch());
    }
    
    @Override
    public void handleSoundEntityEvent(final ClientboundSoundEntityPacket ox) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ox, this, this.minecraft);
        final Entity akq3 = this.level.getEntity(ox.getId());
        if (akq3 == null) {
            return;
        }
        this.minecraft.level.playSound(this.minecraft.player, akq3, ox.getSound(), ox.getSource(), ox.getVolume(), ox.getPitch());
    }
    
    @Override
    public void handleCustomSoundEvent(final ClientboundCustomSoundPacket mx) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mx, this, this.minecraft);
        this.minecraft.getSoundManager().play(new SimpleSoundInstance(mx.getName(), mx.getSource(), mx.getVolume(), mx.getPitch(), false, 0, SoundInstance.Attenuation.LINEAR, (float)mx.getX(), (float)mx.getY(), (float)mx.getZ(), false));
    }
    
    @Override
    public void handleResourcePack(final ClientboundResourcePackPacket oa) {
        final String string3 = oa.getUrl();
        final String string4 = oa.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);
                    this.downloadCallback(completableFuture8);
                    return;
                }
            }
            catch (UnsupportedEncodingException ex) {}
            this.send(ServerboundResourcePackPacket.Action.FAILED_DOWNLOAD);
            return;
        }
        final ServerData dnu5 = this.minecraft.getCurrentServer();
        if (dnu5 != null && dnu5.getResourcePackStatus() == ServerData.ServerPackStatus.ENABLED) {
            this.send(ServerboundResourcePackPacket.Action.ACCEPTED);
            this.downloadCallback(this.minecraft.getClientPackSource().downloadAndSelectResourcePack(string3, string4));
        }
        else if (dnu5 == null || dnu5.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 dnu5 = this.minecraft.getCurrentServer();
                    if (boolean3) {
                        if (dnu5 != null) {
                            dnu5.setResourcePackStatus(ServerData.ServerPackStatus.ENABLED);
                        }
                        this.send(ServerboundResourcePackPacket.Action.ACCEPTED);
                        this.downloadCallback(this.minecraft.getClientPackSource().downloadAndSelectResourcePack(o, o2));
                    }
                    else {
                        if (dnu5 != null) {
                            dnu5.setResourcePackStatus(ServerData.ServerPackStatus.DISABLED);
                        }
                        this.send(ServerboundResourcePackPacket.Action.DECLINED);
                    }
                    ServerList.saveSingleServer(dnu5);
                    this.minecraft.setScreen(null);
                }, new TranslatableComponent("multiplayer.texturePrompt.line1", new Object[0]), new TranslatableComponent("multiplayer.texturePrompt.line2", new Object[0]));
                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 mk) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mk, this, this.minecraft);
        this.minecraft.gui.getBossOverlay().update(mk);
    }
    
    @Override
    public void handleItemCooldown(final ClientboundCooldownPacket mv) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mv, this, this.minecraft);
        if (mv.getDuration() == 0) {
            this.minecraft.player.getCooldowns().removeCooldown(mv.getItem());
        }
        else {
            this.minecraft.player.getCooldowns().addCooldown(mv.getItem(), mv.getDuration());
        }
    }
    
    @Override
    public void handleMoveVehicle(final ClientboundMoveVehiclePacket nn) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nn, this, this.minecraft);
        final Entity akq3 = this.minecraft.player.getRootVehicle();
        if (akq3 != this.minecraft.player && akq3.isControlledByLocalInstance()) {
            akq3.absMoveTo(nn.getX(), nn.getY(), nn.getZ(), nn.getYRot(), nn.getXRot());
            this.connection.send(new ServerboundMoveVehiclePacket(akq3));
        }
    }
    
    @Override
    public void handleOpenBook(final ClientboundOpenBookPacket no) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)no, this, this.minecraft);
        final ItemStack ben3 = this.minecraft.player.getItemInHand(no.getHand());
        if (ben3.getItem() == Items.WRITTEN_BOOK) {
            this.minecraft.setScreen(new BookViewScreen(new BookViewScreen.WrittenBookAccess(ben3)));
        }
    }
    
    @Override
    public void handleCustomPayload(final ClientboundCustomPayloadPacket mw) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mw, this, this.minecraft);
        final ResourceLocation sm3 = mw.getIdentifier();
        FriendlyByteBuf kv4 = null;
        try {
            kv4 = mw.getData();
            if (ClientboundCustomPayloadPacket.BRAND.equals(sm3)) {
                this.minecraft.player.setServerBrand(kv4.readUtf(32767));
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_PATHFINDING_PACKET.equals(sm3)) {
                final int integer5 = kv4.readInt();
                final float float6 = kv4.readFloat();
                final Path cqq7 = Path.createFromStream(kv4);
                this.minecraft.debugRenderer.pathfindingRenderer.addPath(integer5, cqq7, float6);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_NEIGHBORSUPDATE_PACKET.equals(sm3)) {
                final long long5 = kv4.readVarLong();
                final BlockPos fk7 = kv4.readBlockPos();
                ((NeighborsUpdateRenderer)this.minecraft.debugRenderer.neighborsUpdateRenderer).addUpdate(long5, fk7);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_CAVES_PACKET.equals(sm3)) {
                final BlockPos fk8 = kv4.readBlockPos();
                final int integer6 = kv4.readInt();
                final List<BlockPos> list7 = Lists.newArrayList();
                final List<Float> list8 = Lists.newArrayList();
                for (int integer7 = 0; integer7 < integer6; ++integer7) {
                    list7.add(kv4.readBlockPos());
                    list8.add(kv4.readFloat());
                }
                this.minecraft.debugRenderer.caveRenderer.addTunnel(fk8, list7, list8);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_STRUCTURES_PACKET.equals(sm3)) {
                final DimensionType cbi5 = DimensionType.getById(kv4.readInt());
                final BoundingBox clb6 = new BoundingBox(kv4.readInt(), kv4.readInt(), kv4.readInt(), kv4.readInt(), kv4.readInt(), kv4.readInt());
                final int integer8 = kv4.readInt();
                final List<BoundingBox> list9 = Lists.newArrayList();
                final List<Boolean> list10 = Lists.newArrayList();
                for (int integer9 = 0; integer9 < integer8; ++integer9) {
                    list9.add(new BoundingBox(kv4.readInt(), kv4.readInt(), kv4.readInt(), kv4.readInt(), kv4.readInt(), kv4.readInt()));
                    list10.add(kv4.readBoolean());
                }
                this.minecraft.debugRenderer.structureRenderer.addBoundingBox(clb6, list9, list10, cbi5);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_WORLDGENATTEMPT_PACKET.equals(sm3)) {
                ((WorldGenAttemptRenderer)this.minecraft.debugRenderer.worldGenAttemptRenderer).addPos(kv4.readBlockPos(), kv4.readFloat(), kv4.readFloat(), kv4.readFloat(), kv4.readFloat(), kv4.readFloat());
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_VILLAGE_SECTIONS.equals(sm3)) {
                for (int integer5 = kv4.readInt(), integer6 = 0; integer6 < integer5; ++integer6) {
                    this.minecraft.debugRenderer.villageDebugRenderer.setVillageSection(kv4.readSectionPos());
                }
                for (int integer6 = kv4.readInt(), integer8 = 0; integer8 < integer6; ++integer8) {
                    this.minecraft.debugRenderer.villageDebugRenderer.setNotVillageSection(kv4.readSectionPos());
                }
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_POI_ADDED_PACKET.equals(sm3)) {
                final BlockPos fk8 = kv4.readBlockPos();
                final String string6 = kv4.readUtf();
                final int integer8 = kv4.readInt();
                final VillageDebugRenderer.PoiInfo b8 = new VillageDebugRenderer.PoiInfo(fk8, string6, integer8);
                this.minecraft.debugRenderer.villageDebugRenderer.addPoi(b8);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_POI_REMOVED_PACKET.equals(sm3)) {
                final BlockPos fk8 = kv4.readBlockPos();
                this.minecraft.debugRenderer.villageDebugRenderer.removePoi(fk8);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_POI_TICKET_COUNT_PACKET.equals(sm3)) {
                final BlockPos fk8 = kv4.readBlockPos();
                final int integer6 = kv4.readInt();
                this.minecraft.debugRenderer.villageDebugRenderer.setFreeTicketCount(fk8, integer6);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_GOAL_SELECTOR.equals(sm3)) {
                final BlockPos fk8 = kv4.readBlockPos();
                final int integer6 = kv4.readInt();
                final int integer8 = kv4.readInt();
                final List<GoalSelectorDebugRenderer.DebugGoal> list11 = Lists.newArrayList();
                for (int integer7 = 0; integer7 < integer8; ++integer7) {
                    final int integer9 = kv4.readInt();
                    final boolean boolean11 = kv4.readBoolean();
                    final String string7 = kv4.readUtf(255);
                    list11.add(new GoalSelectorDebugRenderer.DebugGoal(fk8, integer9, string7, boolean11));
                }
                this.minecraft.debugRenderer.goalSelectorRenderer.addGoalSelector(integer6, list11);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_RAIDS.equals(sm3)) {
                final int integer5 = kv4.readInt();
                final Collection<BlockPos> collection6 = Lists.newArrayList();
                for (int integer8 = 0; integer8 < integer5; ++integer8) {
                    collection6.add(kv4.readBlockPos());
                }
                this.minecraft.debugRenderer.raidDebugRenderer.setRaidCenters(collection6);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_BRAIN.equals(sm3)) {
                final double double5 = kv4.readDouble();
                final double double6 = kv4.readDouble();
                final double double7 = kv4.readDouble();
                final Position fz11 = new PositionImpl(double5, double6, double7);
                final UUID uUID12 = kv4.readUUID();
                final int integer10 = kv4.readInt();
                final String string8 = kv4.readUtf();
                final String string9 = kv4.readUtf();
                final int integer11 = kv4.readInt();
                final String string10 = kv4.readUtf();
                final boolean boolean12 = kv4.readBoolean();
                Path cqq8;
                if (boolean12) {
                    cqq8 = Path.createFromStream(kv4);
                }
                else {
                    cqq8 = null;
                }
                final boolean boolean13 = kv4.readBoolean();
                final VillageDebugRenderer.BrainDump a21 = new VillageDebugRenderer.BrainDump(uUID12, integer10, string8, string9, integer11, fz11, string10, cqq8, boolean13);
                for (int integer12 = kv4.readInt(), integer13 = 0; integer13 < integer12; ++integer13) {
                    final String string11 = kv4.readUtf();
                    a21.activities.add(string11);
                }
                for (int integer13 = kv4.readInt(), integer14 = 0; integer14 < integer13; ++integer14) {
                    final String string12 = kv4.readUtf();
                    a21.behaviors.add(string12);
                }
                for (int integer14 = kv4.readInt(), integer15 = 0; integer15 < integer14; ++integer15) {
                    final String string13 = kv4.readUtf();
                    a21.memories.add(string13);
                }
                for (int integer15 = kv4.readInt(), integer16 = 0; integer16 < integer15; ++integer16) {
                    final BlockPos fk9 = kv4.readBlockPos();
                    a21.pois.add(fk9);
                }
                for (int integer16 = kv4.readInt(), integer17 = 0; integer17 < integer16; ++integer17) {
                    final String string14 = kv4.readUtf();
                    a21.gossips.add(string14);
                }
                this.minecraft.debugRenderer.villageDebugRenderer.addOrUpdateBrainDump(a21);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_BEE.equals(sm3)) {
                final double double5 = kv4.readDouble();
                final double double6 = kv4.readDouble();
                final double double7 = kv4.readDouble();
                final Position fz11 = new PositionImpl(double5, double6, double7);
                final UUID uUID12 = kv4.readUUID();
                final int integer10 = kv4.readInt();
                final boolean boolean14 = kv4.readBoolean();
                BlockPos fk10 = null;
                if (boolean14) {
                    fk10 = kv4.readBlockPos();
                }
                final boolean boolean15 = kv4.readBoolean();
                BlockPos fk11 = null;
                if (boolean15) {
                    fk11 = kv4.readBlockPos();
                }
                final int integer18 = kv4.readInt();
                final boolean boolean16 = kv4.readBoolean();
                Path cqq9 = null;
                if (boolean16) {
                    cqq9 = Path.createFromStream(kv4);
                }
                final BeeDebugRenderer.BeeInfo a22 = new BeeDebugRenderer.BeeInfo(uUID12, integer10, fz11, cqq9, fk10, fk11, integer18);
                for (int integer12 = kv4.readInt(), integer13 = 0; integer13 < integer12; ++integer13) {
                    final String string11 = kv4.readUtf();
                    a22.goals.add(string11);
                }
                for (int integer13 = kv4.readInt(), integer14 = 0; integer14 < integer13; ++integer14) {
                    final BlockPos fk12 = kv4.readBlockPos();
                    a22.blacklistedHives.add(fk12);
                }
                this.minecraft.debugRenderer.beeDebugRenderer.addOrUpdateBeeInfo(a22);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_HIVE.equals(sm3)) {
                final BlockPos fk8 = kv4.readBlockPos();
                final String string6 = kv4.readUtf();
                final int integer8 = kv4.readInt();
                final int integer19 = kv4.readInt();
                final boolean boolean17 = kv4.readBoolean();
                final BeeDebugRenderer.HiveInfo b9 = new BeeDebugRenderer.HiveInfo(fk8, string6, integer8, integer19, boolean17, this.level.getGameTime());
                this.minecraft.debugRenderer.beeDebugRenderer.addOrUpdateHiveInfo(b9);
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_GAME_TEST_CLEAR.equals(sm3)) {
                this.minecraft.debugRenderer.gameTestDebugRenderer.clear();
            }
            else if (ClientboundCustomPayloadPacket.DEBUG_GAME_TEST_ADD_MARKER.equals(sm3)) {
                final BlockPos fk8 = kv4.readBlockPos();
                final int integer6 = kv4.readInt();
                final String string15 = kv4.readUtf();
                final int integer19 = kv4.readInt();
                this.minecraft.debugRenderer.gameTestDebugRenderer.addMarker(fk8, integer6, string15, integer19);
            }
            else {
                ClientPacketListener.LOGGER.warn("Unknown custom packed identifier: {}", sm3);
            }
        }
        finally {
            if (kv4 != null) {
                kv4.release();
            }
        }
    }
    
    @Override
    public void handleAddObjective(final ClientboundSetObjectivePacket oq) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oq, this, this.minecraft);
        final Scoreboard cwl3 = this.level.getScoreboard();
        final String string4 = oq.getObjectiveName();
        if (oq.getMethod() == 0) {
            cwl3.addObjective(string4, ObjectiveCriteria.DUMMY, oq.getDisplayName(), oq.getRenderType());
        }
        else if (cwl3.hasObjective(string4)) {
            final Objective cwi5 = cwl3.getObjective(string4);
            if (oq.getMethod() == 1) {
                cwl3.removeObjective(cwi5);
            }
            else if (oq.getMethod() == 2) {
                cwi5.setRenderType(oq.getRenderType());
                cwi5.setDisplayName(oq.getDisplayName());
            }
        }
    }
    
    @Override
    public void handleSetScore(final ClientboundSetScorePacket ot) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ot, this, this.minecraft);
        final Scoreboard cwl3 = this.level.getScoreboard();
        final String string4 = ot.getObjectiveName();
        switch (ot.getMethod()) {
            case CHANGE: {
                final Objective cwi5 = cwl3.getOrCreateObjective(string4);
                final Score cwk6 = cwl3.getOrCreatePlayerScore(ot.getOwner(), cwi5);
                cwk6.setScore(ot.getScore());
                break;
            }
            case REMOVE: {
                cwl3.resetPlayerScore(ot.getOwner(), cwl3.getObjective(string4));
                break;
            }
        }
    }
    
    @Override
    public void handleSetDisplayObjective(final ClientboundSetDisplayObjectivePacket oj) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oj, this, this.minecraft);
        final Scoreboard cwl3 = this.level.getScoreboard();
        final String string4 = oj.getObjectiveName();
        final Objective cwi5 = (string4 == null) ? null : cwl3.getOrCreateObjective(string4);
        cwl3.setDisplayObjective(oj.getSlot(), cwi5);
    }
    
    @Override
    public void handleSetPlayerTeamPacket(final ClientboundSetPlayerTeamPacket os) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)os, this, this.minecraft);
        final Scoreboard cwl3 = this.level.getScoreboard();
        PlayerTeam cwj4;
        if (os.getMethod() == 0) {
            cwj4 = cwl3.addPlayerTeam(os.getName());
        }
        else {
            cwj4 = cwl3.getPlayerTeam(os.getName());
        }
        if (os.getMethod() == 0 || os.getMethod() == 2) {
            cwj4.setDisplayName(os.getDisplayName());
            cwj4.setColor(os.getColor());
            cwj4.unpackOptions(os.getOptions());
            final Team.Visibility b5 = Team.Visibility.byName(os.getNametagVisibility());
            if (b5 != null) {
                cwj4.setNameTagVisibility(b5);
            }
            final Team.CollisionRule a6 = Team.CollisionRule.byName(os.getCollisionRule());
            if (a6 != null) {
                cwj4.setCollisionRule(a6);
            }
            cwj4.setPlayerPrefix(os.getPlayerPrefix());
            cwj4.setPlayerSuffix(os.getPlayerSuffix());
        }
        if (os.getMethod() == 0 || os.getMethod() == 3) {
            for (final String string6 : os.getPlayers()) {
                cwl3.addPlayerToTeam(string6, cwj4);
            }
        }
        if (os.getMethod() == 4) {
            for (final String string6 : os.getPlayers()) {
                cwl3.removePlayerFromTeam(string6, cwj4);
            }
        }
        if (os.getMethod() == 1) {
            cwl3.removePlayerTeam(cwj4);
        }
    }
    
    @Override
    public void handleParticleEvent(final ClientboundLevelParticlesPacket nh) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nh, this, this.minecraft);
        if (nh.getCount() == 0) {
            final double double3 = nh.getMaxSpeed() * nh.getXDist();
            final double double4 = nh.getMaxSpeed() * nh.getYDist();
            final double double5 = nh.getMaxSpeed() * nh.getZDist();
            try {
                this.level.addParticle(nh.getParticle(), nh.isOverrideLimiter(), nh.getX(), nh.getY(), nh.getZ(), double3, double4, double5);
            }
            catch (Throwable throwable9) {
                ClientPacketListener.LOGGER.warn("Could not spawn particle effect {}", nh.getParticle());
            }
        }
        else {
            for (int integer3 = 0; integer3 < nh.getCount(); ++integer3) {
                final double double6 = this.random.nextGaussian() * nh.getXDist();
                final double double7 = this.random.nextGaussian() * nh.getYDist();
                final double double8 = this.random.nextGaussian() * nh.getZDist();
                final double double9 = this.random.nextGaussian() * nh.getMaxSpeed();
                final double double10 = this.random.nextGaussian() * nh.getMaxSpeed();
                final double double11 = this.random.nextGaussian() * nh.getMaxSpeed();
                try {
                    this.level.addParticle(nh.getParticle(), nh.isOverrideLimiter(), nh.getX() + double6, nh.getY() + double7, nh.getZ() + double8, double9, double10, double11);
                }
                catch (Throwable throwable10) {
                    ClientPacketListener.LOGGER.warn("Could not spawn particle effect {}", nh.getParticle());
                    return;
                }
            }
        }
    }
    
    @Override
    public void handleUpdateAttributes(final ClientboundUpdateAttributesPacket pf) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)pf, this, this.minecraft);
        final Entity akq3 = this.level.getEntity(pf.getEntityId());
        if (akq3 == null) {
            return;
        }
        if (!(akq3 instanceof LivingEntity)) {
            throw new IllegalStateException("Server tried to update attributes of a non-living entity (actually: " + akq3 + ")");
        }
        final BaseAttributeMap alu4 = ((LivingEntity)akq3).getAttributes();
        for (final ClientboundUpdateAttributesPacket.AttributeSnapshot a6 : pf.getValues()) {
            AttributeInstance alr7 = alu4.getInstance(a6.getName());
            if (alr7 == null) {
                alr7 = alu4.registerAttribute(new RangedAttribute(null, a6.getName(), 0.0, Double.MIN_NORMAL, Double.MAX_VALUE));
            }
            alr7.setBaseValue(a6.getBase());
            alr7.removeModifiers();
            for (final AttributeModifier als9 : a6.getModifiers()) {
                alr7.addModifier(als9);
            }
        }
    }
    
    @Override
    public void handlePlaceRecipe(final ClientboundPlaceGhostRecipePacket nr) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nr, this, this.minecraft);
        final AbstractContainerMenu ban3 = this.minecraft.player.containerMenu;
        if (ban3.containerId != nr.getContainerId() || !ban3.isSynched(this.minecraft.player)) {
            return;
        }
        RecipeBookComponent dip4;
        final AbstractContainerMenu abstractContainerMenu;
        this.recipeManager.byKey(nr.getRecipe()).ifPresent(bgw -> {
            if (this.minecraft.screen instanceof RecipeUpdateListener) {
                dip4 = ((RecipeUpdateListener)this.minecraft.screen).getRecipeBookComponent();
                dip4.setupGhostRecipe(bgw, abstractContainerMenu.slots);
            }
        });
    }
    
    @Override
    public void handleLightUpdatePacked(final ClientboundLightUpdatePacket ni) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)ni, this, this.minecraft);
        final int integer3 = ni.getX();
        final int integer4 = ni.getZ();
        final LevelLightEngine coa5 = this.level.getChunkSource().getLightEngine();
        final int integer5 = ni.getSkyYMask();
        final int integer6 = ni.getEmptySkyYMask();
        final Iterator<byte[]> iterator8 = ni.getSkyUpdates().iterator();
        this.readSectionList(integer3, integer4, coa5, LightLayer.SKY, integer5, integer6, iterator8);
        final int integer7 = ni.getBlockYMask();
        final int integer8 = ni.getEmptyBlockYMask();
        final Iterator<byte[]> iterator9 = ni.getBlockUpdates().iterator();
        this.readSectionList(integer3, integer4, coa5, LightLayer.BLOCK, integer7, integer8, iterator9);
    }
    
    @Override
    public void handleMerchantOffers(final ClientboundMerchantOffersPacket nl) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)nl, this, this.minecraft);
        final AbstractContainerMenu ban3 = this.minecraft.player.containerMenu;
        if (nl.getContainerId() == ban3.containerId && ban3 instanceof MerchantMenu) {
            ((MerchantMenu)ban3).setOffers(new MerchantOffers(nl.getOffers().createTag()));
            ((MerchantMenu)ban3).setXp(nl.getVillagerXp());
            ((MerchantMenu)ban3).setMerchantLevel(nl.getVillagerLevel());
            ((MerchantMenu)ban3).setShowProgressBar(nl.showProgress());
            ((MerchantMenu)ban3).setCanRestock(nl.canRestock());
        }
    }
    
    @Override
    public void handleSetChunkCacheRadius(final ClientboundSetChunkCacheRadiusPacket oi) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oi, this, this.minecraft);
        this.serverChunkRadius = oi.getRadius();
        this.level.getChunkSource().updateViewRadius(oi.getRadius());
    }
    
    @Override
    public void handleSetChunkCacheCenter(final ClientboundSetChunkCacheCenterPacket oh) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)oh, this, this.minecraft);
        this.level.getChunkSource().updateViewCenter(oh.getX(), oh.getZ());
    }
    
    @Override
    public void handleBlockBreakAck(final ClientboundBlockBreakAckPacket mf) {
        PacketUtils.<ClientPacketListener>ensureRunningOnSameThread((Packet<ClientPacketListener>)mf, this, this.minecraft);
        this.minecraft.gameMode.handleBlockBreakAck(this.level, mf.getPos(), mf.getState(), mf.action(), mf.allGood());
    }
    
    private void readSectionList(final int integer1, final int integer2, final LevelLightEngine coa, final LightLayer bkf, final int integer5, final int integer6, final Iterator<byte[]> iterator) {
        for (int integer7 = 0; integer7 < 18; ++integer7) {
            final int integer8 = -1 + integer7;
            final boolean boolean11 = (integer5 & 1 << integer7) != 0x0;
            final boolean boolean12 = (integer6 & 1 << integer7) != 0x0;
            if (boolean11 || boolean12) {
                coa.queueSectionData(bkf, SectionPos.of(integer1, integer8, integer2), boolean11 ? new DataLayer(iterator.next().clone()) : new DataLayer());
                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 dns4 : this.playerInfoMap.values()) {
            if (dns4.getProfile().getName().equals(string)) {
                return dns4;
            }
        }
        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;
    }
    
    static {
        LOGGER = LogManager.getLogger();
    }
}
