From eb91ad9753123792d5e01b4d537915b310235b67 Mon Sep 17 00:00:00 2001 From: Marcel Konrad Date: Thu, 28 Jun 2018 01:07:15 +0200 Subject: [PATCH] Refactoring and fixes --- .../exopandora/worldhandler/WorldHandler.java | 2 +- .../worldhandler/builder/CommandBuilder.java | 27 ++++++--- .../worldhandler/builder/CommandString.java | 52 ++++++++++++++++ .../builder/impl/BuilderAdvancement.java | 18 ++++-- .../builder/impl/BuilderButcher.java | 7 ++- .../builder/impl/BuilderClone.java | 1 + .../builder/impl/BuilderCustomItem.java | 7 +-- .../builder/impl/BuilderDifficulty.java | 3 + .../builder/impl/BuilderFill.java | 1 + .../builder/impl/BuilderGamemode.java | 3 + .../builder/impl/BuilderGeneric.java | 3 +- .../builder/impl/BuilderGive.java | 1 + .../builder/impl/BuilderPotionItem.java | 4 +- .../impl/BuilderScoreboardPlayers.java | 2 + .../builder/impl/BuilderScoreboardTeams.java | 1 + .../builder/impl/BuilderTime.java | 3 + .../builder/impl/BuilderWeather.java | 3 + .../builder/impl/BuilderWhitelist.java | 1 + .../worldhandler/builder/types/Level.java | 3 + .../builder/types/TargetSelector.java | 7 ++- .../gui/button/GuiButtonList.java | 44 ++++++++++++-- .../gui/button/persistence/ButtonValues.java | 4 +- .../worldhandler/gui/category/Category.java | 2 +- .../worldhandler/gui/content/Content.java | 22 +++---- .../gui/content/element/Element.java | 6 -- .../element/impl/ElementClickList.java | 59 +++++++++++-------- .../content/element/impl/ElementPageList.java | 25 +++++++- .../gui/content/impl/ContentAdvancements.java | 4 +- .../impl/ContentScoreboardObjectives.java | 4 +- .../content/impl/ContentScoreboardTeams.java | 2 +- .../worldhandler/helper/EnumHelper.java | 3 + 31 files changed, 245 insertions(+), 79 deletions(-) create mode 100644 src/main/java/exopandora/worldhandler/builder/CommandString.java diff --git a/src/main/java/exopandora/worldhandler/WorldHandler.java b/src/main/java/exopandora/worldhandler/WorldHandler.java index 5d581df..f4ab40f 100644 --- a/src/main/java/exopandora/worldhandler/WorldHandler.java +++ b/src/main/java/exopandora/worldhandler/WorldHandler.java @@ -100,7 +100,7 @@ public class WorldHandler ConfigSliders.load(CONFIG); ConfigButcher.load(CONFIG); - bar.step("Initialising User Interface"); + bar.step("Initializing User Interface"); Content.registerContents(); Category.registerCategories(); diff --git a/src/main/java/exopandora/worldhandler/builder/CommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/CommandBuilder.java index ef0c1c8..ed27226 100644 --- a/src/main/java/exopandora/worldhandler/builder/CommandBuilder.java +++ b/src/main/java/exopandora/worldhandler/builder/CommandBuilder.java @@ -1,7 +1,6 @@ package exopandora.worldhandler.builder; -import java.util.AbstractMap; -import java.util.ArrayList; +import java.util.AbstractMap.SimpleEntry; import java.util.List; import java.util.Map.Entry; import java.util.stream.Collectors; @@ -232,20 +231,34 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax { if(syntax != null) { - this.command = syntax.getSyntaxEntries().stream().map(entry -> new AbstractMap.SimpleEntry(entry, entry.toString())).collect(Collectors.toList()); + this.command = syntax.getSyntaxEntries().stream().map(entry -> new SimpleEntry(entry, entry.toString())).collect(Collectors.toList()); } } @Override public String toCommand() { - return "/" + this.getCommandName() + " " + String.join(" ", this.command.stream().map(entry -> this.isDefaultEntry(entry) ? entry.getKey().toString() : entry.getValue()).collect(Collectors.toList())); + CommandString command = new CommandString(this.getCommandName()); + + for(Entry entry : this.command) + { + if(this.isDefaultEntry(entry)) + { + command.append(entry.getKey().toString()); + } + else + { + command.append(entry.getValue()); + } + } + + return command.toString(); } @Override public String toActualCommand() { - List command = new ArrayList(); + CommandString command = new CommandString(this.getCommandName()); for(Entry entry : this.command) { @@ -254,9 +267,9 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax break; } - command.add(entry.getValue()); + command.append(entry.getValue()); } - return "/" + this.getCommandName() + " " + String.join(" ", command); + return command.toString(); } } diff --git a/src/main/java/exopandora/worldhandler/builder/CommandString.java b/src/main/java/exopandora/worldhandler/builder/CommandString.java new file mode 100644 index 0000000..c69a1ff --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/CommandString.java @@ -0,0 +1,52 @@ +package exopandora.worldhandler.builder; + +import com.mojang.realmsclient.gui.ChatFormatting; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class CommandString +{ + private final StringBuilder command = new StringBuilder("/"); + + public CommandString(String name) + { + this.command.append(name); + } + + public CommandString(String name, String... arguments) + { + this(name); + this.append(arguments); + } + + public void append(String argument) + { + if(argument != null && !argument.isEmpty()) + { + this.command.append(" " + argument); + } + else + { + this.command.append(" " + ChatFormatting.RED + "[error]" + ChatFormatting.RESET); + } + } + + public void append(String... arguments) + { + if(arguments != null) + { + for(String argument : arguments) + { + this.append(argument); + } + } + } + + @Override + public String toString() + { + return this.command.toString(); + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderAdvancement.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderAdvancement.java index 0f9868b..c6d9a20 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderAdvancement.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderAdvancement.java @@ -1,5 +1,7 @@ package exopandora.worldhandler.builder.impl; +import javax.annotation.Nullable; + import exopandora.worldhandler.builder.CommandBuilder; import exopandora.worldhandler.builder.Syntax; import exopandora.worldhandler.builder.types.Type; @@ -28,7 +30,8 @@ public class BuilderAdvancement extends CommandBuilder { this.setNode(0, action != null ? action.toString() : null); } - + + @Nullable public EnumActionType getActionType() { return EnumHelper.valueOf(EnumActionType.class, this.getNodeAsString(1)); @@ -38,7 +41,8 @@ public class BuilderAdvancement extends CommandBuilder { this.setNode(1, player); } - + + @Nullable public String getPlayer() { return this.getNodeAsString(1); @@ -48,7 +52,8 @@ public class BuilderAdvancement extends CommandBuilder { this.setNode(2, mode != null ? mode.toString() : null); } - + + @Nullable public EnumMode getMode() { return EnumHelper.valueOf(EnumMode.class, this.getNodeAsString(2)); @@ -58,7 +63,8 @@ public class BuilderAdvancement extends CommandBuilder { this.setNode(3, advancement); } - + + @Nullable public ResourceLocation getAdvancement() { return this.getNodeAsResourceLocation(3); @@ -92,7 +98,8 @@ public class BuilderAdvancement extends CommandBuilder return syntax; } - + + @SideOnly(Side.CLIENT) public static enum EnumActionType { GRANT, @@ -105,6 +112,7 @@ public class BuilderAdvancement extends CommandBuilder } } + @SideOnly(Side.CLIENT) public static enum EnumMode { ONLY, diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderButcher.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderButcher.java index fd4e1d3..75a59d4 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderButcher.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderButcher.java @@ -1,5 +1,8 @@ package exopandora.worldhandler.builder.impl; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import exopandora.worldhandler.builder.CommandBuilder; import exopandora.worldhandler.builder.Syntax; import exopandora.worldhandler.builder.types.TargetSelector; @@ -30,7 +33,8 @@ public class BuilderButcher extends CommandBuilder this.targetSelector.set("r", radius); this.setNode(0, this.targetSelector); } - + + @Nonnull public int getRadius() { return this.targetSelector.get("r"); @@ -42,6 +46,7 @@ public class BuilderButcher extends CommandBuilder this.setNode(0, this.targetSelector); } + @Nonnull public ResourceLocation getEntity() { return this.targetSelector.get("type"); diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderClone.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderClone.java index 44b6c17..e828fe2 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderClone.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderClone.java @@ -129,6 +129,7 @@ public class BuilderClone extends BuilderDoubleBlockPos return syntax; } + @SideOnly(Side.CLIENT) public static enum EnumMask { REPLACE, diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderCustomItem.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderCustomItem.java index a0611a2..1a610d5 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderCustomItem.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderCustomItem.java @@ -25,12 +25,9 @@ public class BuilderCustomItem extends BuilderGive this(null, null); } - public BuilderCustomItem(String username, ResourceLocation item) + public BuilderCustomItem(String player, ResourceLocation item) { - this.setPlayer(username); - this.setItem(item); - this.setAmount(1); - this.setMetadata(0); + super(player, item); this.attribute = this.registerNBTComponent(new ComponentAttributeItem(attribute -> attribute.getApplyable().equals(Applyable.BOTH) || attribute.getApplyable().equals(Applyable.PLAYER))); this.display = this.registerNBTComponent(new ComponentDisplay()); this.enchantment = this.registerNBTComponent(new ComponentEnchantment()); diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderDifficulty.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderDifficulty.java index 348a31a..e8fbacd 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderDifficulty.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderDifficulty.java @@ -3,6 +3,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; import exopandora.worldhandler.builder.Syntax; import exopandora.worldhandler.builder.types.Type; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; public class BuilderDifficulty extends CommandBuilder { @@ -37,6 +39,7 @@ public class BuilderDifficulty extends CommandBuilder return syntax; } + @SideOnly(Side.CLIENT) public static enum EnumDifficulty { PEACEFUL, diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderFill.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderFill.java index 1fca3af..a420e09 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderFill.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderFill.java @@ -148,6 +148,7 @@ public class BuilderFill extends BuilderDoubleBlockPos return syntax; } + @SideOnly(Side.CLIENT) public static enum EnumBlockHandling { REPLACE, diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamemode.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamemode.java index b2a57e6..6382650 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamemode.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamemode.java @@ -3,6 +3,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; import exopandora.worldhandler.builder.Syntax; import exopandora.worldhandler.builder.types.Type; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; public class BuilderGamemode extends CommandBuilder { @@ -49,6 +51,7 @@ public class BuilderGamemode extends CommandBuilder return syntax; } + @SideOnly(Side.CLIENT) public static enum EnumGamemode { SURVIVAL, diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGeneric.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGeneric.java index 739c145..b27e693 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGeneric.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGeneric.java @@ -1,5 +1,6 @@ package exopandora.worldhandler.builder.impl; +import exopandora.worldhandler.builder.CommandString; import exopandora.worldhandler.builder.ICommandBuilder; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -19,7 +20,7 @@ public class BuilderGeneric implements ICommandBuilder @Override public String toCommand() { - return "/" + this.command + " " + String.join(" ", this.arguments); + return new CommandString(this.command, this.arguments).toString(); } public String toActualCommand() diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGive.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGive.java index 2c0aa17..ab2a6c2 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGive.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGive.java @@ -16,6 +16,7 @@ public class BuilderGive extends CommandBuilderNBT { this.setPlayer(player); this.setItem(item); + this.setAmount(1); this.setMetadata(0); } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionItem.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionItem.java index a1257b6..7587abc 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionItem.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionItem.java @@ -21,9 +21,7 @@ public class BuilderPotionItem extends BuilderGive public BuilderPotionItem(ResourceLocation item, String player, ComponentPotionItem potion) { - this.setItem(item); - this.setPlayer(player); - this.setAmount(1); + super(player, item); this.potion = this.registerNBTComponent(potion); } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardPlayers.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardPlayers.java index 61d3877..d4182f5 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardPlayers.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardPlayers.java @@ -204,6 +204,7 @@ public class BuilderScoreboardPlayers extends BuilderScoreboard return syntax; } + @SideOnly(Side.CLIENT) public static enum EnumTag { ADD, @@ -216,6 +217,7 @@ public class BuilderScoreboardPlayers extends BuilderScoreboard } } + @SideOnly(Side.CLIENT) public static enum EnumPoints { ADD, diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardTeams.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardTeams.java index ba086d8..5de448a 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardTeams.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardTeams.java @@ -238,6 +238,7 @@ public class BuilderScoreboardTeams extends BuilderScoreboard return syntax; } + @SideOnly(Side.CLIENT) public static enum EnumMode { JOIN, diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTime.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTime.java index 0eb9ad9..2bfd052 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTime.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTime.java @@ -3,6 +3,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; import exopandora.worldhandler.builder.Syntax; import exopandora.worldhandler.builder.types.Type; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; public class BuilderTime extends CommandBuilder { @@ -49,6 +51,7 @@ public class BuilderTime extends CommandBuilder return syntax; } + @SideOnly(Side.CLIENT) public static enum EnumMode { ADD, diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWeather.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWeather.java index 61d05d4..5818299 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWeather.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWeather.java @@ -3,6 +3,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; import exopandora.worldhandler.builder.Syntax; import exopandora.worldhandler.builder.types.Type; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; public class BuilderWeather extends CommandBuilder { @@ -49,6 +51,7 @@ public class BuilderWeather extends CommandBuilder return syntax; } + @SideOnly(Side.CLIENT) public static enum EnumWeather { CLEAR, diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWhitelist.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWhitelist.java index c03eab8..d0d9ed6 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWhitelist.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWhitelist.java @@ -76,6 +76,7 @@ public class BuilderWhitelist extends CommandBuilder return syntax; } + @SideOnly(Side.CLIENT) public static enum EnumMode { ADD, diff --git a/src/main/java/exopandora/worldhandler/builder/types/Level.java b/src/main/java/exopandora/worldhandler/builder/types/Level.java index c6c580a..17e1805 100644 --- a/src/main/java/exopandora/worldhandler/builder/types/Level.java +++ b/src/main/java/exopandora/worldhandler/builder/types/Level.java @@ -1,5 +1,7 @@ package exopandora.worldhandler.builder.types; +import javax.annotation.Nullable; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -28,6 +30,7 @@ public class Level this.level = level; } + @Nullable public static Level valueOf(String value) { if(value != null) diff --git a/src/main/java/exopandora/worldhandler/builder/types/TargetSelector.java b/src/main/java/exopandora/worldhandler/builder/types/TargetSelector.java index d00afbf..c27e711 100644 --- a/src/main/java/exopandora/worldhandler/builder/types/TargetSelector.java +++ b/src/main/java/exopandora/worldhandler/builder/types/TargetSelector.java @@ -4,6 +4,9 @@ import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -17,7 +20,8 @@ public class TargetSelector { this.values.put(id.toLowerCase(), value); } - + + @Nullable public T get(String id) { return (T) this.values.get(id); @@ -28,6 +32,7 @@ public class TargetSelector return this.values.remove(id.toLowerCase()); } + @Nonnull public static TargetSelector valueOf(String input) { if(input.matches(REGEX)); diff --git a/src/main/java/exopandora/worldhandler/gui/button/GuiButtonList.java b/src/main/java/exopandora/worldhandler/gui/button/GuiButtonList.java index 0addb1e..7a02174 100644 --- a/src/main/java/exopandora/worldhandler/gui/button/GuiButtonList.java +++ b/src/main/java/exopandora/worldhandler/gui/button/GuiButtonList.java @@ -10,6 +10,7 @@ import exopandora.worldhandler.gui.content.Content; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -100,26 +101,57 @@ public class GuiButtonList extends GuiButtonWorldHandler public void actionPerformed(Container container, GuiButton button) { + int max = this.logic.getMax() - 1; + int index = this.persistence.getIndex(); + if(this.isHoveringLeft(this.mouseX, this.mouseY)) { - if(this.persistence.getIndex() > 0) + if(GuiScreen.isShiftKeyDown()) { - this.persistence.decrementIndex(); + if(index < 10) + { + this.persistence.setIndex(max - (9 - index)); + } + else + { + this.persistence.decrementIndex(10); + } } else { - this.persistence.setIndex(this.logic.getMax() - 1); + if(index > 0) + { + this.persistence.decrementIndex(); + } + else + { + this.persistence.setIndex(max); + } } } else if(this.isHoveringRight(this.mouseX, this.mouseY)) { - if(this.persistence.getIndex() < this.logic.getMax() - 1) + if(GuiScreen.isShiftKeyDown()) { - this.persistence.incrementIndex(); + if(index > max - 10) + { + this.persistence.setIndex(9 - (max - index)); + } + else + { + this.persistence.incrementIndex(10); + } } else { - this.persistence.setIndex(0); + if(index < max) + { + this.persistence.incrementIndex(); + } + else + { + this.persistence.setIndex(0); + } } } diff --git a/src/main/java/exopandora/worldhandler/gui/button/persistence/ButtonValues.java b/src/main/java/exopandora/worldhandler/gui/button/persistence/ButtonValues.java index 8d0f444..8f9018e 100644 --- a/src/main/java/exopandora/worldhandler/gui/button/persistence/ButtonValues.java +++ b/src/main/java/exopandora/worldhandler/gui/button/persistence/ButtonValues.java @@ -24,7 +24,7 @@ public class ButtonValues this.index++; } - public void incrementIndexBy(int amount) + public void incrementIndex(int amount) { this.index += amount; } @@ -34,7 +34,7 @@ public class ButtonValues this.index--; } - public void decrementIndexBy(int amount) + public void decrementIndex(int amount) { this.index -= amount; } diff --git a/src/main/java/exopandora/worldhandler/gui/category/Category.java b/src/main/java/exopandora/worldhandler/gui/category/Category.java index 502da52..f3c3199 100644 --- a/src/main/java/exopandora/worldhandler/gui/category/Category.java +++ b/src/main/java/exopandora/worldhandler/gui/category/Category.java @@ -64,7 +64,7 @@ public class Category registerCategory(1, "entities", new Category(Contents.SUMMON, Contents.PLAYSOUND)); registerCategory(2, "items", new Category(Contents.CUSTOM_ITEM, Contents.ENCHANTMENT)); registerCategory(3, "blocks", new Category(Contents.EDIT_BLOCKS, Contents.SIGN_EDITOR, Contents.NOTE_EDITOR)); - registerCategory(4, "world", new Category(Contents.WORLD_INFO, Contents.GAMERULES)); + registerCategory(4, "world", new Category(Contents.WORLD_INFO, Contents.GAMERULES, Contents.RECIPES)); registerCategory(5, "player", new Category(Contents.PLAYER, Contents.EXPERIENCE, Contents.ADVANCEMENTS)); registerCategory(6, "scoreboard", new Category(Contents.SCOREBOARD_OBJECTIVES, Contents.SCOREBOARD_TEAMS, Contents.SCOREBOARD_PLAYERS)); } diff --git a/src/main/java/exopandora/worldhandler/gui/content/Content.java b/src/main/java/exopandora/worldhandler/gui/content/Content.java index 032d6f6..9710d58 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/Content.java +++ b/src/main/java/exopandora/worldhandler/gui/content/Content.java @@ -21,6 +21,7 @@ import exopandora.worldhandler.gui.content.impl.ContentNoteEditor; import exopandora.worldhandler.gui.content.impl.ContentPlayer; import exopandora.worldhandler.gui.content.impl.ContentPlaysound; import exopandora.worldhandler.gui.content.impl.ContentPotions; +import exopandora.worldhandler.gui.content.impl.ContentRecipes; import exopandora.worldhandler.gui.content.impl.ContentScoreboardObjectives; import exopandora.worldhandler.gui.content.impl.ContentScoreboardPlayers; import exopandora.worldhandler.gui.content.impl.ContentScoreboardTeams; @@ -60,24 +61,25 @@ public abstract class Content implements IContent //WORLD registerContent(9, "world", new ContentWorldInfo()); registerContent(10, "gamerules", new ContentGamerules()); + registerContent(11, "recipes", new ContentRecipes()); //PLAYER - registerContent(11, "player", new ContentPlayer()); - registerContent(12, "experience", new ContentExperience()); - registerContent(13, "advancements", new ContentAdvancements()); + registerContent(12, "player", new ContentPlayer()); + registerContent(13, "experience", new ContentExperience()); + registerContent(14, "advancements", new ContentAdvancements()); //SCOREBOARD - registerContent(14, "scoreboard_objectives", new ContentScoreboardObjectives()); - registerContent(15, "scoreboard_teams", new ContentScoreboardTeams()); - registerContent(16, "scoreboard_players", new ContentScoreboardPlayers()); + registerContent(15, "scoreboard_objectives", new ContentScoreboardObjectives()); + registerContent(16, "scoreboard_teams", new ContentScoreboardTeams()); + registerContent(17, "scoreboard_players", new ContentScoreboardPlayers()); //MISC - registerContent(17, "change_world", new ContentChangeWorld()); - registerContent(18, "continue", new ContentContinue()); + registerContent(18, "change_world", new ContentChangeWorld()); + registerContent(19, "continue", new ContentContinue()); //NO CATEGORY - registerContent(19, "potions", new ContentPotions()); - registerContent(20, "butcher", new ContentButcher()); + registerContent(20, "potions", new ContentPotions()); + registerContent(21, "butcher", new ContentButcher()); } private static void registerContent(int id, String textualID, Content content) diff --git a/src/main/java/exopandora/worldhandler/gui/content/element/Element.java b/src/main/java/exopandora/worldhandler/gui/content/element/Element.java index cef184d..216731e 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/element/Element.java +++ b/src/main/java/exopandora/worldhandler/gui/content/element/Element.java @@ -14,10 +14,4 @@ public abstract class Element implements IElement this.x = x; this.y = y; } - - @Override - public void draw() - { - - } } diff --git a/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementClickList.java b/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementClickList.java index e3983d8..05f09ce 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementClickList.java +++ b/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementClickList.java @@ -21,31 +21,29 @@ import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class ElementClickList extends Element { - private final int buttonId; + private final int[] buttonIds; private final List list; private final ILogicClickList logic; private final Content content; private final ElementClickList parent; private final int depth; - private final int maxDepth; private GuiButtonList button; private ElementClickList child; - public ElementClickList(int x, int y, List list, int buttonId, int maxDepth, Content content, ILogicClickList logic) + public ElementClickList(int x, int y, List list, int[] buttonIds, Content content, ILogicClickList logic) { - this(x, y, list, buttonId, maxDepth, content, logic, null); + this(x, y, list, buttonIds, content, logic, null); } - private ElementClickList(int x, int y, List list, int buttonId, int maxDepth, Content content, ILogicClickList logic, ElementClickList parent) + private ElementClickList(int x, int y, List list, int[] buttonIds, Content content, ILogicClickList logic, ElementClickList parent) { super(x, y); this.list = list; - this.buttonId = buttonId; + this.buttonIds = buttonIds; this.logic = logic; this.content = content; this.parent = parent; - this.maxDepth = maxDepth; this.depth = this.parent != null ? this.parent.depth + 1 : 1; } @@ -58,7 +56,7 @@ public class ElementClickList extends Element @Override public void initButtons(Container container) { - container.add(this.button = new GuiButtonList(this.buttonId, this.x, this.y, 114, 20, EnumTooltip.TOP_RIGHT, this.content, new IListButtonLogic() + container.add(this.button = new GuiButtonList(this.getButtonId(), this.x, this.y, 114, 20, EnumTooltip.TOP_RIGHT, this.content, new IListButtonLogic() { @Override public void actionPerformed(Container container, GuiButton button, ButtonValues values) @@ -108,28 +106,17 @@ public class ElementClickList extends Element if(node.getEntries() != null) { - this.child = new ElementClickList(this.x, this.y + 24, node.getEntries(), this.buttonId + 1, this.maxDepth, this.content, this.logic, this); + this.child = new ElementClickList(this.x, this.y + 24, node.getEntries(), this.buttonIds, this.content, this.logic, this); this.child.initButtons(container); } - else if(this.depth < this.maxDepth) + else if(this.depth < this.buttonIds.length) { - GuiButtonWorldHandler button = new GuiButtonWorldHandler(this.buttonId + 1, this.x, this.y + 24, 114, 20, null); + GuiButtonWorldHandler button = new GuiButtonWorldHandler(this.getButtonId(), this.x, this.y + 24, 114, 20, null); button.enabled = false; container.add(button); } } - private String[] getKeys() - { - return this.getKeys(new String[this.depth]); - } - - private String[] getKeys(String[] keys) - { - keys[this.depth - 1] = this.getValues().getObject().getKey(); - return this.parent != null ? this.parent.getKeys(keys) : keys; - } - @Nullable private ButtonValues getValues() { @@ -144,7 +131,7 @@ public class ElementClickList extends Element @Override public boolean actionPerformed(Container container, GuiButton button) { - if(button.id == this.buttonId) + if(button.id == this.getButtonId()) { this.button.actionPerformed(container, button); return true; @@ -156,4 +143,30 @@ public class ElementClickList extends Element return false; } + + @Override + public void draw() + { + + } + + private int getButtonId() + { + return this.buttonIds[this.depth - 1]; + } + + private String[] getKeys() + { + return this.getKeys(new String[this.depth]); + } + + private String[] getKeys(String[] keys) + { + if(keys != null && this.depth <= keys.length) + { + keys[this.depth - 1] = this.getValues().getObject().getKey(); + } + + return this.parent != null ? this.parent.getKeys(keys) : keys; + } } diff --git a/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementPageList.java b/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementPageList.java index d7eae58..a176279 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementPageList.java +++ b/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementPageList.java @@ -12,6 +12,7 @@ import exopandora.worldhandler.gui.content.element.Element; import exopandora.worldhandler.gui.content.element.logic.ILogicPageList; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -101,13 +102,33 @@ public class ElementPageList extends Element { if(button.id == this.ids[0]) { - this.values.setObject(this.values.getObject() - 1); + int value = this.values.getObject(); + + if(GuiScreen.isShiftKeyDown()) + { + this.values.setObject(value - Math.min(10, value)); + } + else + { + this.values.setObject(value - 1); + } + container.initGui(); return true; } else if(button.id == this.ids[1]) { - this.values.setObject(this.values.getObject() + 1); + int value = this.values.getObject(); + + if(GuiScreen.isShiftKeyDown()) + { + this.values.setObject(value + Math.min(10, this.getTotalPages() - 1 - value)); + } + else + { + this.values.setObject(value + 1); + } + container.initGui(); return true; } 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 4dfd8f6..57be352 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java @@ -3,8 +3,8 @@ package exopandora.worldhandler.gui.content.impl; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import java.util.stream.StreamSupport; +import com.google.common.collect.Lists; import com.mojang.realmsclient.gui.ChatFormatting; import exopandora.worldhandler.WorldHandler; @@ -43,7 +43,7 @@ public class ContentAdvancements extends Content private GuiButtonList modeButton; - private final List advancements = StreamSupport.stream(new AdvancementManager(null).getAdvancements().spliterator(), true).filter(advancement -> advancement.getDisplay() != null).collect(Collectors.toList()); + private final List advancements = Lists.newArrayList(new AdvancementManager(null).getAdvancements()).parallelStream().filter(advancement -> advancement.getDisplay() != null).collect(Collectors.toList()); @Override public ICommandBuilder getCommandBuilder() diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardObjectives.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardObjectives.java index bd3fc34..c90950e 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardObjectives.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardObjectives.java @@ -48,7 +48,7 @@ public class ContentScoreboardObjectives extends ContentScoreboard if(this.selectedObjective.equals("create")) { - ElementClickList objectives = new ElementClickList(x + 118, y + 24, HELPER.getObjectives(), 7, 2, this, new ILogicClickList() + ElementClickList objectives = new ElementClickList(x + 118, y + 24, HELPER.getObjectives(), new int[] {7, 8}, this, new ILogicClickList() { @Override public void consumeKey(String... keys) @@ -116,7 +116,7 @@ public class ContentScoreboardObjectives extends ContentScoreboard } else if(this.selectedObjective.equals("display") || this.selectedObjective.equals("undisplay")) { - ElementClickList slots = new ElementClickList(x + 118, y + 24 + (this.selectedObjective.equals("undisplay") ? -12 : 0), HELPER.getSlots(), 9, 2, this, new ILogicClickList() + ElementClickList slots = new ElementClickList(x + 118, y + 24 + (this.selectedObjective.equals("undisplay") ? -12 : 0), HELPER.getSlots(), new int[] {9, 10}, this, new ILogicClickList() { @Override public String translate(String... keys) diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardTeams.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardTeams.java index 6753f68..66514e4 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardTeams.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardTeams.java @@ -47,7 +47,7 @@ public class ContentScoreboardTeams extends ContentScoreboard if(this.selectedTeam.equals("option")) { - ElementClickList options = new ElementClickList(x + 118, y + 24, HELPER.getOptions(), 6, 2, this, new ILogicClickList() + ElementClickList options = new ElementClickList(x + 118, y + 24, HELPER.getOptions(), new int[] {6, 7}, this, new ILogicClickList() { @Override public String translate(String... keys) diff --git a/src/main/java/exopandora/worldhandler/helper/EnumHelper.java b/src/main/java/exopandora/worldhandler/helper/EnumHelper.java index 5d5bb4a..92a994c 100644 --- a/src/main/java/exopandora/worldhandler/helper/EnumHelper.java +++ b/src/main/java/exopandora/worldhandler/helper/EnumHelper.java @@ -1,11 +1,14 @@ package exopandora.worldhandler.helper; +import javax.annotation.Nullable; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class EnumHelper { + @Nullable public static > T valueOf(Class klass, String name) { try