Skip to content

Commit

Permalink
Fix #19 by caching IHashedItems to AEItemKeys (#23)
Browse files Browse the repository at this point in the history
* Upgrade dependencies for new Mekanism API
  • Loading branch information
ramidzkh authored Feb 3, 2023
1 parent 9c5d258 commit 6cfc4bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/me/ramidzkh/mekae2/qio/QioStorageAdapter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -28,6 +32,7 @@
* block entity class.
*/
public class QioStorageAdapter<DASHBOARD extends BlockEntity & IQIOComponent> implements MEStorage {
private static final Map<IHashedItem, AEItemKey> CACHE = new WeakHashMap<>();
private final DASHBOARD dashboard;
@Nullable
private final Direction queriedSide;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 6cfc4bb

Please sign in to comment.