Spaces:
Build error
Build error
File size: 7,138 Bytes
d46f4a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
package com.mojang.realmsclient.dto;
import com.google.gson.JsonObject;
import com.mojang.realmsclient.util.JsonUtils;
import java.util.Objects;
import javax.annotation.Nullable;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.util.StringUtil;
import net.minecraft.world.Difficulty;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.LevelSettings;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class RealmsWorldOptions extends ValueObject {
public final boolean pvp;
public final boolean spawnMonsters;
public final int spawnProtection;
public final boolean commandBlocks;
public final boolean forceGameMode;
public final int difficulty;
public final int gameMode;
public final boolean hardcore;
private final String slotName;
public final String version;
public final RealmsServer.Compatibility compatibility;
public long templateId;
@Nullable
public String templateImage;
public boolean empty;
private static final boolean DEFAULT_FORCE_GAME_MODE = false;
private static final boolean DEFAULT_PVP = true;
private static final boolean DEFAULT_SPAWN_MONSTERS = true;
private static final int DEFAULT_SPAWN_PROTECTION = 0;
private static final boolean DEFAULT_COMMAND_BLOCKS = false;
private static final int DEFAULT_DIFFICULTY = 2;
private static final int DEFAULT_GAME_MODE = 0;
private static final boolean DEFAULT_HARDCORE_MODE = false;
private static final String DEFAULT_SLOT_NAME = "";
private static final String DEFAULT_VERSION = "";
private static final RealmsServer.Compatibility DEFAULT_COMPATIBILITY = RealmsServer.Compatibility.UNVERIFIABLE;
private static final long DEFAULT_TEMPLATE_ID = -1L;
private static final String DEFAULT_TEMPLATE_IMAGE = null;
public RealmsWorldOptions(
boolean p_167302_,
boolean p_167303_,
int p_167306_,
boolean p_167304_,
int p_167308_,
int p_167309_,
boolean p_167305_,
boolean p_167307_,
String p_167311_,
String p_311180_,
RealmsServer.Compatibility p_311981_
) {
this.pvp = p_167302_;
this.spawnMonsters = p_167303_;
this.spawnProtection = p_167306_;
this.commandBlocks = p_167304_;
this.difficulty = p_167308_;
this.gameMode = p_167309_;
this.hardcore = p_167305_;
this.forceGameMode = p_167307_;
this.slotName = p_167311_;
this.version = p_311180_;
this.compatibility = p_311981_;
}
public static RealmsWorldOptions createDefaults() {
return new RealmsWorldOptions(true, true, 0, false, 2, 0, false, false, "", "", DEFAULT_COMPATIBILITY);
}
public static RealmsWorldOptions createDefaultsWith(GameType p_364043_, Difficulty p_366299_, boolean p_368672_, String p_361621_, String p_365919_) {
return new RealmsWorldOptions(true, true, 0, false, p_366299_.getId(), p_364043_.getId(), p_368672_, false, p_365919_, p_361621_, DEFAULT_COMPATIBILITY);
}
public static RealmsWorldOptions createFromSettings(LevelSettings p_361674_, String p_370223_) {
return createDefaultsWith(p_361674_.gameType(), p_361674_.difficulty(), p_361674_.hardcore(), p_370223_, p_361674_.levelName());
}
public static RealmsWorldOptions createEmptyDefaults() {
RealmsWorldOptions realmsworldoptions = createDefaults();
realmsworldoptions.setEmpty(true);
return realmsworldoptions;
}
public void setEmpty(boolean p_87631_) {
this.empty = p_87631_;
}
public static RealmsWorldOptions parse(JsonObject p_87629_, RealmsSettings p_363227_) {
RealmsWorldOptions realmsworldoptions = new RealmsWorldOptions(
JsonUtils.getBooleanOr("pvp", p_87629_, true),
JsonUtils.getBooleanOr("spawnMonsters", p_87629_, true),
JsonUtils.getIntOr("spawnProtection", p_87629_, 0),
JsonUtils.getBooleanOr("commandBlocks", p_87629_, false),
JsonUtils.getIntOr("difficulty", p_87629_, 2),
JsonUtils.getIntOr("gameMode", p_87629_, 0),
p_363227_.hardcore(),
JsonUtils.getBooleanOr("forceGameMode", p_87629_, false),
JsonUtils.getRequiredStringOr("slotName", p_87629_, ""),
JsonUtils.getRequiredStringOr("version", p_87629_, ""),
RealmsServer.getCompatibility(JsonUtils.getRequiredStringOr("compatibility", p_87629_, RealmsServer.Compatibility.UNVERIFIABLE.name()))
);
realmsworldoptions.templateId = JsonUtils.getLongOr("worldTemplateId", p_87629_, -1L);
realmsworldoptions.templateImage = JsonUtils.getStringOr("worldTemplateImage", p_87629_, DEFAULT_TEMPLATE_IMAGE);
return realmsworldoptions;
}
public String getSlotName(int p_87627_) {
if (StringUtil.isBlank(this.slotName)) {
return this.empty ? I18n.get("mco.configure.world.slot.empty") : this.getDefaultSlotName(p_87627_);
} else {
return this.slotName;
}
}
public String getDefaultSlotName(int p_87634_) {
return I18n.get("mco.configure.world.slot", p_87634_);
}
public String toJson() {
JsonObject jsonobject = new JsonObject();
if (!this.pvp) {
jsonobject.addProperty("pvp", this.pvp);
}
if (!this.spawnMonsters) {
jsonobject.addProperty("spawnMonsters", this.spawnMonsters);
}
if (this.spawnProtection != 0) {
jsonobject.addProperty("spawnProtection", this.spawnProtection);
}
if (this.commandBlocks) {
jsonobject.addProperty("commandBlocks", this.commandBlocks);
}
if (this.difficulty != 2) {
jsonobject.addProperty("difficulty", this.difficulty);
}
if (this.gameMode != 0) {
jsonobject.addProperty("gameMode", this.gameMode);
}
if (this.hardcore) {
jsonobject.addProperty("hardcore", this.hardcore);
}
if (this.forceGameMode) {
jsonobject.addProperty("forceGameMode", this.forceGameMode);
}
if (!Objects.equals(this.slotName, "")) {
jsonobject.addProperty("slotName", this.slotName);
}
if (!Objects.equals(this.version, "")) {
jsonobject.addProperty("version", this.version);
}
if (this.compatibility != DEFAULT_COMPATIBILITY) {
jsonobject.addProperty("compatibility", this.compatibility.name());
}
return jsonobject.toString();
}
public RealmsWorldOptions clone() {
return new RealmsWorldOptions(
this.pvp,
this.spawnMonsters,
this.spawnProtection,
this.commandBlocks,
this.difficulty,
this.gameMode,
this.hardcore,
this.forceGameMode,
this.slotName,
this.version,
this.compatibility
);
}
} |