diff --git a/common/src/main/java/gripe/_90/megacells/MEGACells.java b/common/src/main/java/gripe/_90/megacells/MEGACells.java index 6559f8ba..4f874e20 100644 --- a/common/src/main/java/gripe/_90/megacells/MEGACells.java +++ b/common/src/main/java/gripe/_90/megacells/MEGACells.java @@ -19,7 +19,6 @@ import appeng.core.localization.GuiText; import appeng.hotkeys.HotkeyActions; -import gripe._90.megacells.compression.DecompressionService; import gripe._90.megacells.core.Addons; import gripe._90.megacells.core.Platform; import gripe._90.megacells.definition.MEGABlockEntities; @@ -30,6 +29,7 @@ import gripe._90.megacells.integration.appbot.AppBotIntegration; import gripe._90.megacells.integration.appbot.AppBotItems; import gripe._90.megacells.item.cell.BulkCellItem; +import gripe._90.megacells.misc.DecompressionService; public final class MEGACells { private MEGACells() {} @@ -52,41 +52,39 @@ public static void initCommon() { MEGABlocks.init(); MEGABlockEntities.init(); - if (MEGACells.PLATFORM.isAddonLoaded(Addons.APPBOT)) { + if (PLATFORM.isAddonLoaded(Addons.APPBOT)) { AppBotItems.init(); } initStorageCells(); - MEGACells.PLATFORM.initCompression(); + PLATFORM.initCompression(); GridServices.register(DecompressionService.class, DecompressionService.class); - MEGACells.PLATFORM.addVillagerTrade(MEGAItems.SKY_STEEL_INGOT, 8, 3, 20); - MEGACells.PLATFORM.addVillagerTrade(MEGAItems.ACCUMULATION_PROCESSOR_PRESS, 40, 1, 50); + PLATFORM.addVillagerTrade(MEGAItems.SKY_STEEL_INGOT, 8, 3, 20); + PLATFORM.addVillagerTrade(MEGAItems.ACCUMULATION_PROCESSOR_PRESS, 40, 1, 50); } private static void initStorageCells() { Stream.of(MEGAItems.getItemCells(), MEGAItems.getItemPortables()) .flatMap(Collection::stream) - .forEach(c -> StorageCellModels.registerModel(c, MEGACells.makeId("block/drive/cells/mega_item_cell"))); + .forEach(c -> StorageCellModels.registerModel(c, makeId("block/drive/cells/mega_item_cell"))); Stream.of(MEGAItems.getFluidCells(), MEGAItems.getFluidPortables()) .flatMap(Collection::stream) - .forEach( - c -> StorageCellModels.registerModel(c, MEGACells.makeId("block/drive/cells/mega_fluid_cell"))); + .forEach(c -> StorageCellModels.registerModel(c, makeId("block/drive/cells/mega_fluid_cell"))); StorageCells.addCellHandler(BulkCellItem.HANDLER); - StorageCellModels.registerModel(MEGAItems.BULK_ITEM_CELL, MEGACells.makeId("block/drive/cells/bulk_item_cell")); + StorageCellModels.registerModel(MEGAItems.BULK_ITEM_CELL, makeId("block/drive/cells/bulk_item_cell")); MEGAItems.getItemPortables() .forEach(cell -> HotkeyActions.registerPortableCell(cell, HotkeyAction.PORTABLE_ITEM_CELL)); MEGAItems.getFluidPortables() .forEach(cell -> HotkeyActions.registerPortableCell(cell, HotkeyAction.PORTABLE_FLUID_CELL)); - if (MEGACells.PLATFORM.isAddonLoaded(Addons.APPBOT)) { + if (PLATFORM.isAddonLoaded(Addons.APPBOT)) { Stream.of(AppBotItems.getCells(), AppBotItems.getPortables()) .flatMap(Collection::stream) - .forEach(c -> - StorageCellModels.registerModel(c, MEGACells.makeId("block/drive/cells/mega_mana_cell"))); + .forEach(c -> StorageCellModels.registerModel(c, makeId("block/drive/cells/mega_mana_cell"))); } } @@ -152,11 +150,11 @@ public static void initUpgrades() { Upgrades.add(MEGAItems.GREATER_ENERGY_CARD, portableCell, 2, portableCellGroup); } - if (MEGACells.PLATFORM.isAddonLoaded(Addons.AE2WTLIB)) { + if (PLATFORM.isAddonLoaded(Addons.AE2WTLIB)) { AE2WTIntegration.initUpgrades(); } - if (MEGACells.PLATFORM.isAddonLoaded(Addons.APPBOT)) { + if (PLATFORM.isAddonLoaded(Addons.APPBOT)) { AppBotIntegration.initUpgrades(); } } diff --git a/common/src/main/java/gripe/_90/megacells/compression/CompressionVariant.java b/common/src/main/java/gripe/_90/megacells/compression/CompressionVariant.java deleted file mode 100644 index 88dc27cf..00000000 --- a/common/src/main/java/gripe/_90/megacells/compression/CompressionVariant.java +++ /dev/null @@ -1,11 +0,0 @@ -package gripe._90.megacells.compression; - -import net.minecraft.world.item.Item; - -import appeng.api.stacks.AEItemKey; - -public record CompressionVariant(AEItemKey item, byte factor) { - public CompressionVariant(Item item, byte factor) { - this(AEItemKey.of(item), factor); - } -} diff --git a/common/src/main/java/gripe/_90/megacells/definition/MEGAItems.java b/common/src/main/java/gripe/_90/megacells/definition/MEGAItems.java index 1528f5f2..4331c81b 100644 --- a/common/src/main/java/gripe/_90/megacells/definition/MEGAItems.java +++ b/common/src/main/java/gripe/_90/megacells/definition/MEGAItems.java @@ -23,7 +23,7 @@ import appeng.menu.me.common.MEStorageMenu; import gripe._90.megacells.MEGACells; -import gripe._90.megacells.compression.DecompressionPatternItem; +import gripe._90.megacells.item.DecompressionPatternItem; import gripe._90.megacells.item.cell.BulkCellItem; import gripe._90.megacells.item.cell.MEGAPortableCell; import gripe._90.megacells.item.part.CellDockPart; diff --git a/common/src/main/java/gripe/_90/megacells/compression/DecompressionPatternItem.java b/common/src/main/java/gripe/_90/megacells/item/DecompressionPatternItem.java similarity index 92% rename from common/src/main/java/gripe/_90/megacells/compression/DecompressionPatternItem.java rename to common/src/main/java/gripe/_90/megacells/item/DecompressionPatternItem.java index 41c9ddee..3161475d 100644 --- a/common/src/main/java/gripe/_90/megacells/compression/DecompressionPatternItem.java +++ b/common/src/main/java/gripe/_90/megacells/item/DecompressionPatternItem.java @@ -1,4 +1,4 @@ -package gripe._90.megacells.compression; +package gripe._90.megacells.item; import org.jetbrains.annotations.Nullable; @@ -9,6 +9,7 @@ import appeng.crafting.pattern.EncodedPatternItem; import gripe._90.megacells.MEGACells; +import gripe._90.megacells.misc.DecompressionPattern; public class DecompressionPatternItem extends EncodedPatternItem { public DecompressionPatternItem(Properties properties) { 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 2e9b2b9f..9b85a14f 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 @@ -17,8 +17,8 @@ import appeng.api.storage.cells.ISaveProvider; import appeng.api.storage.cells.StorageCell; -import gripe._90.megacells.compression.CompressionChain; -import gripe._90.megacells.compression.CompressionService; +import gripe._90.megacells.misc.CompressionChain; +import gripe._90.megacells.misc.CompressionService; public class BulkCellInventory implements StorageCell { private static final String KEY = "key"; @@ -231,7 +231,7 @@ public void getAvailableStacks(KeyCounter out) { var compressionFactor = BigInteger.valueOf(variant.factor()); var key = variant.item(); - if (count.divide(compressionFactor).signum() == 1 && variant != chain.last()) { + if (count.divide(compressionFactor).signum() == 1 && variant != chain.get(chain.size() - 1)) { out.add(key, count.remainder(compressionFactor).longValue()); count = count.divide(compressionFactor); } else { diff --git a/common/src/main/java/gripe/_90/megacells/item/part/DecompressionModulePart.java b/common/src/main/java/gripe/_90/megacells/item/part/DecompressionModulePart.java index a3b4e1e5..77b2a7d2 100644 --- a/common/src/main/java/gripe/_90/megacells/item/part/DecompressionModulePart.java +++ b/common/src/main/java/gripe/_90/megacells/item/part/DecompressionModulePart.java @@ -24,8 +24,8 @@ import appeng.parts.PartModel; import gripe._90.megacells.MEGACells; -import gripe._90.megacells.compression.DecompressionPattern; -import gripe._90.megacells.compression.DecompressionService; +import gripe._90.megacells.misc.DecompressionPattern; +import gripe._90.megacells.misc.DecompressionService; public class DecompressionModulePart extends AEBasePart implements ICraftingProvider, IGridTickable { @PartModels diff --git a/common/src/main/java/gripe/_90/megacells/compression/CompressionChain.java b/common/src/main/java/gripe/_90/megacells/misc/CompressionChain.java similarity index 82% rename from common/src/main/java/gripe/_90/megacells/compression/CompressionChain.java rename to common/src/main/java/gripe/_90/megacells/misc/CompressionChain.java index 4de6c4d2..9ec2f62f 100644 --- a/common/src/main/java/gripe/_90/megacells/compression/CompressionChain.java +++ b/common/src/main/java/gripe/_90/megacells/misc/CompressionChain.java @@ -1,4 +1,4 @@ -package gripe._90.megacells.compression; +package gripe._90.megacells.misc; import java.math.BigInteger; import java.util.Collections; @@ -10,9 +10,9 @@ import gripe._90.megacells.definition.MEGAConfig; -public class CompressionChain extends ObjectArrayList { +public class CompressionChain extends ObjectArrayList { public void add(AEItemKey item, byte factor) { - this.add(new CompressionVariant(item, factor)); + this.add(new CompressionService.Variant(item, factor)); } public boolean containsVariant(AEItemKey item) { @@ -30,15 +30,11 @@ public BigInteger unitFactor(AEItemKey item) { return subChain.stream().map(v -> BigInteger.valueOf(v.factor())).reduce(BigInteger.ONE, BigInteger::multiply); } - public CompressionVariant last() { - return get(size - 1); - } - public CompressionChain lastMultiplierSwapped() { - var multipliers = this.stream().map(CompressionVariant::factor).collect(Collectors.toList()); + var multipliers = this.stream().map(CompressionService.Variant::factor).collect(Collectors.toList()); Collections.rotate(multipliers, -1); - var items = this.stream().map(CompressionVariant::item).toList(); + var items = this.stream().map(CompressionService.Variant::item).toList(); var chain = new CompressionChain(); for (var i = 0; i < items.size(); i++) { diff --git a/common/src/main/java/gripe/_90/megacells/compression/CompressionService.java b/common/src/main/java/gripe/_90/megacells/misc/CompressionService.java similarity index 94% rename from common/src/main/java/gripe/_90/megacells/compression/CompressionService.java rename to common/src/main/java/gripe/_90/megacells/misc/CompressionService.java index f527ca13..2196e48e 100644 --- a/common/src/main/java/gripe/_90/megacells/compression/CompressionService.java +++ b/common/src/main/java/gripe/_90/megacells/misc/CompressionService.java @@ -1,4 +1,4 @@ -package gripe._90.megacells.compression; +package gripe._90.megacells.misc; import java.util.Arrays; import java.util.Collection; @@ -116,22 +116,21 @@ private CompressionChain generateChain( return chain; } - private CompressionVariant getNextVariant( - Item item, List recipes, boolean compressed, RegistryAccess access) { + private Variant getNextVariant(Item item, List recipes, boolean compressed, RegistryAccess access) { for (var override : overrides) { if (compressed && override.smaller.equals(item)) { - return new CompressionVariant(override.larger, override.factor); + return new Variant(override.larger, override.factor); } if (!compressed && override.larger.equals(item)) { - return new CompressionVariant(override.smaller, override.factor); + return new Variant(override.smaller, override.factor); } } for (var recipe : recipes) { for (var input : recipe.getIngredients().get(0).getItems()) { if (input.getItem().equals(item)) { - return new CompressionVariant(recipe.getResultItem(access).getItem(), (byte) + return new Variant(recipe.getResultItem(access).getItem(), (byte) (compressed ? recipe.getIngredients().size() : recipe.getResultItem(access).getCount())); @@ -225,5 +224,11 @@ private boolean overrideRecipe(CraftingRecipe recipe, RegistryAccess access) { return false; } + public record Variant(AEItemKey item, byte factor) { + private Variant(Item item, byte factor) { + this(AEItemKey.of(item), factor); + } + } + private record Override(Item smaller, Item larger, byte factor) {} } diff --git a/common/src/main/java/gripe/_90/megacells/compression/DecompressionPattern.java b/common/src/main/java/gripe/_90/megacells/misc/DecompressionPattern.java similarity index 98% rename from common/src/main/java/gripe/_90/megacells/compression/DecompressionPattern.java rename to common/src/main/java/gripe/_90/megacells/misc/DecompressionPattern.java index c00216f8..3d68c542 100644 --- a/common/src/main/java/gripe/_90/megacells/compression/DecompressionPattern.java +++ b/common/src/main/java/gripe/_90/megacells/misc/DecompressionPattern.java @@ -1,4 +1,4 @@ -package gripe._90.megacells.compression; +package gripe._90.megacells.misc; import java.util.Objects; diff --git a/common/src/main/java/gripe/_90/megacells/compression/DecompressionService.java b/common/src/main/java/gripe/_90/megacells/misc/DecompressionService.java similarity index 86% rename from common/src/main/java/gripe/_90/megacells/compression/DecompressionService.java rename to common/src/main/java/gripe/_90/megacells/misc/DecompressionService.java index d9998daa..db6a3397 100644 --- a/common/src/main/java/gripe/_90/megacells/compression/DecompressionService.java +++ b/common/src/main/java/gripe/_90/megacells/misc/DecompressionService.java @@ -1,4 +1,4 @@ -package gripe._90.megacells.compression; +package gripe._90.megacells.misc; import java.util.Collections; import java.util.List; @@ -8,7 +8,6 @@ import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet; import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.item.ItemStack; import appeng.api.crafting.IPatternDetails; import appeng.api.implementations.blockentities.IChestOrDrive; @@ -83,14 +82,14 @@ private Set generatePatterns(BulkCellInventory cell) { var decompressionChain = fullChain.limited().reversed(); for (var variant : decompressionChain) { - if (variant == decompressionChain.last()) { + if (variant == decompressionChain.get(decompressionChain.size() - 1)) { continue; } - var pattern = new ItemStack(MEGAItems.DECOMPRESSION_PATTERN); + var pattern = MEGAItems.DECOMPRESSION_PATTERN.stack(); var decompressed = decompressionChain.get(decompressionChain.indexOf(variant) + 1); - encodePattern(pattern.getOrCreateTag(), decompressed.item(), variant, false); + encode(pattern.getOrCreateTag(), decompressed.item(), variant, false); patterns.add(new DecompressionPattern(pattern)); } @@ -101,17 +100,17 @@ private Set generatePatterns(BulkCellInventory cell) { continue; } - var pattern = new ItemStack(MEGAItems.DECOMPRESSION_PATTERN); + var pattern = MEGAItems.DECOMPRESSION_PATTERN.stack(); var decompressed = compressionChain.get(compressionChain.indexOf(variant) - 1); - encodePattern(pattern.getOrCreateTag(), decompressed.item(), variant, true); + encode(pattern.getOrCreateTag(), decompressed.item(), variant, true); patterns.add(new DecompressionPattern(pattern)); } return patterns; } - private void encodePattern(CompoundTag tag, AEItemKey base, CompressionVariant variant, boolean toCompress) { + private void encode(CompoundTag tag, AEItemKey base, CompressionService.Variant variant, boolean toCompress) { tag.put(DecompressionPattern.NBT_VARIANT, variant.item().toTag()); tag.put(DecompressionPattern.NBT_BASE, base.toTag()); tag.putInt(DecompressionPattern.NBT_FACTOR, variant.factor()); diff --git a/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java b/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java index ba54f858..357c1911 100644 --- a/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java +++ b/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java @@ -25,10 +25,10 @@ import appeng.core.definitions.AEBlocks; import appeng.init.InitVillager; -import gripe._90.megacells.compression.CompressionService; import gripe._90.megacells.core.Addons; import gripe._90.megacells.core.Loaders; import gripe._90.megacells.core.Platform; +import gripe._90.megacells.misc.CompressionService; public final class FabricPlatform implements Platform { @Override diff --git a/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java b/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java index 74f1fbe2..935c0043 100644 --- a/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java +++ b/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java @@ -38,10 +38,10 @@ import appeng.core.definitions.AEBlocks; import appeng.init.InitVillager; -import gripe._90.megacells.compression.CompressionService; import gripe._90.megacells.core.Addons; import gripe._90.megacells.core.Loaders; import gripe._90.megacells.core.Platform; +import gripe._90.megacells.misc.CompressionService; public final class ForgePlatform implements Platform { @Override