diff --git a/patches/minecraft/net/minecraft/client/gui/GuiCreateWorld.java.patch b/patches/minecraft/net/minecraft/client/gui/GuiCreateWorld.java.patch index 29f9068b5..2fc22191f 100644 --- a/patches/minecraft/net/minecraft/client/gui/GuiCreateWorld.java.patch +++ b/patches/minecraft/net/minecraft/client/gui/GuiCreateWorld.java.patch @@ -1,15 +1,154 @@ --- before/net/minecraft/client/gui/GuiCreateWorld.java +++ after/net/minecraft/client/gui/GuiCreateWorld.java -@@ -240,6 +240,8 @@ +@@ -43,6 +43,11 @@ + private String worldName; + private int selectedIndex; + public String chunkProviderSettingsJson = ""; ++ private GuiButton btnDifficulty; ++ private net.minecraft.world.EnumDifficulty currentDifficulty = net.minecraft.world.EnumDifficulty.NORMAL; ++ private net.minecraft.world.EnumDifficulty savedDifficulty; ++ private GuiButton btnWorld; ++ private GuiButton btnGame; + private static final String[] DISALLOWED_FILENAMES = new String[] + { + "CON", +@@ -90,24 +95,29 @@ + { + Keyboard.enableRepeatEvents(true); + this.buttonList.clear(); +- this.buttonList.add(new GuiButton(0, this.width / 2 - 155, this.height - 28, 150, 20, I18n.format("selectWorld.create"))); +- this.buttonList.add(new GuiButton(1, this.width / 2 + 5, this.height - 28, 150, 20, I18n.format("gui.cancel"))); +- this.btnGameMode = this.addButton(new GuiButton(2, this.width / 2 - 75, 115, 150, 20, I18n.format("selectWorld.gameMode"))); +- this.btnMoreOptions = this.addButton(new GuiButton(3, this.width / 2 - 75, 187, 150, 20, I18n.format("selectWorld.moreWorldOptions"))); +- this.btnMapFeatures = this.addButton(new GuiButton(4, this.width / 2 - 155, 100, 150, 20, I18n.format("selectWorld.mapFeatures"))); ++ this.buttonList.add(new GuiButton(0, this.width / 2 - 154, this.height - 26, 150, 20, I18n.format("selectWorld.create"))); ++ this.buttonList.add(new GuiButton(1, this.width / 2 + 4, this.height - 26, 150, 20, I18n.format("gui.cancel"))); ++ this.btnGameMode = this.addButton(new GuiButton(2, this.width / 2 - 105, 78, 211, 20, I18n.format("selectWorld.gameMode"))); ++ this.btnGame = this.addButton(new GuiButton(12, this.width / 2 - 124, 5, 120, 20, I18n.format("fml.game"))); ++ this.btnWorld = this.addButton(new GuiButton(3, this.width / 2 - 2, 5, 120, 20, I18n.format("fml.world"))); ++ this.btnWorld.enabled = true; ++ this.btnGame.enabled = false; ++ this.btnMapFeatures = this.addButton(new GuiButton(4, this.width / 2 + 111, 110, 45, 20, I18n.format("selectWorld.mapFeatures"))); + this.btnMapFeatures.visible = false; +- this.btnBonusItems = this.addButton(new GuiButton(7, this.width / 2 + 5, 151, 150, 20, I18n.format("selectWorld.bonusItems"))); ++ this.btnBonusItems = this.addButton(new GuiButton(7, this.width / 2 + 111, 134, 45, 20, I18n.format("selectWorld.bonusItems"))); + this.btnBonusItems.visible = false; +- this.btnMapType = this.addButton(new GuiButton(5, this.width / 2 + 5, 100, 150, 20, I18n.format("selectWorld.mapType"))); ++ this.btnMapType = this.addButton(new GuiButton(5, this.width / 2 - 155, 37, 150, 20, I18n.format("selectWorld.mapType"))); + this.btnMapType.visible = false; +- this.btnAllowCommands = this.addButton(new GuiButton(6, this.width / 2 - 155, 151, 150, 20, I18n.format("selectWorld.allowCommands"))); +- this.btnAllowCommands.visible = false; +- this.btnCustomizeType = this.addButton(new GuiButton(8, this.width / 2 + 5, 120, 150, 20, I18n.format("selectWorld.customizeType"))); ++ this.btnAllowCommands = this.addButton(new GuiButton(6, this.width / 2 - 105, 134, 211, 20, I18n.format("selectWorld.allowCommands"))); ++ this.btnAllowCommands.visible = !this.inMoreWorldOptionsDisplay; ++ this.btnDifficulty = this.addButton(new GuiButton(11, this.width / 2 - 105, 106, 211, 20, currentDifficulty.getTranslationKey())); ++ this.btnDifficulty.visible = !this.inMoreWorldOptionsDisplay; ++ this.btnCustomizeType = this.addButton(new GuiButton(8, this.width / 2 + 5, 37, 150, 20, I18n.format("selectWorld.customizeType"))); + this.btnCustomizeType.visible = false; +- this.worldNameField = new GuiTextField(9, this.fontRenderer, this.width / 2 - 100, 60, 200, 20); ++ this.worldNameField = new GuiTextField(9, this.fontRenderer, this.width / 2 - 103, 51, 206, 18); + this.worldNameField.setFocused(true); + this.worldNameField.setText(this.worldName); +- this.worldSeedField = new GuiTextField(10, this.fontRenderer, this.width / 2 - 100, 60, 200, 20); ++ this.worldSeedField = new GuiTextField(10, this.fontRenderer, this.width / 2 - 154, 79, 306, 18); + this.worldSeedField.setText(this.worldSeed); + this.showMoreWorldOptions(this.inMoreWorldOptionsDisplay); + this.calcSaveDirName(); +@@ -142,22 +152,22 @@ + + if (this.generateStructuresEnabled) + { +- this.btnMapFeatures.displayString = this.btnMapFeatures.displayString + I18n.format("options.on"); ++ this.btnMapFeatures.displayString = I18n.format("options.on"); + } + else + { +- this.btnMapFeatures.displayString = this.btnMapFeatures.displayString + I18n.format("options.off"); ++ this.btnMapFeatures.displayString = I18n.format("options.off"); + } + + this.btnBonusItems.displayString = I18n.format("selectWorld.bonusItems") + " "; + + if (this.bonusChestEnabled && !this.hardCoreMode) + { +- this.btnBonusItems.displayString = this.btnBonusItems.displayString + I18n.format("options.on"); ++ this.btnBonusItems.displayString = I18n.format("options.on"); + } + else + { +- this.btnBonusItems.displayString = this.btnBonusItems.displayString + I18n.format("options.off"); ++ this.btnBonusItems.displayString = I18n.format("options.off"); + } + + this.btnMapType.displayString = I18n.format("selectWorld.mapType") +@@ -173,6 +183,13 @@ + { + this.btnAllowCommands.displayString = this.btnAllowCommands.displayString + I18n.format("options.off"); + } ++ if (this.hardCoreMode) ++ { ++ this.btnDifficulty.displayString = I18n.format("options.difficulty") + ": " + I18n.format(net.minecraft.world.EnumDifficulty.HARD.getTranslationKey()); ++ this.btnDifficulty.enabled = false; ++ } ++ else this.btnDifficulty.displayString = I18n.format("options.difficulty") + ": " + I18n.format(this.currentDifficulty.getTranslationKey()); ++ this.btnDifficulty.enabled = true; + } + + public static String getUncollidingSaveDirName(ISaveFormat saveLoader, String name) +@@ -240,8 +257,9 @@ } } + WorldType.WORLD_TYPES[this.selectedIndex].onGUICreateWorldPress(); -+ WorldSettings worldsettings = new WorldSettings( - i, GameType.getByName(this.gameMode), this.generateStructuresEnabled, this.hardCoreMode, WorldType.WORLD_TYPES[this.selectedIndex] +- i, GameType.getByName(this.gameMode), this.generateStructuresEnabled, this.hardCoreMode, WorldType.WORLD_TYPES[this.selectedIndex] ++ i, GameType.getByName(this.gameMode), this.generateStructuresEnabled, this.hardCoreMode, WorldType.WORLD_TYPES[this.selectedIndex], this.currentDifficulty ); -@@ -348,14 +350,7 @@ + worldsettings.setGeneratorOptions(this.chunkProviderSettingsJson); + +@@ -257,9 +275,9 @@ + + this.mc.launchIntegratedServer(this.saveDirName, this.worldNameField.getText().trim(), worldsettings); + } +- else if (button.id == 3) ++ else if (button.id == 3 && this.btnWorld.enabled) + { +- this.toggleMoreWorldOptions(); ++ this.showMoreWorldOptions(true); + } + else if (button.id == 2) + { +@@ -273,6 +291,8 @@ + this.hardCoreMode = false; + this.gameMode = "hardcore"; + this.hardCoreMode = true; ++ this.savedDifficulty = this.currentDifficulty; ++ this.currentDifficulty = net.minecraft.world.EnumDifficulty.HARD; + this.btnAllowCommands.enabled = false; + this.btnBonusItems.enabled = false; + this.updateDisplayState(); +@@ -286,6 +306,12 @@ + + this.hardCoreMode = false; + this.gameMode = "creative"; ++ if (this.savedDifficulty != null) ++ { ++ this.currentDifficulty = this.savedDifficulty; ++ this.savedDifficulty = null; ++ } ++ else this.currentDifficulty = net.minecraft.world.EnumDifficulty.NORMAL; + this.updateDisplayState(); + this.hardCoreMode = false; + this.btnAllowCommands.enabled = true; +@@ -339,6 +365,7 @@ + this.chunkProviderSettingsJson = ""; + this.updateDisplayState(); + this.showMoreWorldOptions(this.inMoreWorldOptionsDisplay); ++ this.btnCustomizeType.enabled = WorldType.WORLD_TYPES[this.selectedIndex].isCustomizable(); + } + else if (button.id == 6) + { +@@ -348,15 +375,14 @@ } else if (button.id == 8) { @@ -21,44 +160,135 @@ - { - this.mc.displayGuiScreen(new GuiCustomizeWorldScreen(this, this.chunkProviderSettingsJson)); - } +- } + WorldType.WORLD_TYPES[this.selectedIndex].onCustomizeButton(mc, this); - } ++ } ++ else if (button.id == 11 && !this.hardCoreMode) ++ { ++ this.currentDifficulty = net.minecraft.world.EnumDifficulty.byId((this.currentDifficulty.getId() + 1) % 4); ++ this.updateDisplayState(); ++ } ++ else if (button.id == 12 && this.btnGame.enabled) this.showMoreWorldOptions(false); } } -@@ -415,11 +410,7 @@ + +@@ -383,8 +409,14 @@ + { + this.inMoreWorldOptionsDisplay = toggle; + ++ this.btnWorld.visible = true; ++ this.btnGame.visible = true; ++ this.btnWorld.enabled = !toggle; ++ this.btnGame.enabled = toggle; + if (WorldType.WORLD_TYPES[this.selectedIndex] == WorldType.DEBUG_ALL_BLOCK_STATES) + { ++ this.btnAllowCommands.visible = false; ++ this.btnDifficulty.visible = false; + this.btnGameMode.visible = !this.inMoreWorldOptionsDisplay; + this.btnGameMode.enabled = false; + +@@ -405,6 +437,8 @@ + this.btnGameMode.visible = !this.inMoreWorldOptionsDisplay; + this.btnGameMode.enabled = true; + ++ this.btnAllowCommands.visible = !this.inMoreWorldOptionsDisplay; ++ this.btnDifficulty.visible = !this.inMoreWorldOptionsDisplay; + if (this.savedGameMode != null) + { + this.gameMode = this.savedGameMode; +@@ -414,23 +448,14 @@ + this.btnMapFeatures.visible = this.inMoreWorldOptionsDisplay && WorldType.WORLD_TYPES[this.selectedIndex] != WorldType.CUSTOMIZED; this.btnBonusItems.visible = this.inMoreWorldOptionsDisplay; this.btnMapType.visible = this.inMoreWorldOptionsDisplay; - this.btnAllowCommands.visible = this.inMoreWorldOptionsDisplay; +- this.btnAllowCommands.visible = this.inMoreWorldOptionsDisplay; - this.btnCustomizeType.visible = this.inMoreWorldOptionsDisplay - && ( - WorldType.WORLD_TYPES[this.selectedIndex] == WorldType.FLAT - || WorldType.WORLD_TYPES[this.selectedIndex] == WorldType.CUSTOMIZED - ); -+ this.btnCustomizeType.visible = this.inMoreWorldOptionsDisplay && WorldType.WORLD_TYPES[this.selectedIndex].isCustomizable(); ++ this.btnCustomizeType.visible = this.inMoreWorldOptionsDisplay; ++ if (this.inMoreWorldOptionsDisplay) this.btnCustomizeType.enabled = WorldType.WORLD_TYPES[this.selectedIndex].isCustomizable(); } this.updateDisplayState(); -@@ -460,6 +451,23 @@ + + if (this.inMoreWorldOptionsDisplay) + { +- this.btnMoreOptions.displayString = I18n.format("gui.done"); +- } +- else +- { +- this.btnMoreOptions.displayString = I18n.format("selectWorld.moreWorldOptions"); + } + } + +@@ -460,6 +485,14 @@ @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { -+ if (this.btnMapType.mousePressed(this.mc, mouseX, mouseY)) { -+ if (mouseButton == 1) { -+ -+ do { -+ this.selectedIndex--; -+ -+ if (this.selectedIndex < 0) { -+ this.selectedIndex = WorldType.WORLD_TYPES.length - 1; -+ } -+ } while (!this.canSelectCurWorldType()); -+ -+ this.chunkProviderSettingsJson = ""; -+ this.updateDisplayState(); -+ this.showMoreWorldOptions(this.inMoreWorldOptionsDisplay); -+ } ++ if (this.btnMapType.mousePressed(this.mc, mouseX, mouseY) && mouseButton == 1) { ++ do { ++ this.selectedIndex = (this.selectedIndex - 1 + WorldType.WORLD_TYPES.length) % WorldType.WORLD_TYPES.length; ++ } while (!this.canSelectCurWorldType()); ++ this.chunkProviderSettingsJson = ""; ++ this.updateDisplayState(); ++ if (this.inMoreWorldOptionsDisplay) this.showMoreWorldOptions(true); + } -+ super.mouseClicked(mouseX, mouseY, mouseButton); if (this.inMoreWorldOptionsDisplay) +@@ -476,16 +509,14 @@ + public void drawScreen(int mouseX, int mouseY, float partialTicks) + { + this.drawDefaultBackground(); +- this.drawCenteredString(this.fontRenderer, I18n.format("selectWorld.create"), this.width / 2, 20, -1); + + if (this.inMoreWorldOptionsDisplay) + { +- this.drawString(this.fontRenderer, I18n.format("selectWorld.enterSeed"), this.width / 2 - 100, 47, -6250336); +- this.drawString(this.fontRenderer, I18n.format("selectWorld.seedInfo"), this.width / 2 - 100, 85, -6250336); +- ++ this.drawString(this.fontRenderer, I18n.format("selectWorld.enterSeed"), this.width / 2 - 155, 65, -6250336); ++ this.drawString(this.fontRenderer, I18n.format("fml.generate_structures.title"), this.width / 2 - 155, 116, -6250336); ++ this.drawString(this.fontRenderer, I18n.format("fml.bonus_chest.title"), this.width / 2 - 155, 140, -6250336); + if (this.btnMapFeatures.visible) + { +- this.drawString(this.fontRenderer, I18n.format("selectWorld.mapFeatures.info"), this.width / 2 - 150, 122, -6250336); + } + + if (this.btnAllowCommands.visible) +@@ -497,25 +528,12 @@ + + if (WorldType.WORLD_TYPES[this.selectedIndex].hasInfoNotice()) + { +- this.fontRenderer +- .drawSplitString( +- I18n.format(WorldType.WORLD_TYPES[this.selectedIndex].getInfoTranslationKey()), +- this.btnMapType.x + 2, +- this.btnMapType.y + 22, +- this.btnMapType.getButtonWidth(), +- 10526880 +- ); + } + } + else + { +- this.drawString(this.fontRenderer, I18n.format("selectWorld.enterName"), this.width / 2 - 100, 47, -6250336); +- this.drawString( +- this.fontRenderer, I18n.format("selectWorld.resultFolder") + " " + this.saveDirName, this.width / 2 - 100, 85, -6250336 +- ); ++ this.drawString(this.fontRenderer, I18n.format("selectWorld.enterName"), this.width / 2 - 104, 37, -6250336); + this.worldNameField.drawTextBox(); +- this.drawString(this.fontRenderer, this.gameModeDesc1, this.width / 2 - 100, 137, -6250336); +- this.drawString(this.fontRenderer, this.gameModeDesc2, this.width / 2 - 100, 149, -6250336); + } + + super.drawScreen(mouseX, mouseY, partialTicks); +@@ -523,6 +541,7 @@ + + public void recreateFromExistingWorld(WorldInfo original) + { ++ this.currentDifficulty = original.getDifficulty(); + this.worldName = I18n.format("selectWorld.newWorld.copyOf", original.getWorldName()); + this.worldSeed = original.getSeed() + ""; + this.selectedIndex = original.getTerrainType().getId(); diff --git a/patches/minecraft/net/minecraft/client/gui/GuiOptions.java.patch b/patches/minecraft/net/minecraft/client/gui/GuiOptions.java.patch index 6c2d484ca..38bede772 100644 --- a/patches/minecraft/net/minecraft/client/gui/GuiOptions.java.patch +++ b/patches/minecraft/net/minecraft/client/gui/GuiOptions.java.patch @@ -1,11 +1,33 @@ --- before/net/minecraft/client/gui/GuiOptions.java +++ after/net/minecraft/client/gui/GuiOptions.java -@@ -85,7 +85,7 @@ +@@ -61,7 +61,7 @@ + i++; + } + +- if (this.mc.world != null) ++ if (this.mc.world != null && !this.mc.player.canUseCommand(2, "gamerule")) + { + EnumDifficulty enumdifficulty = this.mc.world.getDifficulty(); + this.difficultyButton = new GuiButton( +@@ -85,7 +85,8 @@ this.difficultyButton.enabled = false; } } - else ++ else if (this.mc.world != null && this.mc.player.canUseCommand(2, "gamerule")) this.buttonList.add(new GuiButton(107, this.width / 2 + 5, this.height / 6 - 12, 150, 20, I18n.format("fml.world_options"))); + else if (false) // removed realms button { this.buttonList .add( +@@ -241,6 +242,11 @@ + { + this.mc.gameSettings.saveOptions(); + this.mc.displayGuiScreen(new GuiScreenOptionsSounds(this, this.settings)); ++ } ++ if (button.id == 107) ++ { ++ this.mc.gameSettings.saveOptions(); ++ this.mc.displayGuiScreen(new com.cleanroommc.client.gui.WorldOptionsGui(this)); + } + } + } diff --git a/patches/minecraft/net/minecraft/world/WorldSettings.java.patch b/patches/minecraft/net/minecraft/world/WorldSettings.java.patch new file mode 100644 index 000000000..954e93a8a --- /dev/null +++ b/patches/minecraft/net/minecraft/world/WorldSettings.java.patch @@ -0,0 +1,42 @@ +--- before/net/minecraft/world/WorldSettings.java ++++ after/net/minecraft/world/WorldSettings.java +@@ -14,6 +14,7 @@ + private boolean commandsAllowed; + private boolean bonusChestEnabled; + private String generatorOptions = ""; ++ private EnumDifficulty difficulty = EnumDifficulty.NORMAL; + + public WorldSettings(long seedIn, GameType gameType, boolean enableMapFeatures, boolean hardcoreMode, WorldType worldTypeIn) + { +@@ -24,9 +25,19 @@ + this.terrainType = worldTypeIn; + } + ++ public WorldSettings(long seedIn, GameType gameType, boolean enableMapFeatures, boolean hardcoreMode, WorldType worldTypeIn, EnumDifficulty difficulty) ++ { ++ this.seed = seedIn; ++ this.gameType = gameType; ++ this.mapFeaturesEnabled = enableMapFeatures; ++ this.hardcoreEnabled = hardcoreMode; ++ this.terrainType = worldTypeIn; ++ this.difficulty = difficulty; ++ } ++ + public WorldSettings(WorldInfo info) + { +- this(info.getSeed(), info.getGameType(), info.isMapFeaturesEnabled(), info.isHardcoreModeEnabled(), info.getTerrainType()); ++ this(info.getSeed(), info.getGameType(), info.isMapFeaturesEnabled(), info.isHardcoreModeEnabled(), info.getTerrainType(), info.getDifficulty()); + } + + public WorldSettings enableBonusChest() +@@ -91,5 +102,10 @@ + public String getGeneratorOptions() + { + return this.generatorOptions; ++ } ++ ++ public EnumDifficulty getDifficulty() ++ { ++ return this.difficulty; + } + } diff --git a/patches/minecraft/net/minecraft/world/storage/WorldInfo.java.patch b/patches/minecraft/net/minecraft/world/storage/WorldInfo.java.patch index f47d2ca37..dd979beff 100644 --- a/patches/minecraft/net/minecraft/world/storage/WorldInfo.java.patch +++ b/patches/minecraft/net/minecraft/world/storage/WorldInfo.java.patch @@ -20,7 +20,22 @@ } } } -@@ -367,6 +368,7 @@ +@@ -261,12 +262,13 @@ + { + this.populateFromWorldSettings(settings); + this.levelName = name; +- this.difficulty = DEFAULT_DIFFICULTY; ++ this.difficulty = settings.getDifficulty(); + this.initialized = false; + } + + public void populateFromWorldSettings(WorldSettings settings) + { ++ this.difficulty = settings.getDifficulty(); + this.randomSeed = settings.getSeed(); + this.gameType = settings.getGameType(); + this.mapFeaturesEnabled = settings.isMapFeaturesEnabled(); +@@ -367,6 +369,7 @@ nbt.setDouble("BorderSizeLerpTarget", this.borderSizeLerpTarget); nbt.setDouble("BorderWarningBlocks", this.borderWarningDistance); nbt.setDouble("BorderWarningTime", this.borderWarningTime); @@ -28,7 +43,7 @@ if (this.difficulty != null) { -@@ -377,9 +379,10 @@ +@@ -377,9 +380,10 @@ nbt.setTag("GameRules", this.gameRules.writeToNBT()); NBTTagCompound nbttagcompound1 = new NBTTagCompound(); @@ -41,7 +56,7 @@ } nbt.setTag("DimensionData", nbttagcompound1); -@@ -709,6 +712,7 @@ +@@ -709,6 +713,7 @@ public void setDifficulty(EnumDifficulty newDifficulty) { @@ -49,7 +64,7 @@ this.difficulty = newDifficulty; } -@@ -832,16 +836,47 @@ +@@ -832,16 +837,47 @@ } ); } diff --git a/src/main/java/com/cleanroommc/client/gui/EditGameRulesGui.java b/src/main/java/com/cleanroommc/client/gui/EditGameRulesGui.java new file mode 100644 index 000000000..5d4206184 --- /dev/null +++ b/src/main/java/com/cleanroommc/client/gui/EditGameRulesGui.java @@ -0,0 +1,172 @@ +package com.cleanroommc.client.gui; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiYesNo; +import net.minecraft.client.gui.GuiYesNoCallback; +import net.minecraft.client.resources.I18n; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class EditGameRulesGui extends GuiScreen implements GuiYesNoCallback { + private final GuiScreen parent; + private final boolean[] ruleStates; + private final boolean[] originalStates; + private boolean changed = false; + + private static final String[] TITLES = { + "fml.death_messages.title", + "fml.mob_loot.title", + "fml.destructive_mob_actions.title", + "fml.keep_inventory.title", + "fml.spectators_generate_terrain.title", + "fml.spawn_mobs.title", + "fml.advance_time.title", + "fml.update_weather.title" + }; + + private static final String[] RULE_KEYS = { + "showDeathMessages", + "doMobLoot", + "mobGriefing", + "keepInventory", + "spectatorsGenerateChunks", + "doMobSpawning", + "doDaylightCycle", + "doWeatherCycle" + }; + + public EditGameRulesGui(GuiScreen parentIn) { + this.parent = parentIn; + this.ruleStates = new boolean[RULE_KEYS.length]; + this.originalStates = new boolean[RULE_KEYS.length]; + loadRulesFromWorld(); + } + + private void loadRulesFromWorld() { + var mc = Minecraft.getMinecraft(); + if (mc.world != null) { + var gameRules = mc.world.getGameRules(); + for (int i = 0; i < 8; i++) { + ruleStates[i] = gameRules.getBoolean(RULE_KEYS[i]); + originalStates[i] = ruleStates[i]; + } + } else { + for (int i = 0; i < 8; i++) { + ruleStates[i] = false; + originalStates[i] = false; + } + } + } + + @Override + public void initGui() { + this.buttonList.add(new GuiButton(8, this.width / 2 - 154, this.height - 26, 150, + 20, I18n.format("gui.done"))); + this.buttonList.add(new GuiButton(9, this.width / 2 + 4, this.height - 26, 150, + 20, I18n.format("gui.cancel"))); + + for (int i = 0; i < 8; i++) { + int y = 30 + 24 * i; + int x = this.width / 2 + 63; + var buttonText = ruleStates[i] ? I18n.format("gui.yes") : I18n.format("gui.no"); + var btn = new GuiButton(i, x, y - 6, 45, 20, buttonText); + this.buttonList.add(btn); + } + } + + @Override + protected void actionPerformed(GuiButton button) { + if (!button.enabled) { + return; + } + + switch (button.id) { + case 8 -> { + applyChanges(); + this.mc.displayGuiScreen(this.parent); + } + case 9 -> onCancel(); + default -> { + int index = button.id; + ruleStates[index] = !ruleStates[index]; + button.displayString = ruleStates[index] ? I18n.format("gui.yes") : I18n.format("gui.no"); + boolean anyChanged = false; + for (int i = 0; i < 8; i++) { + if (ruleStates[i] != originalStates[i]) { + anyChanged = true; + break; + } + } + setChanged(anyChanged); + } + } + } + + private void applyChanges() { + var mc = Minecraft.getMinecraft(); + for (int i = 0; i < 8; i++) { + if (ruleStates[i] != originalStates[i]) { + var command = String.format("/gamerule %s %s", RULE_KEYS[i], ruleStates[i]); + mc.player.sendChatMessage(command); + if (mc.world != null) { + mc.world.getGameRules().setOrCreateGameRule(RULE_KEYS[i], Boolean.toString(ruleStates[i])); + } + } + } + System.arraycopy(ruleStates, 0, originalStates, 0, ruleStates.length); + setChanged(false); + } + + @Override + protected void keyTyped(char typedChar, int keyCode) throws java.io.IOException { + if (keyCode == 1) { + onCancel(); + } else { + super.keyTyped(typedChar, keyCode); + } + } + + private void onCancel() { + if (isChange()) { + this.mc.displayGuiScreen(new GuiYesNo(this, + I18n.format("fml.game_rule_changes.title"), + I18n.format("fml.abandon_game_rule_changes"), + 0)); + } else { + this.mc.displayGuiScreen(this.parent); + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.drawDefaultBackground(); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.edit_game_rules.title"), + this.width / 2, 4, 0xFFFFFF); + + for (int i = 0; i < 8; i++) { + int y = 30 + 24 * i; + this.drawCenteredString(this.fontRenderer, I18n.format(TITLES[i]), this.width / 2 - 65, y, 0xFFFFFF); + } + super.drawScreen(mouseX, mouseY, partialTicks); + } + + public boolean isChange() { + return changed; + } + + public void setChanged(boolean changed) { + this.changed = changed; + } + + @Override + public void confirmClicked(boolean result, int id) { + if (result) { + this.mc.displayGuiScreen(this.parent); + } else { + this.mc.displayGuiScreen(this); + } + } +} diff --git a/src/main/java/com/cleanroommc/client/gui/RestrictionsGui.java b/src/main/java/com/cleanroommc/client/gui/RestrictionsGui.java new file mode 100644 index 000000000..c59e94927 --- /dev/null +++ b/src/main/java/com/cleanroommc/client/gui/RestrictionsGui.java @@ -0,0 +1,95 @@ +package com.cleanroommc.client.gui; + +import java.io.IOException; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScreenChatOptions; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.EntityPlayer.EnumChatVisibility; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class RestrictionsGui extends GuiScreen { + private final GuiScreen parent; + + public RestrictionsGui(GuiScreen parentIn) { + this.parent = parentIn; + } + + @Override + public void initGui() { + if (this.mc.gameSettings.chatVisibility != EnumChatVisibility.FULL) { + this.buttonList.add(new GuiButton(0, this.width / 2 - 100, 80, I18n.format("fml.chat_settings_screen"))); + } + this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height - 26, I18n.format("gui.done"))); + } + + @Override + protected void actionPerformed(GuiButton button) { + if (button.enabled) { + switch (button.id) { + case 0 -> this.mc.displayGuiScreen(new ScreenChatOptions(this.parent, this.mc.gameSettings)); + case 1 -> this.mc.displayGuiScreen(this.parent); + } + } + } + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + if (keyCode == 1) { + this.mc.displayGuiScreen(this.parent); + } else { + super.keyTyped(typedChar, keyCode); + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.drawDefaultBackground(); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.restrictions.title"), this.width / 2, + 12, 0xFFFFFF); + this.drawChatStatus(this.mc.gameSettings.chatVisibility); + super.drawScreen(mouseX, mouseY, partialTicks); + } + + private void drawChatStatus(EnumChatVisibility enumChatVisibility) { + switch (enumChatVisibility) { + case FULL -> { + this.drawCenteredString(this.fontRenderer, I18n.format("fml.send_chat_messages"), + this.width / 2, 67, 0x00FF00); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.send_commands"), + this.width / 2, 76, 0x00FF00); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.receive_system_messages"), + this.width / 2, 85, 0x00FF00); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.receive_player_messages"), + this.width / 2, 94, 0x00FF00); + } + case SYSTEM -> { + this.drawCenteredString(this.fontRenderer, I18n.format("fml.chat_restricted"), + this.width / 2, 67, 0xFF0000); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.cannot_send_chat_messages"), + this.width / 2, 114, 0xFF0000); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.send_commands"), + this.width / 2, 123, 0x00FF00); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.receive_system_messages"), + this.width / 2, 132, 0x00FF00); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.cannot_receive_player_messages"), + this.width / 2, 141, 0xFF0000); + } + case HIDDEN -> { + this.drawCenteredString(this.fontRenderer, I18n.format("fml.chat_restricted"), + this.width / 2, 67, 0xFF0000); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.cannot_send_chat_messages"), + this.width / 2, 114, 0xFF0000); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.cannot_send_commands"), + this.width / 2, 123, 0xFF0000); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.cannot_receive_system_messages"), + this.width / 2, 132, 0xFF0000); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.cannot_receive_player_messages"), + this.width / 2, 141, 0xFF0000); + } + } + } +} diff --git a/src/main/java/com/cleanroommc/client/gui/WorldOptionsGui.java b/src/main/java/com/cleanroommc/client/gui/WorldOptionsGui.java new file mode 100644 index 000000000..72f52920d --- /dev/null +++ b/src/main/java/com/cleanroommc/client/gui/WorldOptionsGui.java @@ -0,0 +1,122 @@ +package com.cleanroommc.client.gui; + +import java.io.IOException; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiLockIconButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiYesNo; +import net.minecraft.client.gui.GuiYesNoCallback; +import net.minecraft.client.resources.I18n; +import net.minecraft.world.EnumDifficulty; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class WorldOptionsGui extends GuiScreen { + private final GuiScreen parent; + private GuiButton difficultyButton; + private GuiLockIconButton lockButton; + + public WorldOptionsGui(GuiScreen parentIn) { + this.parent = parentIn; + } + + @Override + public void initGui() { + this.difficultyButton = new GuiButton(0, this.width / 2 - 154, this.height / 3 - 22, 130, + 20, this.getDifficultyText(this.mc.world.getDifficulty())); + this.lockButton = new GuiLockIconButton(1, this.width / 2 - 24, this.height / 3 - 22); + + this.buttonList.add(this.difficultyButton); + this.buttonList.add(this.lockButton); + + this.buttonList.add(new GuiButton(2, this.width / 2 + 4, this.height / 3 - 22, 150, + 20, I18n.format("fml.edit_game_rules"))); + this.buttonList.add(new GuiButton(3, this.width / 2 - 154, this.height / 3 + 2, 150, + 20, I18n.format("fml.restrictions"))); + this.buttonList.add(new GuiButton(4, this.width / 2 - 100, this.height - 26, I18n.format("gui.done"))); + + this.lockButton.setLocked(this.mc.world.getWorldInfo().isDifficultyLocked()); + this.lockButton.enabled = !this.lockButton.isLocked(); + this.difficultyButton.enabled = !this.lockButton.isLocked(); + } + + @Override + protected void actionPerformed(GuiButton button) { + if (button.enabled) { + switch (button.id) { + case 0 -> { + this.mc.world.getWorldInfo().setDifficulty(EnumDifficulty.byId(this.mc.world.getDifficulty().getId() + 1)); + this.difficultyButton.displayString = this.getDifficultyText(this.mc.world.getDifficulty()); + } + case 1 -> this.mc.displayGuiScreen(new FixedGuiYesNo(this, + I18n.format("difficulty.lock.title"), + I18n.format("difficulty.lock.question", + I18n.format(this.mc.world.getWorldInfo().getDifficulty().getTranslationKey())), + 1 + )); + case 2 -> { + this.mc.gameSettings.saveOptions(); + this.mc.displayGuiScreen(new EditGameRulesGui(this)); + } + case 3 -> { + this.mc.gameSettings.saveOptions(); + this.mc.displayGuiScreen(new RestrictionsGui(this)); + } + case 4 -> { + this.mc.gameSettings.saveOptions(); + this.mc.displayGuiScreen(this.parent); + } + } + } + } + + @Override + public void confirmClicked(boolean result, int id) { + if (id == 1 && result) { + this.mc.world.getWorldInfo().setDifficultyLocked(true); + this.lockButton.setLocked(true); + this.lockButton.enabled = false; + this.difficultyButton.enabled = false; + } + this.mc.displayGuiScreen(this); + } + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + if (keyCode == 1) { + this.mc.gameSettings.saveOptions(); + this.mc.displayGuiScreen(this.parent); + } else { + super.keyTyped(typedChar, keyCode); + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.drawDefaultBackground(); + this.drawCenteredString(this.fontRenderer, I18n.format("fml.world_options.title"), this.width / 2, + 12, 0xFFFFFF); + super.drawScreen(mouseX, mouseY, partialTicks); + } + + public String getDifficultyText(EnumDifficulty difficulty) { + return I18n.format("options.difficulty") + ": " + I18n.format(difficulty.getTranslationKey()); + } + + private static class FixedGuiYesNo extends GuiYesNo { + public FixedGuiYesNo(GuiYesNoCallback parentScreenIn, String messageLine1In, String messageLine2In, int parentButtonClickedIdIn) { + super(parentScreenIn, messageLine1In, messageLine2In, parentButtonClickedIdIn); + } + + @Override + public void keyTyped(char typedChar, int keyCode) throws IOException { + if (keyCode == 1) { + this.parentScreen.confirmClicked(false, this.parentButtonClickedId); + } else { + super.keyTyped(typedChar, keyCode); + } + } + } +} diff --git a/src/main/resources/assets/forge/lang/en_us.lang b/src/main/resources/assets/forge/lang/en_us.lang index 153c71f1a..794060c60 100644 --- a/src/main/resources/assets/forge/lang/en_us.lang +++ b/src/main/resources/assets/forge/lang/en_us.lang @@ -277,6 +277,38 @@ fml.button.continue=Continue fml.button.open.mods.folder=Open Mods Folder fml.button.open.file=Open %s +fml.game=Game +fml.world=World +fml.generate_structures.title=Generate Structures +fml.bonus_chest.title=Bonus Chest +fml.world_options=World Options... +fml.world_options.title=World Options +fml.game_rules.title=Game Rules +fml.edit_game_rules=Edit Game Rules... +fml.edit_game_rules.title=Edit Game Rules +fml.game_rule_changes.title=Game Rule Changes +fml.abandon_game_rule_changes=Are you sure you want to discard your pending game rule changes? +fml.death_messages.title=Show death messages +fml.mob_loot.title=Drop mob loot +fml.destructive_mob_actions.title=Allow destructive mob actions +fml.keep_inventory.title=Keep inventory after death +fml.spectators_generate_terrain.title=Allow spectators to generate terrain +fml.spawn_mobs.title=Spawn mobs +fml.advance_time.title=Advance time of day +fml.update_weather.title=Update weather +fml.restrictions=Restrictions... +fml.restrictions.title=Restrictions +fml.chat_settings_screen=Go to the Chat Settings screen +fml.chat_restricted=Player chat is restricted in client settings. +fml.send_chat_messages=You can send chat messages +fml.cannot_send_chat_messages=You can't send chat messages +fml.send_commands=You can send commands +fml.cannot_send_commands=You can't send commands +fml.receive_system_messages=You can receive system messages from the server +fml.cannot_receive_system_messages=You can't receive system messages from the server +fml.receive_player_messages=You can receive messages from players +fml.cannot_receive_player_messages=You can't receive messages from players + forge.container.enchant.limitedEnchantability=Limited Enchantability attribute.name.generic.reachDistance=Reach Distance attribute.name.forge.swimSpeed=Swim Speed diff --git a/src/main/resources/assets/forge/lang/zh_cn.lang b/src/main/resources/assets/forge/lang/zh_cn.lang index a051f6c71..5f8ad8366 100644 --- a/src/main/resources/assets/forge/lang/zh_cn.lang +++ b/src/main/resources/assets/forge/lang/zh_cn.lang @@ -239,6 +239,38 @@ fml.button.continue=继续 fml.button.open.mods.folder=打开Mods文件夹 fml.button.open.file=打开%s +fml.game=游戏 +fml.world=世界 +fml.generate_structures.title=生成结构 +fml.bonus_chest.title=奖励箱 +fml.world_options=世界选项... +fml.world_options.title=世界选项 +fml.game_rules.title=游戏规则 +fml.edit_game_rules=编辑游戏规则... +fml.edit_game_rules.title=编辑游戏规则 +fml.game_rule_changes.title=游戏规则更改 +fml.abandon_game_rule_changes=你确定要放弃未保存的游戏规则更改吗? +fml.death_messages.title=显示死亡消息 +fml.mob_loot.title=生物战利品掉落 +fml.destructive_mob_actions.title=允许破坏性生物行为 +fml.keep_inventory.title=死亡后保留物品栏 +fml.spectators_generate_terrain.title=允许旁观者生成地形 +fml.spawn_mobs.title=生成生物 +fml.advance_time.title=游戏内时间流逝 +fml.update_weather.title=天气更替 +fml.restrictions=行为限制... +fml.restrictions.title=行为限制 +fml.chat_settings_screen=前往聊天设置屏幕 +fml.chat_restricted=玩家聊天功能受客户端设置限制。 +fml.send_chat_messages=你可以发送聊天消息 +fml.cannot_send_chat_messages=你无法发送聊天消息 +fml.send_commands=你可以发送命令 +fml.cannot_send_commands=你无法发送命令 +fml.receive_system_messages=你可以从服务器收到系统消息 +fml.cannot_receive_system_messages=你无法从服务器收到系统消息 +fml.receive_player_messages=你可以收到来自玩家的消息 +fml.cannot_receive_player_messages=你无法收到来自玩家的消息 + forge.container.enchant.limitedEnchantability=附魔能力限制 attribute.name.generic.reachDistance=触及半径 attribute.name.forge.swimSpeed=游泳速度