Skip to content

Commit

Permalink
Add safeguard and logging for recipes leading to duplicate (infinitel…
Browse files Browse the repository at this point in the history
…y-looping) compression variants
  • Loading branch information
62832 committed Oct 16, 2024
1 parent f25557f commit 853034e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ run {
version("minecraft", mc)

val nf = mc.substringAfter('.')
version("neoforge", "${nf + (if (!nf.contains('.')) ".0" else "")}.26")
version("neoforge", "${nf + (if (!nf.contains('.')) ".0" else "")}.66")
version("parchment", "2024.07.28")

version("ae2", "19.0.21-beta")
version("ae2", "19.0.23-beta")
library("ae2", "appeng", "appliedenergistics2").versionRef("ae2")

version("ae2wtlib", "19.1.3-beta")
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/gripe/_90/megacells/MEGACells.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.List;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;

Expand Down Expand Up @@ -46,6 +48,7 @@
import gripe._90.megacells.definition.MEGACreativeTab;
import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.definition.MEGAMenus;
import gripe._90.megacells.definition.MEGATranslations;
import gripe._90.megacells.integration.Addons;
import gripe._90.megacells.integration.ae2wt.AE2WTIntegration;
import gripe._90.megacells.integration.appmek.AppMekIntegration;
Expand All @@ -57,6 +60,7 @@
@Mod(MEGACells.MODID)
public class MEGACells {
public static final String MODID = "megacells";
public static final Logger LOGGER = LogManager.getFormatterLogger(MEGATranslations.ModName.getEnglishText());

public MEGACells(ModContainer container, IEventBus eventBus) {
MEGABlocks.DR.register(eventBus);
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/gripe/_90/megacells/misc/CompressionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import appeng.api.stacks.AEItemKey;

import gripe._90.megacells.MEGACells;
import gripe._90.megacells.definition.MEGATags;

public class CompressionService {
Expand Down Expand Up @@ -92,9 +93,18 @@ private CompressionChain generateChain(
variants.addFirst(baseVariant);

for (var lower = getNextVariant(baseVariant, decompressed, false, access); lower != null; ) {
variants.addFirst(lower.item().getItem());
multipliers.addFirst(lower.factor());
lower = getNextVariant(lower.item().getItem(), decompressed, false, access);
var item = lower.item.getItem();

if (variants.contains(item)) {
MEGACells.LOGGER.warn(
"Duplicate lower compression variant detected: %s. Check any recipe involving this item for problems.",
lower);
break;
}

variants.addFirst(item);
multipliers.addFirst(lower.factor);
lower = getNextVariant(item, decompressed, false, access);
}

multipliers.addFirst((byte) 1);
Expand All @@ -105,6 +115,13 @@ private CompressionChain generateChain(
}

for (var higher = getNextVariant(baseVariant, compressed, true, access); higher != null; ) {
if (chain.contains(higher)) {
MEGACells.LOGGER.warn(
"Duplicate higher compression variant detected: %s. Check any recipe involving this item for problems.",
higher);
break;
}

chain.add(higher);
higher = getNextVariant(higher.item().getItem(), compressed, true, access);
}
Expand Down

0 comments on commit 853034e

Please sign in to comment.