package com.dairymoose.modernlife.network.play.client;

import com.dairymoose.modernlife.core.ModernLifeClient;
import com.dairymoose.modernlife.core.ModernLifeCommon;
import com.dairymoose.modernlife.items.HandgunItem;
import java.util.function.Supplier;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.network.NetworkEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/* loaded from: outputsrg.jar:com/dairymoose/modernlife/network/play/client/ClientboundBulletHolePacket.class */
public class ClientboundBulletHolePacket implements Packet<ClientGamePacketListener> {
    private int playerId;

    /* renamed from: x */
    private double f11x;

    /* renamed from: y */
    private double f12y;

    /* renamed from: z */
    private double f13z;
    private BlockPos pos;
    private int holeNo;
    private Direction facing;
    private String dim;
    private static final Logger LOGGER = LogManager.getLogger();

    public ClientboundBulletHolePacket() {
    }

    public ClientboundBulletHolePacket(FriendlyByteBuf buffer) {
        read(buffer);
    }

    public ClientboundBulletHolePacket(int playerId, Vec3 vec, BlockPos pos, int holeNo, Direction facing, String dim) {
        this.playerId = playerId;
        this.f11x = vec.x;
        this.f12y = vec.y;
        this.f13z = vec.z;
        this.pos = pos;
        this.holeNo = holeNo;
        this.facing = facing;
        this.dim = dim;
    }

    public void read(FriendlyByteBuf p_148837_1_) {
        this.playerId = p_148837_1_.readInt();
        this.f11x = p_148837_1_.readDouble();
        this.f12y = p_148837_1_.readDouble();
        this.f13z = p_148837_1_.readDouble();
        this.pos = p_148837_1_.readBlockPos();
        this.holeNo = p_148837_1_.readInt();
        this.facing = Direction.from3DDataValue(p_148837_1_.readInt());
        this.dim = p_148837_1_.readUtf();
    }

    public void write(FriendlyByteBuf p_148840_1_) {
        p_148840_1_.writeInt(this.playerId);
        p_148840_1_.writeDouble(this.f11x);
        p_148840_1_.writeDouble(this.f12y);
        p_148840_1_.writeDouble(this.f13z);
        p_148840_1_.writeBlockPos(this.pos);
        p_148840_1_.writeInt(this.holeNo);
        p_148840_1_.writeInt(this.facing.get3DDataValue());
        p_148840_1_.writeUtf(this.dim);
    }

    public void handle(Supplier<NetworkEvent.Context> ctx) {
        ctx.get().enqueueWork(() -> {
            handle((ClientGamePacketListener) ((NetworkEvent.Context) ctx.get()).getNetworkManager().getPacketListener());
        });
        ctx.get().setPacketHandled(true);
    }

    public void handle(ClientGamePacketListener handler) {
        ModernLifeCommon.LOGGER.debug("Handle ClientboundBulletHolePacket");
        if (handler instanceof ClientPacketListener) {
            DistExecutor.runWhenOn(Dist.CLIENT, () -> {
                return new Runnable() { // from class: com.dairymoose.modernlife.network.play.client.ClientboundBulletHolePacket.1
                    final /* synthetic */ ClientGamePacketListener val$handler;

                    RunnableC01311(ClientGamePacketListener handler2) {
                        handler = handler2;
                    }

                    @Override // java.lang.Runnable
                    public void run() {
                        ClientPacketListener clientHandler = handler;
                        Player entity = clientHandler.getLevel().getEntity(ClientboundBulletHolePacket.this.playerId);
                        if (entity instanceof Player) {
                            Player Player = entity;
                            if (Player.getId() != Minecraft.getInstance().player.getId()) {
                                HandgunItem.firingTickMap.put(Player, 6);
                            }
                        }
                        ModernLifeClient.BulletHoleInfo bulletHole = new ModernLifeClient.BulletHoleInfo();
                        bulletHole.dim = ClientboundBulletHolePacket.this.dim;
                        bulletHole.facing = ClientboundBulletHolePacket.this.facing;
                        bulletHole.holeNo = ClientboundBulletHolePacket.this.holeNo;
                        bulletHole.loc = new Vec3(ClientboundBulletHolePacket.this.f11x, ClientboundBulletHolePacket.this.f12y, ClientboundBulletHolePacket.this.f13z);
                        bulletHole.pos = ClientboundBulletHolePacket.this.pos;
                        bulletHole.timestamp = System.currentTimeMillis();
                        ModernLifeClient.bulletHoles.add(bulletHole);
                    }
                };
            });
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: com.dairymoose.modernlife.network.play.client.ClientboundBulletHolePacket$1 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/network/play/client/ClientboundBulletHolePacket$1.class */
    public class RunnableC01311 implements Runnable {
        final /* synthetic */ ClientGamePacketListener val$handler;

        RunnableC01311(ClientGamePacketListener handler2) {
            handler = handler2;
        }

        @Override // java.lang.Runnable
        public void run() {
            ClientPacketListener clientHandler = handler;
            Player entity = clientHandler.getLevel().getEntity(ClientboundBulletHolePacket.this.playerId);
            if (entity instanceof Player) {
                Player Player = entity;
                if (Player.getId() != Minecraft.getInstance().player.getId()) {
                    HandgunItem.firingTickMap.put(Player, 6);
                }
            }
            ModernLifeClient.BulletHoleInfo bulletHole = new ModernLifeClient.BulletHoleInfo();
            bulletHole.dim = ClientboundBulletHolePacket.this.dim;
            bulletHole.facing = ClientboundBulletHolePacket.this.facing;
            bulletHole.holeNo = ClientboundBulletHolePacket.this.holeNo;
            bulletHole.loc = new Vec3(ClientboundBulletHolePacket.this.f11x, ClientboundBulletHolePacket.this.f12y, ClientboundBulletHolePacket.this.f13z);
            bulletHole.pos = ClientboundBulletHolePacket.this.pos;
            bulletHole.timestamp = System.currentTimeMillis();
            ModernLifeClient.bulletHoles.add(bulletHole);
        }
    }
}
