Skip to content

Commit

Permalink
bluh
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Sep 2, 2023
1 parent 9f661ac commit 3b8931f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@
import gripe._90.megacells.definition.MEGATags;

public class CompressionService {
private static final Set<CompressionChain> compressionChains = new ObjectLinkedOpenHashSet<>();
private static final Set<Override> overrides = new ObjectLinkedOpenHashSet<>();
public static final CompressionService INSTANCE = new CompressionService();

public static Optional<CompressionChain> getChain(AEItemKey item) {
private final Set<CompressionChain> compressionChains = new ObjectLinkedOpenHashSet<>();
private final Set<Override> overrides = new ObjectLinkedOpenHashSet<>();

private CompressionService() {}

public Optional<CompressionChain> 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();
Expand Down Expand Up @@ -63,7 +67,7 @@ public static void loadRecipes(RecipeManager recipeManager, RegistryAccess acces
});
}

private static CompressionChain generateChain(
private CompressionChain generateChain(
Item baseVariant,
List<CraftingRecipe> compressed,
List<CraftingRecipe> decompressed,
Expand Down Expand Up @@ -94,7 +98,7 @@ private static CompressionChain generateChain(
return chain;
}

private static CompressionVariant getNextVariant(
private CompressionVariant getNextVariant(
Item item, List<CraftingRecipe> recipes, boolean compressed, RegistryAccess access) {
for (var override : overrides) {
if (compressed && override.smaller.equals(item)) {
Expand All @@ -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()) {
Expand Down Expand Up @@ -163,8 +167,7 @@ private static boolean sameIngredient(CraftingRecipe recipe) {
return true;
}

private static boolean isReversibleRecipe(
CraftingRecipe recipe, List<CraftingRecipe> candidates, RegistryAccess access) {
private boolean isReversibleRecipe(CraftingRecipe recipe, List<CraftingRecipe> candidates, RegistryAccess access) {
if (overrideRecipe(recipe, access)) {
return true;
}
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

0 comments on commit 3b8931f

Please sign in to comment.