Skip to content

Commit

Permalink
Remove reversibility override system for the time being
Browse files Browse the repository at this point in the history
(At least until an implementation is found that doesn't fucking OOM)
  • Loading branch information
62832 committed Aug 30, 2023
1 parent 3e87b5b commit ee2e0f7
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.data.PackOutput;
import net.minecraft.data.tags.IntrinsicHolderTagsProvider;
import net.minecraft.data.tags.ItemTagsProvider;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;

import appeng.api.features.P2PTunnelAttunement;
Expand Down Expand Up @@ -36,15 +35,6 @@ 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)
.add(Items.ICE, Items.PACKED_ICE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,4 @@ public final class MEGATags {

public static final TagKey<Item> MEGA_PATTERN_PROVIDER =
TagKey.create(Registries.ITEM, MEGACells.makeId("mega_pattern_provider"));

public static final TagKey<Item> COMPRESSION_OVERRIDES =
TagKey.create(Registries.ITEM, MEGACells.makeId("compression_overrides"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void getAvailableStacks(KeyCounter out) {
if (storedItem != null) {
var stackLimit = (long) Math.pow(2, 42);

if (compressionEnabled && storedItem.equals(filterItem)) {
if (compressionEnabled && storedItem.equals(filterItem) && !compressionChain.isEmpty()) {
var count = unitCount;
var chain = compressionChain.lastMultiplierSwapped();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
Expand All @@ -18,11 +17,8 @@

import appeng.api.stacks.AEItemKey;

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 Optional<CompressionChain> getChain(AEItemKey item) {
return compressionChains.stream()
Expand All @@ -33,7 +29,6 @@ public static Optional<CompressionChain> getChain(AEItemKey item) {
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);
Expand All @@ -54,8 +49,7 @@ 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.containsVariant(AEItemKey.of(baseVariant)))) {
Expand Down Expand Up @@ -97,16 +91,6 @@ private static CompressionChain generateChain(

private static CompressionVariant getNextVariant(
Item item, List<CraftingRecipe> recipes, boolean compressed, RegistryAccess access) {
for (var override : overrides) {
if (override.smaller.equals(item) && compressed) {
return new CompressionVariant(override.larger, override.factor);
}

if (override.larger.equals(item) && !compressed) {
return new CompressionVariant(override.smaller, override.factor);
}
}

for (var recipe : recipes) {
for (var input : recipe.getIngredients().get(0).getItems()) {
if (input.getItem().equals(item)) {
Expand Down Expand Up @@ -163,10 +147,6 @@ private static boolean sameIngredient(CraftingRecipe recipe) {

private static boolean isReversibleRecipe(
CraftingRecipe recipe, List<CraftingRecipe> candidates, RegistryAccess access) {
if (overrideRecipe(recipe, access)) {
return true;
}

var compressible = false;
var decompressible = false;

Expand All @@ -191,21 +171,4 @@ 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();

overrides.add(new Override(item.getItem(), variant.getItem(), compressed, factor));
return true;
}
}

return false;
}

private record Override(Item smaller, Item larger, boolean compressed, int factor) {}
}

0 comments on commit ee2e0f7

Please sign in to comment.