From 6cfc4bb4d0297ebdfc4e2ea81c7bede5d8cee7aa Mon Sep 17 00:00:00 2001 From: ramidzkh Date: Fri, 3 Feb 2023 20:25:27 +1100 Subject: [PATCH] Fix #19 by caching IHashedItems to AEItemKeys (#23) * Upgrade dependencies for new Mekanism API --- gradle.properties | 6 +++--- .../me/ramidzkh/mekae2/qio/QioStorageAdapter.java | 13 +++++++++++-- src/main/resources/META-INF/mods.toml | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 955afce..cf39b34 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ minecraft_version=1.19.2 -forge_version=43.1.65 -ae2_version=12.8.6 -mekanism_version=10.3.5.474 +forge_version=43.2.4 +ae2_version=12.9.2 +mekanism_version=10.3.7.476 jei_version=11.4.0.287 jade_id=4096513 diff --git a/src/main/java/me/ramidzkh/mekae2/qio/QioStorageAdapter.java b/src/main/java/me/ramidzkh/mekae2/qio/QioStorageAdapter.java index 1420d69..4bd4933 100644 --- a/src/main/java/me/ramidzkh/mekae2/qio/QioStorageAdapter.java +++ b/src/main/java/me/ramidzkh/mekae2/qio/QioStorageAdapter.java @@ -1,5 +1,8 @@ package me.ramidzkh.mekae2.qio; +import java.util.Map; +import java.util.WeakHashMap; + import org.jetbrains.annotations.Nullable; import net.minecraft.core.Direction; @@ -10,6 +13,7 @@ import me.ramidzkh.mekae2.AMText; import mekanism.api.Action; import mekanism.api.MekanismAPI; +import mekanism.api.inventory.IHashedItem; import mekanism.api.inventory.qio.IQIOComponent; import mekanism.api.inventory.qio.IQIOFrequency; import mekanism.api.security.SecurityMode; @@ -28,6 +32,7 @@ * block entity class. */ public class QioStorageAdapter implements MEStorage { + private static final Map CACHE = new WeakHashMap<>(); private final DASHBOARD dashboard; @Nullable private final Direction queriedSide; @@ -99,8 +104,12 @@ public void getAvailableStacks(KeyCounter out) { if (freq == null) { return; } - // noinspection ConstantConditions - freq.forAllStored((stack, value) -> out.add(AEItemKey.of(stack), value)); + + // Fixes #19 + freq.forAllHashedStored((type, count) -> { + // noinspection ConstantConditions + out.add(CACHE.computeIfAbsent(type, it -> AEItemKey.of(it.getInternalStack())), count); + }); } @Override diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 45fbf70..a544a79 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -32,6 +32,6 @@ side = "BOTH" [[dependencies.appmek]] modId = "mekanism" mandatory = true -versionRange = "[10.3.0,11.0.0)" +versionRange = "[10.3.7,11.0.0)" ordering = "AFTER" side = "BOTH"