From 3b8931f90a26dea849d7abded2fcb8881d92bedd Mon Sep 17 00:00:00 2001 From: 90 Date: Sat, 2 Sep 2023 18:46:52 +0100 Subject: [PATCH] bluh --- .../item/cell/BulkCellInventory.java | 3 ++- .../megacells/util/CompressionService.java | 27 ++++++++++--------- .../_90/megacells/fabric/FabricPlatform.java | 4 +-- .../_90/megacells/forge/ForgePlatform.java | 4 +-- 4 files changed, 21 insertions(+), 17 deletions(-) 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 788e7184..c7a10e2e 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 @@ -50,7 +50,8 @@ public BulkCellInventory(MEGABulkCell cell, ItemStack o, ISaveProvider container : BigInteger.ZERO; compressionEnabled = cell.getUpgrades(i).isInstalled(COMPRESSION_CARD); - compressionChain = CompressionService.getChain(storedItem != null ? storedItem : filterItem) + compressionChain = CompressionService.INSTANCE + .getChain(storedItem != null ? storedItem : filterItem) .orElseGet(CompressionChain::new); unitFactor = compressionChain.unitFactor(storedItem != null ? storedItem : filterItem); } diff --git a/common/src/main/java/gripe/_90/megacells/util/CompressionService.java b/common/src/main/java/gripe/_90/megacells/util/CompressionService.java index e39c2187..733ad726 100644 --- a/common/src/main/java/gripe/_90/megacells/util/CompressionService.java +++ b/common/src/main/java/gripe/_90/megacells/util/CompressionService.java @@ -21,16 +21,20 @@ import gripe._90.megacells.definition.MEGATags; public class CompressionService { - private static final Set compressionChains = new ObjectLinkedOpenHashSet<>(); - private static final Set overrides = new ObjectLinkedOpenHashSet<>(); + public static final CompressionService INSTANCE = new CompressionService(); - public static Optional getChain(AEItemKey item) { + private final Set compressionChains = new ObjectLinkedOpenHashSet<>(); + private final Set overrides = new ObjectLinkedOpenHashSet<>(); + + private CompressionService() {} + + public Optional getChain(AEItemKey item) { return compressionChains.stream() .filter(chain -> chain.containsVariant(item)) .findFirst(); } - public static void loadRecipes(RecipeManager recipeManager, RegistryAccess access) { + public void loadRecipes(RecipeManager recipeManager, RegistryAccess access) { // Clear old variant cache in case of the server restarting or recipes being reloaded compressionChains.clear(); overrides.clear(); @@ -63,7 +67,7 @@ public static void loadRecipes(RecipeManager recipeManager, RegistryAccess acces }); } - private static CompressionChain generateChain( + private CompressionChain generateChain( Item baseVariant, List compressed, List decompressed, @@ -94,7 +98,7 @@ private static CompressionChain generateChain( return chain; } - private static CompressionVariant getNextVariant( + private CompressionVariant getNextVariant( Item item, List recipes, boolean compressed, RegistryAccess access) { for (var override : overrides) { if (compressed && override.smaller.equals(item)) { @@ -121,19 +125,19 @@ private static CompressionVariant getNextVariant( return null; } - private static boolean isDecompressionRecipe(CraftingRecipe recipe, RegistryAccess access) { + private 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) { + private boolean isCompressionRecipe(CraftingRecipe recipe, RegistryAccess access) { return sameIngredient(recipe) && recipe.getResultItem(access).getCount() == 1 && Set.of(4, 9).contains(recipe.getIngredients().size()); } // All this for some fucking melons. - private static boolean sameIngredient(CraftingRecipe recipe) { + private boolean sameIngredient(CraftingRecipe recipe) { var ingredients = new ObjectArrayList<>(recipe.getIngredients()); if (ingredients.isEmpty()) { @@ -163,8 +167,7 @@ private static boolean sameIngredient(CraftingRecipe recipe) { return true; } - private static boolean isReversibleRecipe( - CraftingRecipe recipe, List candidates, RegistryAccess access) { + private boolean isReversibleRecipe(CraftingRecipe recipe, List candidates, RegistryAccess access) { if (overrideRecipe(recipe, access)) { return true; } @@ -194,7 +197,7 @@ private static boolean isReversibleRecipe( return false; } - private static boolean overrideRecipe(CraftingRecipe recipe, RegistryAccess access) { + private boolean overrideRecipe(CraftingRecipe recipe, RegistryAccess access) { var compressed = isCompressionRecipe(recipe, access); var output = recipe.getResultItem(access); 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 be50aec9..16c69274 100644 --- a/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java +++ b/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java @@ -29,9 +29,9 @@ public boolean isAddonLoaded(Addons addon) { @Override public void initCompression() { ServerLifecycleEvents.SERVER_STARTED.register( - server -> CompressionService.loadRecipes(server.getRecipeManager(), server.registryAccess())); + server -> CompressionService.INSTANCE.loadRecipes(server.getRecipeManager(), server.registryAccess())); ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((server, resourceManager, success) -> { - if (success) CompressionService.loadRecipes(server.getRecipeManager(), server.registryAccess()); + if (success) CompressionService.INSTANCE.loadRecipes(server.getRecipeManager(), server.registryAccess()); }); } } 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 c7a9380c..56821800 100644 --- a/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java +++ b/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java @@ -38,9 +38,9 @@ public boolean isAddonLoaded(Addons addon) { @Override public void initCompression() { - MinecraftForge.EVENT_BUS.addListener((ServerStartedEvent event) -> CompressionService.loadRecipes( + MinecraftForge.EVENT_BUS.addListener((ServerStartedEvent event) -> CompressionService.INSTANCE.loadRecipes( event.getServer().getRecipeManager(), event.getServer().registryAccess())); - MinecraftForge.EVENT_BUS.addListener((AddReloadListenerEvent event) -> CompressionService.loadRecipes( + MinecraftForge.EVENT_BUS.addListener((AddReloadListenerEvent event) -> CompressionService.INSTANCE.loadRecipes( event.getServerResources().getRecipeManager(), event.getRegistryAccess())); } }