diff --git a/dependencies.gradle b/dependencies.gradle index 81c78616..7163bb84 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -30,6 +30,7 @@ */ dependencies { api("org.jetbrains:annotations:24.0.1") + api("com.github.GTNewHorizons:GTNHLib:0.2.4:dev") compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.5.4-GTNH:dev") compileOnly("com.github.GTNewHorizons:Hodgepodge:2.4.8:dev") { transitive = false } diff --git a/gradle.properties b/gradle.properties index 8c0c9bd7..e1e430e6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,7 +33,7 @@ channel = stable mappingsVersion = 12 # Defines other MCP mappings for dependency deobfuscation. -remoteMappings = https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/ +remoteMappings = https\://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/ # Select a default username for testing your mod. You can always override this per-run by running # `./gradlew runClient --username=AnotherPlayer`, or configuring this command in your IDE. @@ -117,7 +117,7 @@ includeWellKnownRepositories = true usesMavenPublishing = true # Maven repository to publish the mod to. -# mavenPublishUrl = https://nexus.gtnewhorizons.com/repository/releases/ +# mavenPublishUrl = https\://nexus.gtnewhorizons.com/repository/releases/ # Publishing to Modrinth requires you to set the MODRINTH_TOKEN environment variable to your current Modrinth API token. # diff --git a/settings.gradle b/settings.gradle index 3b6c62d0..16a5b4ca 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,7 +17,7 @@ pluginManagement { } plugins { - id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.9' + id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.14' } diff --git a/src/main/java/com/cleanroommc/modularui/GuiErrorHandler.java b/src/main/java/com/cleanroommc/modularui/GuiErrorHandler.java index 74cbf9b8..c6e46e75 100644 --- a/src/main/java/com/cleanroommc/modularui/GuiErrorHandler.java +++ b/src/main/java/com/cleanroommc/modularui/GuiErrorHandler.java @@ -3,9 +3,9 @@ import com.cleanroommc.modularui.api.widget.IGuiElement; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Set; @@ -14,7 +14,7 @@ public class GuiErrorHandler { public static final GuiErrorHandler INSTANCE = new GuiErrorHandler(); - private final Set errorSet = new HashSet<>(); + private final Set errorSet = new ObjectOpenHashSet<>(); private final List errors = new ArrayList<>(); private GuiErrorHandler() { diff --git a/src/main/java/com/cleanroommc/modularui/ModularUI.java b/src/main/java/com/cleanroommc/modularui/ModularUI.java index da295b5f..fbd624d2 100644 --- a/src/main/java/com/cleanroommc/modularui/ModularUI.java +++ b/src/main/java/com/cleanroommc/modularui/ModularUI.java @@ -15,6 +15,7 @@ public class ModularUI { static final String DEPENDENCIES = "required-after:gtnhmixins@[2.0.1,); " + + "required-after:gtnhlib@[0.2.0,);" + "after:NotEnoughItems@[2.3.27-GTNH,);" + "after:hodgepodge@[2.0.0,);" + "before:gregtech"; diff --git a/src/main/java/com/cleanroommc/modularui/config/Config.java b/src/main/java/com/cleanroommc/modularui/config/Config.java index 4404ff52..270c3ca6 100644 --- a/src/main/java/com/cleanroommc/modularui/config/Config.java +++ b/src/main/java/com/cleanroommc/modularui/config/Config.java @@ -7,13 +7,14 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import cpw.mods.fml.common.Loader; +import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; + import net.minecraft.network.PacketBuffer; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import java.io.File; import java.nio.file.Path; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; @@ -23,7 +24,7 @@ @Deprecated public class Config { - private static final Map configs = new HashMap<>(); + private static final Map configs = new Object2ObjectLinkedOpenHashMap<>(); private static final Path configPath = Loader.instance().getConfigDir().toPath(); @NotNull @@ -44,8 +45,8 @@ public static Builder builder(String name) { private final String name; private final String basePath; - private final Map categories = new HashMap<>(); - private final Map values = new HashMap<>(); + private final Map categories = new Object2ObjectLinkedOpenHashMap<>(); + private final Map values = new Object2ObjectLinkedOpenHashMap<>(); private final File filePath; private final boolean synced; @@ -159,8 +160,8 @@ public static class Builder { private final String name; private final Builder parent; private String basePath = "modularui"; - private final Map categories = new HashMap<>(); - private final Map values = new HashMap<>(); + private final Map categories = new Object2ObjectLinkedOpenHashMap<>(); + private final Map values = new Object2ObjectLinkedOpenHashMap<>(); private boolean synced = true; private Builder(String name, Builder parent) { diff --git a/src/main/java/com/cleanroommc/modularui/drawable/DrawableSerialization.java b/src/main/java/com/cleanroommc/modularui/drawable/DrawableSerialization.java index 619b3db6..66df2719 100644 --- a/src/main/java/com/cleanroommc/modularui/drawable/DrawableSerialization.java +++ b/src/main/java/com/cleanroommc/modularui/drawable/DrawableSerialization.java @@ -12,20 +12,20 @@ import com.google.gson.JsonParseException; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Type; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; public class DrawableSerialization implements JsonSerializer, JsonDeserializer { - private static final Map> DRAWABLE_TYPES = new HashMap<>(); - private static final Map TEXTURES = new HashMap<>(); + private static final Map> DRAWABLE_TYPES = new Object2ObjectOpenHashMap<>(); + private static final Map TEXTURES = new Object2ObjectOpenHashMap<>(); public static void registerTexture(String s, UITexture texture) { TEXTURES.put(s, texture); diff --git a/src/main/java/com/cleanroommc/modularui/drawable/Stencil.java b/src/main/java/com/cleanroommc/modularui/drawable/Stencil.java index b0b8b257..a5520e38 100644 --- a/src/main/java/com/cleanroommc/modularui/drawable/Stencil.java +++ b/src/main/java/com/cleanroommc/modularui/drawable/Stencil.java @@ -2,8 +2,10 @@ import com.cleanroommc.modularui.api.layout.IViewportStack; import com.cleanroommc.modularui.screen.viewport.GuiContext; -import com.cleanroommc.modularui.utils.ArrayListStack; import com.cleanroommc.modularui.widget.sizer.Area; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; + import net.minecraft.client.renderer.Tessellator; import org.jetbrains.annotations.Nullable; import org.lwjgl.opengl.GL11; @@ -13,9 +15,9 @@ public class Stencil { // Stores a stack of areas that are transformed, so it represents the actual area - private final static ArrayListStack stencils = new ArrayListStack<>(); + private final static ObjectArrayList stencils = new ObjectArrayList<>(); // Stores a stack of stencilShapes which is used to mark and remove the stencil shape area - private final static ArrayListStack stencilShapes = new ArrayListStack<>(); + private final static ObjectArrayList stencilShapes = new ObjectArrayList<>(); // the current highest stencil value private static int stencilValue = 0; diff --git a/src/main/java/com/cleanroommc/modularui/factory/GuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/GuiManager.java index bedfe7b5..5f838090 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/GuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/GuiManager.java @@ -17,6 +17,10 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.Unpooled; +import it.unimi.dsi.fastutil.objects.Object2ObjectMap; + +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; + import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.player.EntityPlayer; @@ -33,7 +37,7 @@ public class GuiManager { - private static final Map> FACTORIES = new HashMap<>(16); + private static final Object2ObjectMap> FACTORIES = new Object2ObjectOpenHashMap<>(16); private static GuiScreenWrapper lastMui; private static final List openedContainers = new ArrayList<>(4); diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index e48138e1..5a789d3e 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -2,6 +2,9 @@ import com.cleanroommc.modularui.screen.ModularScreen; import com.cleanroommc.modularui.screen.NEISettingsImpl; + +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; + import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; @@ -18,7 +21,7 @@ @ApiStatus.Experimental public class HoloUI { - private static final Map> syncedHolos = new HashMap<>(); + private static final Map> syncedHolos = new Object2ObjectOpenHashMap<>(); public static void registerSyncedHoloUI(ResourceLocation loc, Supplier screen) { syncedHolos.put(loc, screen); diff --git a/src/main/java/com/cleanroommc/modularui/screen/ModularScreen.java b/src/main/java/com/cleanroommc/modularui/screen/ModularScreen.java index 373f3e93..2953c315 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/ModularScreen.java +++ b/src/main/java/com/cleanroommc/modularui/screen/ModularScreen.java @@ -16,6 +16,11 @@ import com.cleanroommc.modularui.widgets.Dialog; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectIterator; + import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.RenderHelper; @@ -30,8 +35,6 @@ import javax.annotation.Nonnegative; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; @@ -70,8 +73,8 @@ public static ModularScreen getCurrent() { private final PanelManager panelManager; private final GuiContext context = new GuiContext(this); private final Area screenArea = new Area(); - private final Map, List> guiActionListeners = new HashMap<>(); - private final Map frameUpdates = new HashMap<>(); + private final Map, List> guiActionListeners = new Object2ObjectOpenHashMap<>(); + private final Object2ObjectArrayMap frameUpdates = new Object2ObjectArrayMap<>(); private ITheme currentTheme; private GuiScreenWrapper screenWrapper; @@ -218,8 +221,8 @@ public void onUpdate() { @MustBeInvokedByOverriders public void onFrameUpdate() { this.panelManager.checkDirty(); - for (Iterator> iterator = this.frameUpdates.entrySet().iterator(); iterator.hasNext();) { - Map.Entry entry = iterator.next(); + for (ObjectIterator> iterator = this.frameUpdates.object2ObjectEntrySet().fastIterator(); iterator.hasNext(); ) { + Object2ObjectMap.Entry entry = iterator.next(); if (!entry.getKey().isValid()) { iterator.remove(); continue; diff --git a/src/main/java/com/cleanroommc/modularui/screen/viewport/GuiViewportStack.java b/src/main/java/com/cleanroommc/modularui/screen/viewport/GuiViewportStack.java index 2bb8f514..eb5f6180 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/viewport/GuiViewportStack.java +++ b/src/main/java/com/cleanroommc/modularui/screen/viewport/GuiViewportStack.java @@ -2,9 +2,10 @@ import com.cleanroommc.modularui.api.layout.IViewport; import com.cleanroommc.modularui.api.layout.IViewportStack; -import com.cleanroommc.modularui.utils.ArrayListStack; import com.cleanroommc.modularui.utils.GuiUtils; import com.cleanroommc.modularui.widget.sizer.Area; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.jetbrains.annotations.Nullable; import org.lwjgl.util.vector.Matrix4f; import org.lwjgl.util.vector.Vector2f; @@ -24,7 +25,7 @@ public class GuiViewportStack implements IViewportStack { private static final Vector3f sharedVec = new Vector3f(); - private final ArrayListStack viewportStack = new ArrayListStack<>(); + private final ObjectArrayList viewportStack = new ObjectArrayList<>(); private final List viewportAreas = new ArrayList<>(); private TransformationMatrix top; private TransformationMatrix topViewport; diff --git a/src/main/java/com/cleanroommc/modularui/test/TestGui.java b/src/main/java/com/cleanroommc/modularui/test/TestGui.java index d5d5cd6d..52d5dfba 100644 --- a/src/main/java/com/cleanroommc/modularui/test/TestGui.java +++ b/src/main/java/com/cleanroommc/modularui/test/TestGui.java @@ -13,9 +13,9 @@ import com.cleanroommc.modularui.widgets.layout.Grid; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; @@ -41,7 +41,7 @@ public void onClose() { if (this.lines == null) { this.lines = IntStream.range(0, 20).mapToObj(i -> "Option " + (i + 1)).collect(Collectors.toList()); this.configuredOptions = this.lines; - this.availableElements = new HashMap<>(); + this.availableElements = new Object2ObjectOpenHashMap<>(); } AtomicReference>> ref = new AtomicReference<>(null); List> availableMatrix = Grid.mapToMatrix(2, this.lines, (index, value) -> { diff --git a/src/main/java/com/cleanroommc/modularui/theme/Theme.java b/src/main/java/com/cleanroommc/modularui/theme/Theme.java index 8c7b8acb..674274e6 100644 --- a/src/main/java/com/cleanroommc/modularui/theme/Theme.java +++ b/src/main/java/com/cleanroommc/modularui/theme/Theme.java @@ -5,7 +5,8 @@ import com.cleanroommc.modularui.api.IThemeApi; import com.cleanroommc.modularui.screen.Tooltip; -import java.util.HashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; + import java.util.Map; public class Theme implements ITheme { @@ -18,7 +19,7 @@ public class Theme implements ITheme { public static final String TEXT_FIELD = "textField"; public static final String TOGGLE_BUTTON = "toggleButton"; - private final Map widgetThemes = new HashMap<>(); + private final Map widgetThemes = new Object2ObjectOpenHashMap<>(); private final String id; private final ITheme parentTheme; diff --git a/src/main/java/com/cleanroommc/modularui/theme/ThemeAPI.java b/src/main/java/com/cleanroommc/modularui/theme/ThemeAPI.java index 5d275d04..3b1600d0 100644 --- a/src/main/java/com/cleanroommc/modularui/theme/ThemeAPI.java +++ b/src/main/java/com/cleanroommc/modularui/theme/ThemeAPI.java @@ -7,13 +7,14 @@ import com.cleanroommc.modularui.drawable.GuiTextures; import com.cleanroommc.modularui.utils.Color; import com.cleanroommc.modularui.utils.JsonBuilder; + +import it.unimi.dsi.fastutil.objects.Object2ObjectMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Objects; public class ThemeAPI implements IThemeApi { @@ -22,12 +23,12 @@ public class ThemeAPI implements IThemeApi { public static final String DEFAULT = "DEFAULT"; public static final ITheme DEFAULT_DEFAULT = new DefaultTheme(); - private final Map THEMES = new HashMap<>(); - protected final Map> defaultThemes = new HashMap<>(); - protected final Map defaultWidgetThemes = new HashMap<>(); - protected final Map widgetThemeFunctions = new HashMap<>(); - protected final Map jsonScreenThemes = new HashMap<>(); - private final Map screenThemes = new HashMap<>(); + private final Object2ObjectMap THEMES = new Object2ObjectOpenHashMap<>(); + protected final Object2ObjectMap> defaultThemes = new Object2ObjectOpenHashMap<>(); + protected final Object2ObjectMap defaultWidgetThemes = new Object2ObjectOpenHashMap<>(); + protected final Object2ObjectMap widgetThemeFunctions = new Object2ObjectOpenHashMap<>(); + protected final Object2ObjectOpenHashMap jsonScreenThemes = new Object2ObjectOpenHashMap<>(); + private final Object2ObjectMap screenThemes = new Object2ObjectOpenHashMap<>(); private ThemeAPI() { registerWidgetTheme(Theme.PANEL, new WidgetTheme(GuiTextures.MC_BACKGROUND, null, Color.WHITE.main, 0xFF404040, false), WidgetTheme::new); diff --git a/src/main/java/com/cleanroommc/modularui/theme/ThemeManager.java b/src/main/java/com/cleanroommc/modularui/theme/ThemeManager.java index 7fc9e855..df82dcf6 100644 --- a/src/main/java/com/cleanroommc/modularui/theme/ThemeManager.java +++ b/src/main/java/com/cleanroommc/modularui/theme/ThemeManager.java @@ -15,6 +15,8 @@ import com.google.gson.JsonParseException; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import it.unimi.dsi.fastutil.objects.*; + import net.minecraft.client.resources.IResource; import net.minecraft.client.resources.IResourceManager; import net.minecraft.client.resources.IResourceManagerReloadListener; @@ -24,8 +26,6 @@ import org.jetbrains.annotations.ApiStatus; import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -50,7 +50,7 @@ public static void reload() { } private static void loadThemesJsons() { - Map> themes = new HashMap<>(); + Map> themes = new Object2ObjectOpenHashMap<>(); // find any theme.json files under any domain // works with mods like resource loader ObjectList themesJsons = ObjectList.create(); @@ -91,7 +91,7 @@ private static void loadThemesJsons() { } public static void loadThemes(Map> themesPaths) { - Map themeMap = new HashMap<>(); + Map themeMap = new Object2ObjectOpenHashMap<>(); // load json files from the path and parse their parent for (Map.Entry> entry : themesPaths.entrySet()) { @@ -112,7 +112,7 @@ public static void loadThemes(Map> themesPaths) { if (themeMap.isEmpty()) return; // create a sorted list of themes - Map sortedThemes = new HashMap<>(); + Map sortedThemes = new Object2ObjectLinkedOpenHashMap<>(); Iterator> iterator; boolean changed; do { @@ -137,12 +137,12 @@ public static void loadThemes(Map> themesPaths) { } private static void validateAncestorTree(Map themeMap) { - Set invalidThemes = new HashSet<>(); + Set invalidThemes = new ObjectOpenHashSet<>(); for (ThemeJson theme : themeMap.values()) { if (invalidThemes.contains(theme)) { continue; } - Set parents = new HashSet<>(); + Set parents = new ObjectOpenHashSet<>(); parents.add(theme); ThemeJson parent = theme; do { @@ -216,7 +216,7 @@ private static void loadScreenThemes(JsonObject json) { } private static void validateJsonScreenThemes() { - for (Iterator> iterator = ThemeAPI.INSTANCE.jsonScreenThemes.entrySet().iterator(); iterator.hasNext(); ) { + for (ObjectIterator> iterator = ThemeAPI.INSTANCE.jsonScreenThemes.object2ObjectEntrySet().fastIterator(); iterator.hasNext(); ) { Map.Entry entry = iterator.next(); if (!ThemeAPI.INSTANCE.hasTheme(entry.getValue())) { ModularUI.LOGGER.error("Tried to register theme '{}' for screen '{}', but theme does not exist", entry.getValue(), entry.getKey()); @@ -269,7 +269,7 @@ private Theme deserialize() { } // parse fallback theme for widget themes - Map widgetThemes = new HashMap<>(); + Map widgetThemes = new Object2ObjectOpenHashMap<>(); WidgetTheme parentWidgetTheme = parent.getFallback(); WidgetTheme fallback = new WidgetTheme(parentWidgetTheme, jsonBuilder.getJson(), jsonBuilder.getJson()); widgetThemes.put(Theme.FALLBACK, fallback); diff --git a/src/main/java/com/cleanroommc/modularui/utils/Alignment.java b/src/main/java/com/cleanroommc/modularui/utils/Alignment.java index a81c9c20..c77fe168 100644 --- a/src/main/java/com/cleanroommc/modularui/utils/Alignment.java +++ b/src/main/java/com/cleanroommc/modularui/utils/Alignment.java @@ -5,14 +5,14 @@ import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import java.lang.reflect.Type; -import java.util.HashMap; import java.util.Map; public class Alignment { - private static final Map ALIGNMENT_MAP = new HashMap<>(); + private static final Map ALIGNMENT_MAP = new Object2ObjectOpenHashMap<>(); public final float x, y; diff --git a/src/main/java/com/cleanroommc/modularui/utils/ArrayListStack.java b/src/main/java/com/cleanroommc/modularui/utils/ArrayListStack.java deleted file mode 100644 index 986deaee..00000000 --- a/src/main/java/com/cleanroommc/modularui/utils/ArrayListStack.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.cleanroommc.modularui.utils; - -import java.util.ArrayList; -import java.util.NoSuchElementException; - -/** - * Extension of ArrayList, inspired by it.unimi.dsi.fastutil.Stack - */ -public class ArrayListStack extends ArrayList { - - public void push(E o) { - add(o); - } - - public E pop() { - if (isEmpty()) throw new NoSuchElementException(); - return remove(size() - 1); - } - - public E top() { - if (isEmpty()) throw new NoSuchElementException(); - return get(size() - 1); - } -} diff --git a/src/main/java/com/cleanroommc/modularui/utils/ColorShade.java b/src/main/java/com/cleanroommc/modularui/utils/ColorShade.java index c9ff8eb7..65767096 100644 --- a/src/main/java/com/cleanroommc/modularui/utils/ColorShade.java +++ b/src/main/java/com/cleanroommc/modularui/utils/ColorShade.java @@ -1,13 +1,12 @@ package com.cleanroommc.modularui.utils; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntIterable; +import it.unimi.dsi.fastutil.ints.IntIterator; +import it.unimi.dsi.fastutil.ints.IntIterators; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -public class ColorShade implements Iterable { +public class ColorShade implements IntIterable { public static Builder builder(int main) { return new Builder(main); @@ -43,32 +42,34 @@ public int brighter(int index) { @NotNull @Override - public Iterator iterator() { - return Arrays.stream(this.all).iterator(); + public IntIterator iterator() { + return IntIterators.wrap(this.all); } public static class Builder { private final int main; - private final List darker = new ArrayList<>(); - private final List brighter = new ArrayList<>(); + private final IntArrayList darker = new IntArrayList(); + private final IntArrayList brighter = new IntArrayList(); public Builder(int main) { this.main = main; } public Builder addDarker(int... darker) { - Arrays.stream(darker).forEach(this.darker::add); + this.darker.addElements(this.darker.size(), darker, 0, darker.length); return this; } public Builder addBrighter(int... brighter) { - Arrays.stream(brighter).forEach(this.brighter::add); + this.brighter.addElements(this.brighter.size(), brighter, 0, brighter.length); return this; } public ColorShade build() { - return new ColorShade(this.main, this.brighter.stream().mapToInt(Integer::intValue).toArray(), this.darker.stream().mapToInt(Integer::intValue).toArray()); + this.darker.trim(); + this.brighter.trim(); + return new ColorShade(this.main, this.brighter.elements(), this.darker.elements()); } } } diff --git a/src/main/java/com/cleanroommc/modularui/utils/ObjectList.java b/src/main/java/com/cleanroommc/modularui/utils/ObjectList.java index 8bb4a76e..09f3a342 100644 --- a/src/main/java/com/cleanroommc/modularui/utils/ObjectList.java +++ b/src/main/java/com/cleanroommc/modularui/utils/ObjectList.java @@ -1,17 +1,14 @@ package com.cleanroommc.modularui.utils; -import com.google.common.collect.ForwardingList; -import com.google.common.collect.Lists; +import it.unimi.dsi.fastutil.objects.ObjectCollection; +import it.unimi.dsi.fastutil.objects.ObjectIterator; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Iterator; -import java.util.List; -public interface ObjectList extends List, Comparable> { +public interface ObjectList extends it.unimi.dsi.fastutil.objects.ObjectList { static ObjectArrayList create() { return new ObjectArrayList<>(); @@ -25,6 +22,14 @@ static ObjectArrayList of(Collection c) { return new ObjectArrayList<>(c); } + static ObjectArrayList of(ObjectCollection c) { + return new ObjectArrayList<>(c); + } + + static ObjectArrayList of(it.unimi.dsi.fastutil.objects.ObjectList l) { + return new ObjectArrayList<>(l); + } + static ObjectArrayList of(V[] a) { return new ObjectArrayList<>(a); } @@ -37,6 +42,10 @@ static ObjectArrayList of(Iterator i) { return new ObjectArrayList<>(i); } + static ObjectArrayList of(ObjectIterator i) { + return new ObjectArrayList<>(i); + } + void addFirst(V v); void addLast(V v); @@ -70,37 +79,41 @@ static ObjectArrayList of(Iterator i) { @NotNull V[] elements(); - class ObjectArrayList extends ForwardingList implements ObjectList { - - final List delegate; + class ObjectArrayList extends it.unimi.dsi.fastutil.objects.ObjectArrayList implements ObjectList { public ObjectArrayList(int capacity) { - this.delegate = new ArrayList<>(capacity); + super(capacity); } public ObjectArrayList() { - this.delegate = new ArrayList<>(); } public ObjectArrayList(Collection c) { - this.delegate = new ArrayList<>(c); + super(c); + } + + public ObjectArrayList(ObjectCollection c) { + super(c); + } + + public ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectList l) { + super(l); } public ObjectArrayList(V[] a) { - this.delegate = new ArrayList<>(Arrays.asList(a)); + super(a); } public ObjectArrayList(V[] a, int offset, int length) { - this(Arrays.copyOfRange(a, offset, offset + length)); + super(a, offset, length); } public ObjectArrayList(Iterator i) { - this.delegate = Lists.newArrayList(i); + super(i); } - @Override - protected List delegate() { - return this.delegate; + public ObjectArrayList(ObjectIterator i) { + super(i); } @Override @@ -152,21 +165,5 @@ public V peekLast() { public V pollLast() { return isEmpty() ? null : removeLast(); } - - @Override - public int compareTo(@NotNull List o) { - // I don't think this will be used - throw new UnsupportedOperationException(); - } - - @Override - public void trim() { - // Kept just for preserving consistency with 1.12.2 code. It looks to be not that important anyway. - } - - @Override - public V[] elements() { - return (V[]) delegate.toArray(); - } } } diff --git a/src/main/java/com/cleanroommc/modularui/utils/math/MathBuilder.java b/src/main/java/com/cleanroommc/modularui/utils/math/MathBuilder.java index 21aef77a..2e8b6de3 100644 --- a/src/main/java/com/cleanroommc/modularui/utils/math/MathBuilder.java +++ b/src/main/java/com/cleanroommc/modularui/utils/math/MathBuilder.java @@ -33,10 +33,11 @@ import com.cleanroommc.modularui.utils.math.functions.utility.RandomInteger; import com.cleanroommc.modularui.widgets.textfield.BaseTextFieldWidget; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; + import java.lang.reflect.Constructor; import java.text.ParsePosition; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -62,12 +63,12 @@ public class MathBuilder { * Named variables that can be used in math expression by this * builder */ - public final Map variables = new HashMap<>(); + public final Map variables = new Object2ObjectOpenHashMap<>(); /** * Map of functions which can be used in the math expressions */ - public final Map> functions = new HashMap<>(); + public final Map> functions = new Object2ObjectOpenHashMap<>(); /** * Whether math expression parser should be strict about which characters diff --git a/src/main/java/com/cleanroommc/modularui/utils/math/Operation.java b/src/main/java/com/cleanroommc/modularui/utils/math/Operation.java index 0b2bd8a1..5a94aef4 100644 --- a/src/main/java/com/cleanroommc/modularui/utils/math/Operation.java +++ b/src/main/java/com/cleanroommc/modularui/utils/math/Operation.java @@ -1,5 +1,7 @@ package com.cleanroommc.modularui.utils.math; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; + import java.util.HashSet; import java.util.Set; @@ -130,7 +132,7 @@ public double calculate(double a, double b) { } }; - public final static Set OPERATORS = new HashSet<>(); + public final static Set OPERATORS = new ObjectOpenHashSet<>(); public static boolean equals(double a, double b) { return Math.abs(a - b) < 0.00001; diff --git a/src/main/java/com/cleanroommc/modularui/value/sync/GuiSyncManager.java b/src/main/java/com/cleanroommc/modularui/value/sync/GuiSyncManager.java index 6184d19f..c29ab0b2 100644 --- a/src/main/java/com/cleanroommc/modularui/value/sync/GuiSyncManager.java +++ b/src/main/java/com/cleanroommc/modularui/value/sync/GuiSyncManager.java @@ -5,6 +5,10 @@ import com.cleanroommc.modularui.screen.ModularContainer; import com.cleanroommc.modularui.widgets.slot.ModularSlot; import com.cleanroommc.modularui.widgets.slot.SlotGroup; + +import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; @@ -23,9 +27,9 @@ public class GuiSyncManager { private final CursorSlotSyncHandler cursorSlotSyncHandler = new CursorSlotSyncHandler(); private final EntityPlayer player; private final PlayerMainInvWrapper playerInventory; - private final Map syncHandlers = new LinkedHashMap<>(); - private final Map slotGroups = new HashMap<>(); - private final Map reverseSyncHandlers = new HashMap<>(); + private final Map syncHandlers = new Object2ObjectLinkedOpenHashMap<>(); + private final Map slotGroups = new Object2ObjectOpenHashMap<>(); + private final Map reverseSyncHandlers = new Object2ObjectOpenHashMap<>(); private ModularContainer container; private final List> openListener = new ArrayList<>(); diff --git a/src/main/java/com/cleanroommc/modularui/widgets/ListWidget.java b/src/main/java/com/cleanroommc/modularui/widgets/ListWidget.java index 6cb95ccb..551f4eca 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/ListWidget.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/ListWidget.java @@ -8,10 +8,11 @@ import com.cleanroommc.modularui.widget.WidgetTree; import com.cleanroommc.modularui.widget.scroll.ScrollData; import com.cleanroommc.modularui.widget.scroll.VerticalScrollData; + +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.Nullable; import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -49,8 +50,8 @@ public static & IWidget, W extends ListWidget> ListWidget builder(List list, Function creator) { - Map map = new HashMap<>(); - Map map_reverse = new HashMap<>(); + Map map = new Object2ObjectOpenHashMap<>(); + Map map_reverse = new Object2ObjectOpenHashMap<>(); ListWidget listWidget = new ListWidget<>(map::get, map_reverse::get); for (T t : list) { I widget = creator.apply(t); diff --git a/src/main/java/com/cleanroommc/modularui/widgets/SliderWidget.java b/src/main/java/com/cleanroommc/modularui/widgets/SliderWidget.java index 3bb82a86..c7f82884 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/SliderWidget.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/SliderWidget.java @@ -1,7 +1,6 @@ package com.cleanroommc.modularui.widgets; import com.cleanroommc.modularui.api.GuiAxis; -import com.cleanroommc.modularui.api.ITheme; import com.cleanroommc.modularui.api.drawable.IDrawable; import com.cleanroommc.modularui.api.value.IDoubleValue; import com.cleanroommc.modularui.api.widget.IGuiAction; @@ -16,9 +15,10 @@ import com.cleanroommc.modularui.widget.Widget; import com.cleanroommc.modularui.widget.sizer.Area; import com.cleanroommc.modularui.widget.sizer.Unit; -import gnu.trove.iterator.TDoubleIterator; -import gnu.trove.list.TDoubleList; -import gnu.trove.list.array.TDoubleArrayList; +import it.unimi.dsi.fastutil.doubles.DoubleArrayList; + +import it.unimi.dsi.fastutil.doubles.DoubleList; + import net.minecraft.util.MathHelper; import org.jetbrains.annotations.NotNull; @@ -28,7 +28,7 @@ public class SliderWidget extends Widget implements Interactable { private IDrawable stopperDrawable = new Rectangle().setColor(Color.withAlpha(Color.WHITE.main, 0.4f)); private IDrawable handleDrawable = GuiTextures.BUTTON_CLEAN; private GuiAxis axis = GuiAxis.X; - private TDoubleList stopper; + private DoubleList stopper; private int stopperWidth = 2, stopperHeight = 4; private final Unit sliderWidth = new Unit(), sliderHeight = new Unit(); private final Area sliderArea = new Area(); @@ -53,7 +53,7 @@ public void onInit() { this.doubleValue = new DoubleValue((this.max - this.min) * 0.5 + this.min); } if (this.each > 0 && this.stopper == null) { - this.stopper = new TDoubleArrayList(); + this.stopper = new DoubleArrayList(); for (double d = this.min; d < this.max; d += this.each) { this.stopper.add(d); } @@ -74,9 +74,7 @@ public boolean isValidSyncHandler(SyncHandler syncHandler) { public void drawBackground(GuiContext context, WidgetTheme widgetTheme) { super.drawBackground(context, widgetTheme); if (this.stopper != null && this.stopperDrawable != null && this.stopperWidth > 0 && this.stopperHeight > 0) { - TDoubleIterator it = this.stopper.iterator(); - while (it.hasNext()) { - double stop = it.next(); + for (double stop : this.stopper) { int pos = valueToPos(stop) + this.sliderArea.getSize(this.axis) / 2; if (this.axis.isHorizontal()) { pos -= this.stopperWidth / 2; @@ -209,19 +207,19 @@ public SliderWidget bounds(double min, double max) { return this; } - public SliderWidget stopper(TDoubleList stopper) { - if (this.stopper == null) this.stopper = new TDoubleArrayList(); + public SliderWidget stopper(DoubleList stopper) { + if (this.stopper == null) this.stopper = new DoubleArrayList(); this.stopper.addAll(stopper); - this.stopper.sort(); + this.stopper.sort(Double::compare); return this; } public SliderWidget stopper(double... stopper) { - if (this.stopper == null) this.stopper = new TDoubleArrayList(); + if (this.stopper == null) this.stopper = new DoubleArrayList(); for (double stop : stopper) { this.stopper.add(stop); } - this.stopper.sort(); + this.stopper.sort(Double::compare); return this; } diff --git a/src/main/java/com/cleanroommc/modularui/widgets/SlotGroupWidget.java b/src/main/java/com/cleanroommc/modularui/widgets/SlotGroupWidget.java index 1e445bad..f6fe1e60 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/SlotGroupWidget.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/SlotGroupWidget.java @@ -3,10 +3,10 @@ import com.cleanroommc.modularui.api.widget.ISynced; import com.cleanroommc.modularui.api.widget.IWidget; import com.cleanroommc.modularui.widget.ParentWidget; -import gnu.trove.map.TCharIntMap; -import gnu.trove.map.TCharObjectMap; -import gnu.trove.map.hash.TCharIntHashMap; -import gnu.trove.map.hash.TCharObjectHashMap; +import it.unimi.dsi.fastutil.chars.Char2IntMap; +import it.unimi.dsi.fastutil.chars.Char2IntOpenHashMap; +import it.unimi.dsi.fastutil.chars.Char2ObjectMap; +import it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap; import java.util.ArrayList; import java.util.Collections; @@ -71,7 +71,7 @@ public static class Builder { private String syncKey; private final List matrix = new ArrayList<>(); - private final TCharObjectMap keys = new TCharObjectHashMap<>(); + private final Char2ObjectMap keys = new Char2ObjectOpenHashMap<>(); private Builder() { this.keys.put(' ', null); @@ -105,7 +105,7 @@ public Builder key(char c, IntFunction widget) { public SlotGroupWidget build() { SlotGroupWidget slotGroupWidget = new SlotGroupWidget(); - TCharIntMap charCount = new TCharIntHashMap(); + Char2IntMap charCount = new Char2IntOpenHashMap(); int x = 0, y = 0, maxWidth = 0; int syncId = 0; for (String row : this.matrix) { diff --git a/src/main/java/com/cleanroommc/modularui/widgets/SortableListWidget.java b/src/main/java/com/cleanroommc/modularui/widgets/SortableListWidget.java index d95da21a..a65ded9b 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/SortableListWidget.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/SortableListWidget.java @@ -7,12 +7,13 @@ import com.cleanroommc.modularui.drawable.GuiTextures; import com.cleanroommc.modularui.widget.DraggableWidget; import com.cleanroommc.modularui.widget.WidgetTree; + +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -25,7 +26,7 @@ public class SortableListWidget> extends public static > SortableListWidget sortableBuilder(Collection fullList, List list, Function builder) { Objects.requireNonNull(list); Objects.requireNonNull(builder); - Map map = new HashMap<>(); + Map map = new Object2ObjectOpenHashMap<>(); SortableListWidget sortableListWidget = new SortableListWidget<>(map::get); for (T t : fullList) { I item = builder.apply(t); diff --git a/src/main/java/com/cleanroommc/modularui/widgets/layout/Grid.java b/src/main/java/com/cleanroommc/modularui/widgets/layout/Grid.java index ccf4c6ec..5d708daf 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/layout/Grid.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/layout/Grid.java @@ -8,8 +8,8 @@ import com.cleanroommc.modularui.widget.ScrollWidget; import com.cleanroommc.modularui.widget.sizer.Area; import com.cleanroommc.modularui.widget.sizer.Box; -import gnu.trove.list.TIntList; -import gnu.trove.list.array.TIntArrayList; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -54,8 +54,8 @@ private int getElementHeight(Area area) { @Override public void layoutWidgets() { - TIntList rowSizes = new TIntArrayList(); - TIntList colSizes = new TIntArrayList(); + IntList rowSizes = new IntArrayList(); + IntList colSizes = new IntArrayList(); int i = 0, j; for (List row : this.matrix) { @@ -129,7 +129,7 @@ public int getDefaultHeight() { @Override public int getDefaultWidth() { - TIntList colSizes = new TIntArrayList(); + IntList colSizes = new IntArrayList(); int i = 0, j; for (List row : this.matrix) { j = 0; @@ -138,13 +138,17 @@ public int getDefaultWidth() { colSizes.add(this.minColWidth); } if (child != null) { - colSizes.set(j, Math.max(colSizes.get(j), getElementWidth(child.getArea()))); + colSizes.set(j, Math.max(colSizes.getInt(j), getElementWidth(child.getArea()))); } j++; } i++; } - return colSizes.sum(); + int w = 0; + for (int colWidth : colSizes) { + w += colWidth; + } + return w; } public Grid matrix(List> matrix) {