From 74d77805a271d7f73c0fcda2c97d73dfa55d6df8 Mon Sep 17 00:00:00 2001 From: 90 Date: Tue, 29 Aug 2023 16:46:12 +0100 Subject: [PATCH] Revert "Rewrite and overhaul bulk compression system (#69)" This reverts commit ceadc538c4278d173c2ea6985969ecb8094604a0. --- .../megacells/datagen/CommonTagProvider.java | 22 +- .../_90/megacells/definition/MEGATags.java | 3 - .../item/cell/BulkCellInventory.java | 123 +++++++---- .../megacells/service/CompressionService.java | 209 ++++++++---------- .../service/DecompressionService.java | 22 +- .../megacells/datagen/MEGADataGenerators.java | 4 +- .../megacells/datagen/MEGADataGenerators.java | 4 +- 7 files changed, 197 insertions(+), 190 deletions(-) diff --git a/common/src/data/java/gripe/_90/megacells/datagen/CommonTagProvider.java b/common/src/data/java/gripe/_90/megacells/datagen/CommonTagProvider.java index 6314518b..cee72b78 100644 --- a/common/src/data/java/gripe/_90/megacells/datagen/CommonTagProvider.java +++ b/common/src/data/java/gripe/_90/megacells/datagen/CommonTagProvider.java @@ -8,8 +8,7 @@ import net.minecraft.data.PackOutput; import net.minecraft.data.tags.IntrinsicHolderTagsProvider; import net.minecraft.data.tags.ItemTagsProvider; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.Items; +import net.minecraft.tags.BlockTags; import net.minecraft.world.level.block.Block; import appeng.api.features.P2PTunnelAttunement; @@ -19,8 +18,8 @@ import gripe._90.megacells.definition.MEGATags; public class CommonTagProvider { - public static class ItemTags extends ItemTagsProvider { - public ItemTags( + public static class Items extends ItemTagsProvider { + public Items( PackOutput output, CompletableFuture registries, CompletableFuture> blockTags) { @@ -37,20 +36,11 @@ protected void addTags(HolderLookup.Provider provider) { tag(MEGATags.MEGA_PATTERN_PROVIDER) .add(MEGABlocks.MEGA_PATTERN_PROVIDER.asItem()) .add(MEGAItems.MEGA_PATTERN_PROVIDER.asItem()); - - tag(MEGATags.COMPRESSION_OVERRIDES) - .add(Items.QUARTZ) - .add(Items.AMETHYST_SHARD) - .add(Items.GLOWSTONE_DUST) - .add(Items.CLAY_BALL) - .add(Items.MELON_SLICE) - .add(Items.MAGMA_CREAM) - .addOptionalTag(new ResourceLocation("functionalstorage", "ignore_crafting_check")); } } - public static class BlockTags extends IntrinsicHolderTagsProvider { - public BlockTags(PackOutput packOutput, CompletableFuture registries) { + public static class Blocks extends IntrinsicHolderTagsProvider { + public Blocks(PackOutput packOutput, CompletableFuture registries) { super(packOutput, Registries.BLOCK, registries, block -> BuiltInRegistries.BLOCK .getResourceKey(block) .orElseThrow()); @@ -59,7 +49,7 @@ public BlockTags(PackOutput packOutput, CompletableFuture @Override protected void addTags(HolderLookup.Provider provider) { for (var block : MEGABlocks.getBlocks()) { - tag(net.minecraft.tags.BlockTags.MINEABLE_WITH_PICKAXE).add(block.block()); + tag(BlockTags.MINEABLE_WITH_PICKAXE).add(block.block()); } tag(MEGATags.SKY_STEEL_BLOCK).add(MEGABlocks.SKY_STEEL_BLOCK.block()); diff --git a/common/src/main/java/gripe/_90/megacells/definition/MEGATags.java b/common/src/main/java/gripe/_90/megacells/definition/MEGATags.java index bb01379e..1b27627f 100644 --- a/common/src/main/java/gripe/_90/megacells/definition/MEGATags.java +++ b/common/src/main/java/gripe/_90/megacells/definition/MEGATags.java @@ -27,7 +27,4 @@ public final class MEGATags { public static final TagKey MEGA_PATTERN_PROVIDER = TagKey.create(Registries.ITEM, MEGACells.makeId("mega_pattern_provider")); - - public static final TagKey COMPRESSION_OVERRIDES = - TagKey.create(Registries.ITEM, MEGACells.makeId("compression_overrides")); } diff --git a/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellInventory.java b/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellInventory.java index 98f4f579..6648bb4c 100644 --- a/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellInventory.java +++ b/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellInventory.java @@ -3,10 +3,14 @@ import static gripe._90.megacells.definition.MEGAItems.COMPRESSION_CARD; import java.math.BigInteger; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.function.Function; -import it.unimi.dsi.fastutil.objects.Object2LongLinkedOpenHashMap; -import it.unimi.dsi.fastutil.objects.Object2LongMap; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import it.unimi.dsi.fastutil.Pair; +import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; @@ -20,6 +24,7 @@ import appeng.api.storage.cells.CellState; import appeng.api.storage.cells.ISaveProvider; import appeng.api.storage.cells.StorageCell; +import appeng.util.prioritylist.IPartitionList; import gripe._90.megacells.item.MEGABulkCell; import gripe._90.megacells.service.CompressionService; @@ -33,8 +38,10 @@ public class BulkCellInventory implements StorageCell { private AEItemKey storedItem; private final AEItemKey filterItem; + private final IPartitionList partitionList; - private final Object2LongMap compressionChain; + private final Object2IntMap compressed; + private final Object2IntMap decompressed; private BigInteger unitCount; private AEItemKey highestCompressed; private final long unitFactor; @@ -46,9 +53,16 @@ public BulkCellInventory(MEGABulkCell cell, ItemStack o, ISaveProvider container this.i = o; this.container = container; - this.filterItem = (AEItemKey) cell.getConfigInventory(i).getKey(0); - this.compressionChain = CompressionService.getChain(filterItem).orElseGet(Object2LongLinkedOpenHashMap::new); - this.unitFactor = compressionChain.containsKey(filterItem) ? compressionChain.getLong(filterItem) : 1; + var config = cell.getConfigInventory(i); + this.filterItem = (AEItemKey) config.getKey(0); + + var builder = IPartitionList.builder(); + builder.addAll(config.keySet()); + this.partitionList = builder.build(); + + this.compressed = CompressionService.getVariants(filterItem, false); + this.decompressed = CompressionService.getVariants(filterItem, true); + this.unitFactor = decompressed.values().intStream().asLongStream().reduce(1, Math::multiplyExact); this.storedItem = getTag().contains(KEY) ? AEItemKey.fromTag(getTag().getCompound(KEY)) : null; this.unitCount = !getTag().getString(UNIT_COUNT).isEmpty() @@ -111,22 +125,23 @@ public long insert(AEKey what, long amount, Actionable mode, IActionSource sourc return 0; } - if (!compressionEnabled && (!filterItem.equals(what) || storedItem != null && !storedItem.equals(what))) { + if (!compressionEnabled && (!partitionList.isListed(what) || storedItem != null && !storedItem.equals(what))) { return 0; } - if (compressionEnabled && !filterItem.equals(what) && !compressionChain.containsKey(what)) { + if (compressionEnabled + && !partitionList.isListed(what) + && !compressed.containsKey(item) + && !decompressed.containsKey(item)) { return 0; } - var factor = BigInteger.valueOf(compressionChain.containsKey(item) ? compressionChain.getLong(item) : 1); - var units = BigInteger.valueOf(amount).multiply(factor); + var units = BigInteger.valueOf(amount).multiply(compressedTransferFactor(item)); if (mode == Actionable.MODULATE) { if (storedItem == null) { storedItem = filterItem; } - unitCount = unitCount.add(units); saveChanges(); } @@ -141,7 +156,6 @@ public long extract(AEKey what, long amount, Actionable mode, IActionSource sour } var itemCount = unitCount.divide(BigInteger.valueOf(unitFactor)); - if (!compressionEnabled && (itemCount.signum() < 1 || !storedItem.equals(what))) { return 0; } @@ -149,12 +163,13 @@ public long extract(AEKey what, long amount, Actionable mode, IActionSource sour if (compressionEnabled && !storedItem.equals(what) && !filterItem.equals(what) - && !compressionChain.containsKey(item)) { + && !compressed.containsKey(item) + && !decompressed.containsKey(item)) { return 0; } - var factor = BigInteger.valueOf(compressionChain.containsKey(item) ? compressionChain.getLong(item) : 1); - var units = BigInteger.valueOf(amount).multiply(factor); + var extractionFactor = compressedTransferFactor(item); + var units = BigInteger.valueOf(amount).multiply(extractionFactor); var currentUnitCount = unitCount; if (currentUnitCount.compareTo(units) <= 0) { @@ -163,18 +178,41 @@ public long extract(AEKey what, long amount, Actionable mode, IActionSource sour unitCount = BigInteger.ZERO; saveChanges(); } - - return clampedLong(currentUnitCount.divide(factor), Long.MAX_VALUE); + return clampedLong(currentUnitCount.divide(extractionFactor), Long.MAX_VALUE); } else { if (mode == Actionable.MODULATE) { unitCount = unitCount.subtract(units); saveChanges(); } + return clampedLong(units.divide(extractionFactor), Long.MAX_VALUE); + } + } - return clampedLong(units.divide(factor), Long.MAX_VALUE); + private BigInteger compressedTransferFactor(AEItemKey what) { + if (compressed.getInt(what) > 0) { + return compressedTransferFactor(compressed, unitFactor, keys -> Pair.of(0, keys.indexOf(what) + 1)); + } else if (decompressed.getInt(what) > 0) { + return compressedTransferFactor(decompressed, 1, keys -> Pair.of(keys.indexOf(what) + 1, keys.size())); + } else { + return BigInteger.valueOf(unitFactor); } } + private BigInteger compressedTransferFactor( + Object2IntMap variants, long baseFactor, Function, Pair> subLister) { + var variantKeys = new LinkedList<>(variants.keySet()); + var toStored = new Object2IntLinkedOpenHashMap<>(variants); + + var range = subLister.apply(variantKeys); + toStored.keySet().retainAll(variantKeys.subList(range.first(), range.second())); + + for (var i : toStored.values()) { + baseFactor *= i; + } + + return BigInteger.valueOf(baseFactor); + } + private void saveChanges() { isPersisted = false; @@ -208,29 +246,37 @@ public void getAvailableStacks(KeyCounter out) { if (storedItem != null) { var stackLimit = (long) Math.pow(2, 42); - if (compressionEnabled && storedItem.equals(filterItem) && !compressionChain.isEmpty()) { + if (compressionEnabled && storedItem.equals(filterItem)) { + var allVariants = new Object2IntLinkedOpenHashMap(); + + if (!decompressed.isEmpty()) { + var decompressedKeys = new LinkedList<>(decompressed.keySet()); + Collections.reverse(decompressedKeys); + decompressedKeys.forEach(k -> allVariants.put(k, decompressed.getInt(k))); + + allVariants.put(storedItem, decompressed.getInt(decompressedKeys.getLast())); + allVariants.putAll(compressed); + } else if (!compressed.isEmpty()) { + allVariants.put( + storedItem, + compressed.values().intStream().findFirst().orElseThrow()); + allVariants.putAll(compressed); + } else { + allVariants.put(storedItem, 1); + } + var count = unitCount; - var variants = new ObjectArrayList<>(compressionChain.keySet()); - for (var i = 0; i < variants.size(); i++) { - var variant = variants.get(i); + for (var variant : allVariants.keySet()) { + var compressionFactor = BigInteger.valueOf(allVariants.getInt(variant)); - if (i == variants.size() - 1) { + if (count.divide(compressionFactor).signum() == 1 && variant != allVariants.lastKey()) { + out.add(variant, clampedLong(count.remainder(compressionFactor), stackLimit)); + count = count.divide(compressionFactor); + } else { out.add(variant, clampedLong(count, stackLimit)); highestCompressed = variant; - } else { - var nextVariant = variants.get(i + 1); - var compressionFactor = BigInteger.valueOf( - compressionChain.getLong(nextVariant) / compressionChain.getLong(variant)); - - if (count.divide(compressionFactor).signum() == 1) { - out.add(variant, count.remainder(compressionFactor).longValue()); - count = count.divide(compressionFactor); - } else { - out.add(variant, clampedLong(count, stackLimit)); - highestCompressed = variant; - break; - } + break; } } } else { @@ -241,7 +287,8 @@ public void getAvailableStacks(KeyCounter out) { @Override public boolean isPreferredStorageFor(AEKey what, IActionSource source) { - return what instanceof AEItemKey item && (filterItem.equals(item) || compressionChain.containsKey(item)); + return what instanceof AEItemKey item + && (partitionList.isListed(item) || compressed.containsKey(item) || decompressed.containsKey(item)); } @Override diff --git a/common/src/main/java/gripe/_90/megacells/service/CompressionService.java b/common/src/main/java/gripe/_90/megacells/service/CompressionService.java index 5579dd95..8ee04212 100644 --- a/common/src/main/java/gripe/_90/megacells/service/CompressionService.java +++ b/common/src/main/java/gripe/_90/megacells/service/CompressionService.java @@ -1,48 +1,59 @@ package gripe._90.megacells.service; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.stream.Stream; import it.unimi.dsi.fastutil.Pair; -import it.unimi.dsi.fastutil.objects.Object2LongLinkedOpenHashMap; -import it.unimi.dsi.fastutil.objects.Object2LongMap; +import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet; import net.minecraft.core.RegistryAccess; import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingRecipe; import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.world.item.crafting.RecipeType; import appeng.api.stacks.AEItemKey; -import gripe._90.megacells.definition.MEGATags; - public class CompressionService { - // Each chain is an ordered map with the items themselves as the keys and the values being how much of the smallest - // "unit" item in the chain makes up each subsequent variant item. - // e.g. 1 nugget -> 9 nuggets per ingot -> 81 nuggets per block -> etc. - private static final Set> compressionChains = new ObjectLinkedOpenHashSet<>(); - - // It may be desirable for some items to be included as variants in a chain in spite of any recipes involving those - // items not being reversible. Hence, we override any reversibility checks and generate a variant for such an item - // based on its usually irreversible recipe. - private static final Set overrides = new ObjectLinkedOpenHashSet<>(); + // Each chain is an ordered map with the items themselves as the keys and the values being the amount of either: + // - the item itself, needed to compress to its next variant + // - the next variant, when decompressing the item + // This value is typically either 4 or 9 for any given item. + private static final Set> compressionChains = new ObjectLinkedOpenHashSet<>(); - public static Optional> getChain(AEItemKey key) { + public static Optional> getChain(AEItemKey key) { return compressionChains.stream() .filter(chain -> chain.containsKey(key)) .findFirst(); } + public static Object2IntMap getVariants(AEItemKey key, boolean decompress) { + return getChain(key) + .map(chain -> { + var keys = new ObjectArrayList<>(chain.keySet()); + + // Reverse ordering when going from provided storage/filter variant to least-compressed "base unit" + if (decompress) { + Collections.reverse(keys); + } + + // Split variant chain into separate compressed/decompressed chains, omitting the initial variant + // provided + var variants = new Object2IntLinkedOpenHashMap(); + keys.subList(keys.indexOf(key) + 1, keys.size()).forEach(k -> variants.put(k, chain.getInt(k))); + return variants; + }) + .orElseGet(Object2IntLinkedOpenHashMap::new); + } + public static void loadRecipes(RecipeManager recipeManager, RegistryAccess access) { // Clear old variant cache in case of the server restarting or recipes being reloaded compressionChains.clear(); - overrides.clear(); // Retrieve all available "compression" and "decompression" recipes from the current server's recipe manager var allRecipes = recipeManager.getAllRecipesFor(RecipeType.CRAFTING); @@ -63,112 +74,33 @@ public static void loadRecipes(RecipeManager recipeManager, RegistryAccess acces .toList(); // Pull all available compression chains from the recipe shortlist and add these to the cache - for (var recipe : - Stream.concat(compressed.stream(), decompressed.stream()).toList()) { + for (var recipe : compressed) { var baseVariant = recipe.getResultItem(access).getItem(); if (compressionChains.stream().noneMatch(chain -> chain.containsKey(AEItemKey.of(baseVariant)))) { - compressionChains.add(generateChain(baseVariant, compressed, decompressed, access)); - } - } - } - - private static Object2LongMap generateChain( - Item baseVariant, - List compressed, - List decompressed, - RegistryAccess access) { - var chain = new Object2LongLinkedOpenHashMap(); - var compressionFactor = 1L; - - for (var lower = getNextVariant(baseVariant, decompressed, false, access); lower != null; ) { - baseVariant = lower.first(); - lower = getNextVariant(baseVariant, decompressed, false, access); - } - - chain.put(AEItemKey.of(baseVariant), compressionFactor); - - for (var higher = getNextVariant(baseVariant, compressed, true, access); higher != null; ) { - compressionFactor *= higher.second(); - chain.put(AEItemKey.of(higher.first()), compressionFactor); - higher = getNextVariant(higher.first(), compressed, true, access); - } - - return chain; - } + var newChain = generateChain(baseVariant, compressed, decompressed, access); - private static Pair getNextVariant( - Item item, List recipes, boolean compressed, RegistryAccess access) { - for (var override : overrides) { - if (override.smaller.equals(item) && compressed) { - return Pair.of(override.larger, override.factor); - } - - if (override.larger.equals(item) && !compressed) { - return Pair.of(override.smaller, override.factor); - } - } - - for (var recipe : recipes) { - for (var input : recipe.getIngredients().get(0).getItems()) { - if (input.getItem().equals(item)) { - return Pair.of( - recipe.getResultItem(access).getItem(), - compressed - ? recipe.getIngredients().size() - : recipe.getResultItem(access).getCount()); + if (!newChain.isEmpty()) { + compressionChains.add(newChain); } } } - - return null; - } - - private static boolean isDecompressionRecipe(CraftingRecipe recipe, RegistryAccess access) { - return recipe.getIngredients().size() == 1 - && Set.of(4, 9).contains(recipe.getResultItem(access).getCount()); } private static boolean isCompressionRecipe(CraftingRecipe recipe, RegistryAccess access) { - return sameIngredient(recipe) - && recipe.getResultItem(access).getCount() == 1 - && Set.of(4, 9).contains(recipe.getIngredients().size()); + return (recipe.getIngredients().size() == 4 || recipe.getIngredients().size() == 9) + && recipe.getIngredients().stream().distinct().count() <= 1 + && recipe.getResultItem(access).getCount() == 1; } - // All this for some fucking melons. - private static boolean sameIngredient(CraftingRecipe recipe) { - var ingredients = new ObjectArrayList<>(recipe.getIngredients()); - - if (ingredients.isEmpty()) { - return false; - } - - var first = ingredients.remove(0).getItems(); - if (first.length == 0) return false; - - for (var ingredient : ingredients) { - var stacks = ingredient.getItems(); - - if (stacks.length != first.length) { - return false; - } - - for (var i = 0; i < stacks.length; i++) { - if (!ItemStack.isSameItemSameTags(stacks[i], first[i])) { - return false; - } - } - } - - return true; + private static boolean isDecompressionRecipe(CraftingRecipe recipe, RegistryAccess access) { + return (recipe.getResultItem(access).getCount() == 4 + || recipe.getResultItem(access).getCount() == 9) + && recipe.getIngredients().size() == 1; } private static boolean isReversibleRecipe( CraftingRecipe recipe, List candidates, RegistryAccess access) { - if (overrideRecipe(recipe, access)) { - return true; - } - var compressible = false; var decompressible = false; @@ -194,20 +126,61 @@ private static boolean isReversibleRecipe( return false; } - private static boolean overrideRecipe(CraftingRecipe recipe, RegistryAccess access) { - for (var item : recipe.getIngredients().get(0).getItems()) { - if (item.is(MEGATags.COMPRESSION_OVERRIDES)) { - var variant = recipe.getResultItem(access); - var compressed = isCompressionRecipe(recipe, access); - var factor = compressed ? recipe.getIngredients().size() : variant.getCount(); + private static Object2IntMap generateChain( + Item baseVariant, + List compressed, + List decompressed, + RegistryAccess access) { + var decompressionChain = new Object2IntLinkedOpenHashMap(); - overrides.add(new Override(item.getItem(), variant.getItem(), compressed, factor)); - return true; - } + for (var lower = getNextVariant(baseVariant, decompressed, access); lower != null; ) { + decompressionChain.put(AEItemKey.of(lower.first()), (int) lower.second()); + lower = getNextVariant(lower.first(), decompressed, access); } - return false; + var compressionChain = new Object2IntLinkedOpenHashMap(); + + for (var higher = getNextVariant(baseVariant, compressed, access); higher != null; ) { + compressionChain.put(AEItemKey.of(higher.first()), (int) higher.second()); + higher = getNextVariant(higher.first(), compressed, access); + } + + // Collate decompression and compression chains together with base variant + var fullChain = new Object2IntLinkedOpenHashMap(); + + // In theory this shouldn't even be happening by this point + if (compressionChain.isEmpty() && decompressionChain.isEmpty()) return fullChain; + + // By default, full chains go from the smallest "unit" variant to the most compressed, so reverse the + // decompression chain and add it first + var decompressionKeys = new ObjectArrayList<>(decompressionChain.keySet()); + Collections.reverse(decompressionKeys); + decompressionKeys.forEach(k -> fullChain.put(k, decompressionChain.getInt(k))); + + // Retrieve appropriate multiplier for base variant for completion's sake + fullChain.put( + AEItemKey.of(baseVariant), + fullChain.isEmpty() + ? compressionChain.getInt(compressionChain.firstKey()) + : fullChain.getInt(fullChain.lastKey())); + + fullChain.putAll(compressionChain); + return fullChain; } - private record Override(Item smaller, Item larger, boolean compressed, int factor) {} + private static Pair getNextVariant(Item item, List recipes, RegistryAccess access) { + for (var recipe : recipes) { + for (var input : recipe.getIngredients().get(0).getItems()) { + if (input.getItem().equals(item)) { + return Pair.of( + recipe.getResultItem(access).getItem(), + isCompressionRecipe(recipe, access) + ? recipe.getIngredients().size() + : recipe.getResultItem(access).getCount()); + } + } + } + + return null; + } } diff --git a/common/src/main/java/gripe/_90/megacells/service/DecompressionService.java b/common/src/main/java/gripe/_90/megacells/service/DecompressionService.java index 9f4b1e96..c85a630d 100644 --- a/common/src/main/java/gripe/_90/megacells/service/DecompressionService.java +++ b/common/src/main/java/gripe/_90/megacells/service/DecompressionService.java @@ -5,8 +5,8 @@ import java.util.Optional; import java.util.Set; -import it.unimi.dsi.fastutil.objects.Object2LongLinkedOpenHashMap; -import it.unimi.dsi.fastutil.objects.Object2LongMap; +import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet; @@ -23,7 +23,7 @@ import gripe._90.megacells.item.cell.BulkCellInventory; public class DecompressionService implements IGridService, IGridServiceProvider { - private final Set> decompressionChains = new ObjectLinkedOpenHashSet<>(); + private final Set> decompressionChains = new ObjectLinkedOpenHashSet<>(); private final List cellHosts = new ObjectArrayList<>(); @Override @@ -55,17 +55,17 @@ public void onServerStartTick() { } } - private Optional> getChain(BulkCellInventory cell) { + private Optional> getChain(BulkCellInventory cell) { return CompressionService.getChain(cell.getStoredItem()).map(c -> { var keys = new ObjectArrayList<>(c.keySet()); Collections.reverse(keys); - var decompressed = new Object2LongLinkedOpenHashMap(); + var decompressed = new Object2IntLinkedOpenHashMap(); var highest = keys.indexOf(cell.getHighestCompressed()); if (highest > -1) { for (var key : keys.subList(highest, keys.size())) { - decompressed.put(key, c.getLong(key)); + decompressed.put(key, c.getInt(key)); } } @@ -73,12 +73,12 @@ private Optional> getChain(BulkCellInventory cell) { }); } - public Set> getDecompressionChains() { + public Set> getDecompressionChains() { return Collections.unmodifiableSet(decompressionChains); } - public Set getDecompressionPatterns(Object2LongMap decompressionChain) { - var variants = new ObjectArrayList<>(decompressionChain.keySet()); + public Set getDecompressionPatterns(Object2IntMap compressionChain) { + var variants = new ObjectArrayList<>(compressionChain.keySet()); var patterns = new ObjectLinkedOpenHashSet(); for (var variant : variants) { @@ -88,9 +88,9 @@ public Set getDecompressionPatterns(Object2LongMap decompr var pattern = new ItemStack(MEGAItems.DECOMPRESSION_PATTERN); var decompressed = variants.get(variants.indexOf(variant) + 1); - var factor = decompressionChain.getLong(variant) / decompressionChain.getLong(decompressed); + var factor = compressionChain.getInt(decompressed); - DecompressionPatternEncoding.encode(pattern.getOrCreateTag(), variant, decompressed, (int) factor); + DecompressionPatternEncoding.encode(pattern.getOrCreateTag(), variant, decompressed, factor); patterns.add(AEItemKey.of(pattern)); } diff --git a/fabric/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java b/fabric/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java index 949269b6..3003ca5d 100644 --- a/fabric/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java +++ b/fabric/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java @@ -14,9 +14,9 @@ public void onInitializeDataGenerator(FabricDataGenerator generator) { var pack = generator.createPack(); var registries = CompletableFuture.supplyAsync(VanillaRegistries::createLookup, Util.backgroundExecutor()); - var blocks = pack.addProvider((FabricDataOutput output) -> new CommonTagProvider.BlockTags(output, registries)); + var blockTags = pack.addProvider((FabricDataOutput output) -> new CommonTagProvider.Blocks(output, registries)); pack.addProvider((FabricDataOutput output) -> - new CommonTagProvider.ItemTags(output, registries, blocks.contentsGetter())); + new CommonTagProvider.Items(output, registries, blockTags.contentsGetter())); pack.addProvider(ModelProvider::new); pack.addProvider(RecipeProvider::new); diff --git a/forge/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java b/forge/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java index 32fd4e2d..0689ae3b 100644 --- a/forge/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java +++ b/forge/src/data/java/gripe/_90/megacells/datagen/MEGADataGenerators.java @@ -19,8 +19,8 @@ public static void onGatherData(GatherDataEvent event) { var existing = event.getExistingFileHelper(); var registries = CompletableFuture.supplyAsync(VanillaRegistries::createLookup, Util.backgroundExecutor()); - var blockTags = pack.addProvider(output -> new CommonTagProvider.BlockTags(output, registries)); - pack.addProvider(output -> new CommonTagProvider.ItemTags(output, registries, blockTags.contentsGetter())); + var blockTags = pack.addProvider(output -> new CommonTagProvider.Blocks(output, registries)); + pack.addProvider(output -> new CommonTagProvider.Items(output, registries, blockTags.contentsGetter())); pack.addProvider(output -> new ModelProvider.Items(output, existing)); pack.addProvider(output -> new ModelProvider.Blocks(output, existing));