package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.core.Registry;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.resources.ResourceKey;
import net.minecraft.network.protocol.Packet;

public class ClientboundRespawnPacket implements Packet<ClientGamePacketListener> {
    private ResourceKey<DimensionType> dimensionType;
    private ResourceKey<Level> dimension;
    private long seed;
    private GameType playerGameType;
    private GameType previousPlayerGameType;
    private boolean isDebug;
    private boolean isFlat;
    private boolean keepAllPlayerData;
    
    public ClientboundRespawnPacket() {
    }
    
    public ClientboundRespawnPacket(final ResourceKey<DimensionType> ug1, final ResourceKey<Level> ug2, final long long3, final GameType bpy4, final GameType bpy5, final boolean boolean6, final boolean boolean7, final boolean boolean8) {
        this.dimensionType = ug1;
        this.dimension = ug2;
        this.seed = long3;
        this.playerGameType = bpy4;
        this.previousPlayerGameType = bpy5;
        this.isDebug = boolean6;
        this.isFlat = boolean7;
        this.keepAllPlayerData = boolean8;
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.handleRespawn(this);
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.dimensionType = ResourceKey.<DimensionType>create(Registry.DIMENSION_TYPE_REGISTRY, mg.readResourceLocation());
        this.dimension = ResourceKey.<Level>create(Registry.DIMENSION_REGISTRY, mg.readResourceLocation());
        this.seed = mg.readLong();
        this.playerGameType = GameType.byId(mg.readUnsignedByte());
        this.previousPlayerGameType = GameType.byId(mg.readUnsignedByte());
        this.isDebug = mg.readBoolean();
        this.isFlat = mg.readBoolean();
        this.keepAllPlayerData = mg.readBoolean();
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeResourceLocation(this.dimensionType.location());
        mg.writeResourceLocation(this.dimension.location());
        mg.writeLong(this.seed);
        mg.writeByte(this.playerGameType.getId());
        mg.writeByte(this.previousPlayerGameType.getId());
        mg.writeBoolean(this.isDebug);
        mg.writeBoolean(this.isFlat);
        mg.writeBoolean(this.keepAllPlayerData);
    }
    
    public ResourceKey<DimensionType> getDimensionType() {
        return this.dimensionType;
    }
    
    public ResourceKey<Level> getDimension() {
        return this.dimension;
    }
    
    public long getSeed() {
        return this.seed;
    }
    
    public GameType getPlayerGameType() {
        return this.playerGameType;
    }
    
    public GameType getPreviousPlayerGameType() {
        return this.previousPlayerGameType;
    }
    
    public boolean isDebug() {
        return this.isDebug;
    }
    
    public boolean isFlat() {
        return this.isFlat;
    }
    
    public boolean shouldKeepAllPlayerData() {
        return this.keepAllPlayerData;
    }
}
