package net.minecraft.world.level;

import com.mojang.serialization.DynamicLike;
import com.mojang.serialization.Dynamic;
import net.minecraft.world.Difficulty;

public final class LevelSettings {
    private final String levelName;
    private final GameType gameType;
    private final boolean hardcore;
    private final Difficulty difficulty;
    private final boolean allowCommands;
    private final GameRules gameRules;
    private final DataPackConfig dataPackConfig;
    
    public LevelSettings(final String string, final GameType bpy, final boolean boolean3, final Difficulty and, final boolean boolean5, final GameRules bpx, final DataPackConfig bpn) {
        this.levelName = string;
        this.gameType = bpy;
        this.hardcore = boolean3;
        this.difficulty = and;
        this.allowCommands = boolean5;
        this.gameRules = bpx;
        this.dataPackConfig = bpn;
    }
    
    public static LevelSettings parse(final Dynamic<?> dynamic, final DataPackConfig bpn) {
        final GameType bpy3 = GameType.byId(dynamic.get("GameType").asInt(0));
        return new LevelSettings(dynamic.get("LevelName").asString(""), bpy3, dynamic.get("hardcore").asBoolean(false), dynamic.get("Difficulty").asNumber().map(number -> Difficulty.byId(number.byteValue())).result().orElse(Difficulty.NORMAL), dynamic.get("allowCommands").asBoolean(bpy3 == GameType.CREATIVE), new GameRules(dynamic.get("GameRules")), bpn);
    }
    
    public String levelName() {
        return this.levelName;
    }
    
    public GameType gameType() {
        return this.gameType;
    }
    
    public boolean hardcore() {
        return this.hardcore;
    }
    
    public Difficulty difficulty() {
        return this.difficulty;
    }
    
    public boolean allowCommands() {
        return this.allowCommands;
    }
    
    public GameRules gameRules() {
        return this.gameRules;
    }
    
    public DataPackConfig getDataPackConfig() {
        return this.dataPackConfig;
    }
    
    public LevelSettings withGameType(final GameType bpy) {
        return new LevelSettings(this.levelName, bpy, this.hardcore, this.difficulty, this.allowCommands, this.gameRules, this.dataPackConfig);
    }
    
    public LevelSettings withDifficulty(final Difficulty and) {
        return new LevelSettings(this.levelName, this.gameType, this.hardcore, and, this.allowCommands, this.gameRules, this.dataPackConfig);
    }
    
    public LevelSettings withDataPackConfig(final DataPackConfig bpn) {
        return new LevelSettings(this.levelName, this.gameType, this.hardcore, this.difficulty, this.allowCommands, this.gameRules, bpn);
    }
    
    public LevelSettings copy() {
        return new LevelSettings(this.levelName, this.gameType, this.hardcore, this.difficulty, this.allowCommands, this.gameRules.copy(), this.dataPackConfig);
    }
}
