package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.LevelType;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.network.protocol.Packet;

public class ClientboundRespawnPacket implements Packet<ClientGamePacketListener> {
    private DimensionType dimension;
    private long seed;
    private GameType playerGameType;
    private LevelType levelType;
    
    public ClientboundRespawnPacket() {
    }
    
    public ClientboundRespawnPacket(final DimensionType cbi, final long long2, final LevelType bkd, final GameType bjt) {
        this.dimension = cbi;
        this.seed = long2;
        this.playerGameType = bjt;
        this.levelType = bkd;
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleRespawn(this);
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.dimension = DimensionType.getById(kv.readInt());
        this.seed = kv.readLong();
        this.playerGameType = GameType.byId(kv.readUnsignedByte());
        this.levelType = LevelType.getLevelType(kv.readUtf(16));
        if (this.levelType == null) {
            this.levelType = LevelType.NORMAL;
        }
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeInt(this.dimension.getId());
        kv.writeLong(this.seed);
        kv.writeByte(this.playerGameType.getId());
        kv.writeUtf(this.levelType.getName());
    }
    
    public DimensionType getDimension() {
        return this.dimension;
    }
    
    public long getSeed() {
        return this.seed;
    }
    
    public GameType getPlayerGameType() {
        return this.playerGameType;
    }
    
    public LevelType getLevelType() {
        return this.levelType;
    }
}
