From 9e76757af9f257ae851d83a6ff4b199b943b4104 Mon Sep 17 00:00:00 2001 From: Marcel Konrad Date: Wed, 4 Nov 2020 17:32:53 +0100 Subject: [PATCH] Use ActionHelper#open whenever possible --- .../gui/content/impl/ContentAdvancements.java | 4 +- .../gui/content/impl/ContentButcher.java | 5 +- .../content/impl/ContentButcherPresets.java | 8 +-- .../gui/content/impl/ContentContinue.java | 2 +- .../gui/content/impl/ContentMain.java | 51 ++++--------------- .../gui/content/impl/ContentMultiplayer.java | 5 +- .../gui/content/impl/ContentPlayer.java | 8 +-- .../worldhandler/util/ActionHelper.java | 8 +-- 8 files changed, 29 insertions(+), 62 deletions(-) diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java index 0c3eab2..774feb4 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java @@ -11,7 +11,6 @@ import exopandora.worldhandler.builder.impl.BuilderAdvancement.EnumMode; import exopandora.worldhandler.gui.category.Categories; import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.container.impl.GuiWorldHandler; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; import exopandora.worldhandler.gui.menu.impl.ILogicMapped; @@ -25,7 +24,6 @@ import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.AdvancementHelper; import exopandora.worldhandler.util.CommandHelper; import net.minecraft.advancements.Advancement; -import net.minecraft.client.Minecraft; import net.minecraft.util.text.IFormattableTextComponent; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; @@ -132,7 +130,7 @@ public class ContentAdvancements extends Content })); container.add(new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.actions.reset").mergeStyle(TextFormatting.RED), () -> { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.CONTINUE.withBuilder(this.builderAdvancement.build(EnumActionType.REVOKE, EnumMode.EVERYTHING)).withParent(Contents.ADVANCEMENTS))); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderAdvancement.build(EnumActionType.REVOKE, EnumMode.EVERYTHING))); })); } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcher.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcher.java index 5ba755b..60fa6e9 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcher.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcher.java @@ -13,7 +13,6 @@ import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.category.Categories; import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.container.impl.GuiWorldHandler; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; @@ -99,7 +98,7 @@ public class ContentButcher extends Content container.add(this.radiusField); container.add(new GuiButtonBase(x + 58, y + 24, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.configure"), () -> { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.BUTCHER_SETTINGS.withParent(Contents.BUTCHER))); + ActionHelper.open(Contents.BUTCHER_SETTINGS); })); boolean enabled = this.radius != null && !this.radius.isEmpty(); @@ -112,7 +111,7 @@ public class ContentButcher extends Content container.add(slaughter = new GuiButtonBase(x + 58, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.presets"), () -> { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.BUTCHER_PRESETS.withBuilder(this.builderButcher).withRadius(Integer.parseInt(this.radius)).withParent(Contents.BUTCHER))); + ActionHelper.open(Contents.BUTCHER_PRESETS.withBuilder(this.builderButcher).withRadius(Integer.parseInt(this.radius))); })); slaughter.active = enabled; } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherPresets.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherPresets.java index bcb90ad..b749980 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherPresets.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherPresets.java @@ -48,22 +48,22 @@ public class ContentButcherPresets extends ContentChild container.add(new GuiButtonBase(x + 58, y, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.presets.passive_mobs"), () -> { ContentButcher.slaughter(container.getPlayer(), ForgeRegistries.ENTITIES.getValues().stream().filter(entity -> !EntityClassification.MONSTER.equals(entity.getClassification()) && !EntityClassification.MISC.equals(entity.getClassification())).collect(Collectors.toList()), this.radius); - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(this.getParentContent())); + ActionHelper.open(this.getParentContent()); })); container.add(new GuiButtonBase(x + 58, y + 24, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.presets.hostile_mobs"), () -> { ContentButcher.slaughter(container.getPlayer(), ForgeRegistries.ENTITIES.getValues().stream().filter(entity -> EntityClassification.MONSTER.equals(entity.getClassification())).collect(Collectors.toList()), this.radius); - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(this.getParentContent())); + ActionHelper.open(this.getParentContent()); })); container.add(new GuiButtonBase(x + 58, y + 48, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.presets.players"), () -> { ContentButcher.slaughter(container.getPlayer(), ForgeRegistries.ENTITIES.getValues().stream().filter(entity -> EntityType.PLAYER.equals(entity)).collect(Collectors.toList()), this.radius); - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(this.getParentContent())); + ActionHelper.open(this.getParentContent()); })); container.add(new GuiButtonBase(x + 58, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.presets.entities"), () -> { ContentButcher.slaughter(container.getPlayer(), ForgeRegistries.ENTITIES.getValues().stream().filter(entity -> EntityClassification.MISC.equals(entity.getClassification()) && !EntityType.PLAYER.equals(entity)).collect(Collectors.toList()), this.radius); - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(this.getParentContent())); + ActionHelper.open(this.getParentContent()); })); } } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContinue.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContinue.java index 4f1ff4f..2cb1b5e 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContinue.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContinue.java @@ -70,7 +70,7 @@ public class ContentContinue extends ContentChild container.add(new GuiButtonBase(x + 116 / 2, y + 36, 116, 20, new TranslationTextComponent("gui.worldhandler.generic.yes").mergeStyle(TextFormatting.RED), () -> { CommandHelper.sendCommand(container.getPlayer(), this.builder, this.special); - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(this.getParentContent())); + ActionHelper.open(this.getParentContent()); })); container.add(new GuiButtonBase(x + 116 / 2, y + 60, 116, 20, new TranslationTextComponent("gui.worldhandler.generic.no"), () -> ActionHelper.back(this))); } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMain.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMain.java index 6a46e5c..f092f52 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMain.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMain.java @@ -5,7 +5,6 @@ import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.category.Categories; import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.container.impl.GuiWorldHandler; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; import exopandora.worldhandler.gui.widget.button.EnumIcon; @@ -35,57 +34,27 @@ public class ContentMain extends Content container.add(new GuiButtonIcon(x + 26 * 5 + 2, y, 23, 20, EnumIcon.DIFFICULTY_EASY, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.difficulty", new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.difficulty.easy")), ActionHelper::difficultyEasy)); container.add(new GuiButtonIcon(x + 26 * 6 + 2, y, 22, 20, EnumIcon.DIFFICULTY_NORMAL, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.difficulty", new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.difficulty.normal")), ActionHelper::difficultyNormal)); container.add(new GuiButtonIcon(x + 26 * 7 + 2, y, 22, 20, EnumIcon.DIFFICULTY_HARD, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.difficulty", new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.difficulty.hard")), ActionHelper::difficultyHard)); - container.add(new GuiButtonIcon(x + 26 * 8 + 2, y, 22, 20, EnumIcon.SETTINGS, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.settings"), () -> - { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.SETTINGS.withParent(Contents.MAIN))); - })); + container.add(new GuiButtonIcon(x + 26 * 8 + 2, y, 22, 20, EnumIcon.SETTINGS, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.settings"), () -> ActionHelper.open(Contents.SETTINGS))); container.add(new GuiButtonIcon(x, y + 24, 22, 20, EnumIcon.WEATHER_SUN, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.weather", new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.weather.clear")), ActionHelper::weatherClear)); container.add(new GuiButtonIcon(x + 26, y + 24, 22, 20, EnumIcon.WEATHER_RAIN, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.weather", new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.weather.rainy")), ActionHelper::weatherRain)); container.add(new GuiButtonIcon(x + 26 * 2, y + 24, 22, 20, EnumIcon.WEATHER_STORM, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.weather", new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.weather.thunder")), ActionHelper::weatherThunder)); - container.add(new GuiButtonIcon(x + 26 * 3, y + 24, 23, 20, EnumIcon.POTION, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.potions"), () -> - { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.POTIONS.withParent(Contents.MAIN))); - })); - container.add(new GuiButtonIcon(x + 26 * 4, y + 24, 24, 20, EnumIcon.COMMAND_STACK, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.command_stack"), () -> - { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.COMMAND_STACK.withParent(Contents.MAIN))); - })); + container.add(new GuiButtonIcon(x + 26 * 3, y + 24, 23, 20, EnumIcon.POTION, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.potions"), () -> ActionHelper.open(Contents.POTIONS))); + container.add(new GuiButtonIcon(x + 26 * 4, y + 24, 24, 20, EnumIcon.COMMAND_STACK, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.command_stack"), () -> ActionHelper.open(Contents.COMMAND_STACK))); container.add(new GuiButtonIcon(x + 26 * 5 + 2, y + 24, 23, 20, EnumIcon.GAMEMODE_SURVIVAL, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.gamemode", new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.gamemode.survival")), ActionHelper::gamemodeSurvival)); container.add(new GuiButtonIcon(x + 26 * 6 + 2, y + 24, 22, 20, EnumIcon.GAMEMODE_CREATIVE, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.gamemode", new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.gamemode.creative")), ActionHelper::gamemodeCreative)); container.add(new GuiButtonIcon(x + 26 * 7 + 2, y + 24, 22, 20, EnumIcon.GAMEMODE_ADVENTURE, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.gamemode", new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.gamemode.adventure")), ActionHelper::gamemodeAdventure)); container.add(new GuiButtonIcon(x + 26 * 8 + 2, y + 24, 22, 20, EnumIcon.GAMEMODE_SPECTATOR, new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.gamemode", new TranslationTextComponent("gui.worldhandler.shortcuts.tooltip.gamemode.spectator")), ActionHelper::gamemodeSpectator)); - container.add(new GuiButtonBase(x, y + 48, 74, 20, new TranslationTextComponent("gui.worldhandler.items"), () -> - { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.CUSTOM_ITEM)); - })); - container.add(new GuiButtonBase(x + 78, y + 48, 76, 20, new TranslationTextComponent("gui.worldhandler.blocks"), () -> - { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.EDIT_BLOCKS)); - })); - container.add(new GuiButtonBase(x + 158, y + 48, 74, 20, new TranslationTextComponent("gui.worldhandler.entities"), () -> - { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.SUMMON)); - })); + container.add(new GuiButtonBase(x, y + 48, 74, 20, new TranslationTextComponent("gui.worldhandler.items"), () -> ActionHelper.open(Contents.CUSTOM_ITEM))); + container.add(new GuiButtonBase(x + 78, y + 48, 76, 20, new TranslationTextComponent("gui.worldhandler.blocks"), () -> ActionHelper.open(Contents.EDIT_BLOCKS))); + container.add(new GuiButtonBase(x + 158, y + 48, 74, 20, new TranslationTextComponent("gui.worldhandler.entities"), () -> ActionHelper.open(Contents.SUMMON))); - container.add(new GuiButtonBase(x, y + 72, 74, 20, new TranslationTextComponent("gui.worldhandler.world"), () -> - { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.WORLD_INFO)); - })); - container.add(new GuiButtonBase(x + 78, y + 72, 76, 20, new TranslationTextComponent("gui.worldhandler.player"), () -> - { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.PLAYER)); - })); - container.add(new GuiButtonBase(x + 158, y + 72, 74, 20, new TranslationTextComponent("gui.worldhandler.scoreboard"), () -> - { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.SCOREBOARD_OBJECTIVES)); - })); + container.add(new GuiButtonBase(x, y + 72, 74, 20, new TranslationTextComponent("gui.worldhandler.world"), () -> ActionHelper.open(Contents.WORLD_INFO))); + container.add(new GuiButtonBase(x + 78, y + 72, 76, 20, new TranslationTextComponent("gui.worldhandler.player"), () -> ActionHelper.open(Contents.PLAYER))); + container.add(new GuiButtonBase(x + 158, y + 72, 74, 20, new TranslationTextComponent("gui.worldhandler.scoreboard"), () -> ActionHelper.open(Contents.SCOREBOARD_OBJECTIVES))); - container.add(new GuiButtonBase(x, y + 96, 74, 20, new TranslationTextComponent("gui.worldhandler.change_world"), () -> - { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.CHANGE_WORLD.withParent(Contents.MAIN))); - })); + container.add(new GuiButtonBase(x, y + 96, 74, 20, new TranslationTextComponent("gui.worldhandler.change_world"), () -> ActionHelper.open(Contents.CHANGE_WORLD))); container.add(new GuiButtonBase(x + 78, y + 96, 76, 20, new TranslationTextComponent("gui.worldhandler.resourcepack"), () -> { Minecraft.getInstance().gameSettings.saveOptions(); diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMultiplayer.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMultiplayer.java index 104b1e1..b51c17d 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMultiplayer.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMultiplayer.java @@ -2,6 +2,7 @@ package exopandora.worldhandler.gui.content.impl; import com.google.common.base.Predicates; import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.realmsclient.gui.RealmsServerSlotButton.Action; import exopandora.worldhandler.builder.ICommandBuilder; import exopandora.worldhandler.builder.impl.BuilderGeneric; @@ -214,11 +215,11 @@ public class ContentMultiplayer extends Content })); container.add(new GuiButtonTooltip(x + 118, y + 48, 114, 20, new TranslationTextComponent("gui.worldhandler.multiplayer.runtime.autosave", new TranslationTextComponent("gui.worldhandler.generic.off")).mergeStyle(TextFormatting.RED), new StringTextComponent(this.builderSaveOff.toActualCommand()), () -> { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.CONTINUE.withBuilder(this.builderSaveOff).withParent(Contents.MULTIPLAYER))); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderSaveOff)); })); container.add(new GuiButtonTooltip(x + 118, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.multiplayer.runtime.stop_server").mergeStyle(TextFormatting.RED), new StringTextComponent(this.builderStop.toActualCommand()), () -> { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.CONTINUE.withBuilder(this.builderStop).withParent(Contents.MULTIPLAYER))); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderStop)); })); button4.active = false; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPlayer.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPlayer.java index 9b2ba4d..17942c7 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPlayer.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPlayer.java @@ -135,19 +135,19 @@ public class ContentPlayer extends Content container.add(new GuiButtonBase(x + 118, y, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.player.miscellaneous.set_spawn").mergeStyle(TextFormatting.RED), () -> { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.CONTINUE.withBuilder(this.builderSpawnpoint).withParent(Contents.PLAYER))); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderSpawnpoint)); })); container.add(new GuiButtonBase(x + 118, y + 24, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.player.miscellaneous.set_global_spawn").mergeStyle(TextFormatting.RED), () -> { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.CONTINUE.withBuilder(this.builderSetworldspawn).withParent(Contents.PLAYER))); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderSetworldspawn)); })); container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.player.miscellaneous.kill").mergeStyle(TextFormatting.RED), () -> { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.CONTINUE.withBuilder(this.builderKill).withParent(Contents.PLAYER))); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderKill)); })); container.add(new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.player.miscellaneous.clear_inventory").mergeStyle(TextFormatting.RED), () -> { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.CONTINUE.withBuilder(this.builderClear).withParent(Contents.PLAYER))); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderClear)); })); } } diff --git a/src/main/java/exopandora/worldhandler/util/ActionHelper.java b/src/main/java/exopandora/worldhandler/util/ActionHelper.java index 9205563..ed3dc10 100644 --- a/src/main/java/exopandora/worldhandler/util/ActionHelper.java +++ b/src/main/java/exopandora/worldhandler/util/ActionHelper.java @@ -42,7 +42,7 @@ public class ActionHelper { if(content.getBackContent() != null) { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(content.getBackContent())); + ActionHelper.open(content.getBackContent()); } } @@ -181,15 +181,15 @@ public class ActionHelper { if(BlockHelper.getFocusedBlock() instanceof AbstractSignBlock) { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.SIGN_EDITOR)); + ActionHelper.open(Contents.SIGN_EDITOR); } else if(BlockHelper.getFocusedBlock() instanceof NoteBlock) { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.NOTE_EDITOR)); + ActionHelper.open(Contents.NOTE_EDITOR); } else { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.MAIN)); + ActionHelper.open(Contents.MAIN); } }); }