diff --git a/build.properties b/build.properties index 756b1b2..3375784 100644 --- a/build.properties +++ b/build.properties @@ -1,9 +1,9 @@ -#Thu Apr 11 18:45:01 UTC 2024 +#Tue Jun 11 13:34:58 UTC 2024 mapping_version=1.20.1 version=1.0 mod_name=Zeta mc_version=1.20.1 mapping_channel=official mod_id=zeta -build_number=17 +build_number=20 dir_output=../Build Output/Zeta/ diff --git a/changelog.txt b/changelog.txt index c3422bf..1541f6c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1 +1,6 @@ -- Made some minor tweaks to the creative tab addition logic to try and fix whatever is going on with the sporadic tabs disappearing/crashing bug \ No newline at end of file +- mass recipe get can now also get tags +- recipe crawl event will ignore catalyst items +- Recipe crawl digestion will only target vanilla recipe types as to noc cause problems with unknown recipe types that could have some different interpretation +- moved recipe handler methods in recipe digest event + +(sorry for triple release i messed up :/) \ No newline at end of file diff --git a/src/main/java/org/violetmoon/zeta/event/play/ZRecipeCrawl.java b/src/main/java/org/violetmoon/zeta/event/play/ZRecipeCrawl.java index 1ff638a..022e19b 100644 --- a/src/main/java/org/violetmoon/zeta/event/play/ZRecipeCrawl.java +++ b/src/main/java/org/violetmoon/zeta/event/play/ZRecipeCrawl.java @@ -1,7 +1,16 @@ package org.violetmoon.zeta.event.play; import java.util.Collection; - +import java.util.List; +import java.util.Set; +import java.util.function.Consumer; + +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import com.google.common.collect.Streams; +import net.minecraft.core.registries.BuiltInRegistries; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import org.violetmoon.zeta.event.bus.IZetaPlayEvent; import com.google.common.collect.Multimap; @@ -17,32 +26,13 @@ import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.ShapedRecipe; import net.minecraft.world.item.crafting.ShapelessRecipe; +import org.violetmoon.zeta.util.RegistryUtil; public abstract class ZRecipeCrawl implements IZetaPlayEvent { public static class Reset extends ZRecipeCrawl { } public static class Starting extends ZRecipeCrawl { } - public static class Digest extends ZRecipeCrawl { - - private final Multimap digestion; - private final Multimap backwardsDigestion; - - public Digest(Multimap digestion, Multimap backwardsDigestion) { - this.digestion = digestion; - this.backwardsDigestion = backwardsDigestion; - } - - public boolean has(Item item, boolean backwards) { - return (backwards ? backwardsDigestion : digestion).containsKey(item); - } - - public Collection get(Item item, boolean backwards) { - return (backwards ? backwardsDigestion : digestion).get(item); - } - - } - public static abstract class Visit> extends ZRecipeCrawl { public final T recipe; @@ -98,4 +88,71 @@ public Misc(Recipe recipe, RegistryAccess access) { } } + + /** + * Fired after all recipes have been digested + */ + public static class Digest extends ZRecipeCrawl { + + private final Multimap digestion; + private final Multimap backwardsDigestion; + + public Digest(Multimap digestion, Multimap backwardsDigestion) { + this.digestion = digestion; + this.backwardsDigestion = backwardsDigestion; + } + + public boolean has(Item item, boolean backwards) { + return (backwards ? backwardsDigestion : digestion).containsKey(item); + } + + public Collection get(Item item, boolean backwards) { + return (backwards ? backwardsDigestion : digestion).get(item); + } + + /* + * Derivation list -> items to add and then derive (raw materials) + * Whitelist -> items to add and not derive from + * Blacklist -> items to ignore + */ + + public void recursivelyFindCraftedItemsFromStrings(@Nullable Collection derivationList, @Nullable Collection whitelist, @Nullable Collection blacklist, Consumer callback) { + List parsedDerivationList = derivationList == null ? null : RegistryUtil.massRegistryGet(derivationList, BuiltInRegistries.ITEM); + List parsedWhitelist = whitelist == null ? null : RegistryUtil.massRegistryGet(whitelist, BuiltInRegistries.ITEM); + List parsedBlacklist = blacklist == null ? null : RegistryUtil.massRegistryGet(blacklist, BuiltInRegistries.ITEM); + + recursivelyFindCraftedItems(parsedDerivationList, parsedWhitelist, parsedBlacklist, callback); + } + + public void recursivelyFindCraftedItems(@Nullable Collection derivationList, @Nullable Collection whitelist, @Nullable Collection blacklist, Consumer callback) { + Collection trueDerivationList = derivationList == null ? Lists.newArrayList() : derivationList; + Collection trueWhitelist = whitelist == null ? Lists.newArrayList() : whitelist; + Collection trueBlacklist = blacklist == null ? Lists.newArrayList() : blacklist; + + Streams.concat(trueDerivationList.stream(), trueWhitelist.stream()).forEach(callback); + + Set scanned = Sets.newHashSet(trueDerivationList); + List toScan = Lists.newArrayList(trueDerivationList); + + while(!toScan.isEmpty()) { + Item scan = toScan.remove(0); + + if(digestion.containsKey(scan)) { + for(ItemStack digestedStack : digestion.get(scan)) { + Item candidate = digestedStack.getItem(); + + if(!scanned.contains(candidate)) { + scanned.add(candidate); + toScan.add(candidate); + + if(!trueBlacklist.contains(candidate)) + callback.accept(candidate); + } + } + } + } + } + + } + } diff --git a/src/main/java/org/violetmoon/zeta/util/ItemNBTHelper.java b/src/main/java/org/violetmoon/zeta/util/ItemNBTHelper.java index 45ce714..e62bc14 100644 --- a/src/main/java/org/violetmoon/zeta/util/ItemNBTHelper.java +++ b/src/main/java/org/violetmoon/zeta/util/ItemNBTHelper.java @@ -14,9 +14,11 @@ import net.minecraft.nbt.ListTag; import net.minecraft.world.item.ItemStack; +// TBH this entire class could be Deprecated and removed public final class ItemNBTHelper { /** Checks if an ItemStack has a Tag Compound **/ + @Deprecated(forRemoval = true) // Just use stack.hasTag() public static boolean detectNBT(ItemStack stack) { return stack.hasTag(); } @@ -24,119 +26,122 @@ public static boolean detectNBT(ItemStack stack) { /** Tries to initialize an NBT Tag Compound in an ItemStack, * this will not do anything if the stack already has a tag * compound **/ + @Deprecated(forRemoval = true) // Just use stack.getOrCreateTag() public static void initNBT(ItemStack stack) { - if(!detectNBT(stack)) - injectNBT(stack, new CompoundTag()); + stack.getOrCreateTag(); } /** Injects an NBT Tag Compound to an ItemStack, no checks * are made previously **/ + @Deprecated(forRemoval = true) // Just use stack.setTag(nbt) public static void injectNBT(ItemStack stack, CompoundTag nbt) { stack.setTag(nbt); } /** Gets the CompoundNBT in an ItemStack. Tries to init it * previously in case there isn't one present **/ + @Deprecated(forRemoval = true) // Just use stack.getOrCreateTag() public static CompoundTag getNBT(ItemStack stack) { - initNBT(stack); - return stack.getTag(); + return stack.getOrCreateTag(); } // SETTERS /////////////////////////////////////////////////////////////////// + // All these force create a tag if it doesn't exist + public static void setBoolean(ItemStack stack, String tag, boolean b) { - getNBT(stack).putBoolean(tag, b); + stack.getOrCreateTag().putBoolean(tag, b); } public static void setByte(ItemStack stack, String tag, byte b) { - getNBT(stack).putByte(tag, b); + stack.getOrCreateTag().putByte(tag, b); } public static void setShort(ItemStack stack, String tag, short s) { - getNBT(stack).putShort(tag, s); + stack.getOrCreateTag().putShort(tag, s); } public static void setInt(ItemStack stack, String tag, int i) { - getNBT(stack).putInt(tag, i); + stack.getOrCreateTag().putInt(tag, i); } public static void setLong(ItemStack stack, String tag, long l) { - getNBT(stack).putLong(tag, l); + stack.getOrCreateTag().putLong(tag, l); } public static void setFloat(ItemStack stack, String tag, float f) { - getNBT(stack).putFloat(tag, f); + stack.getOrCreateTag().putFloat(tag, f); } public static void setDouble(ItemStack stack, String tag, double d) { - getNBT(stack).putDouble(tag, d); + stack.getOrCreateTag().putDouble(tag, d); } public static void setCompound(ItemStack stack, String tag, CompoundTag cmp) { if(!tag.equalsIgnoreCase("ench")) // not override the enchantments - getNBT(stack).put(tag, cmp); + stack.getOrCreateTag().put(tag, cmp); } public static void setString(ItemStack stack, String tag, String s) { - getNBT(stack).putString(tag, s); + stack.getOrCreateTag().putString(tag, s); } public static void setList(ItemStack stack, String tag, ListTag list) { - getNBT(stack).put(tag, list); + stack.getOrCreateTag().put(tag, list); } // GETTERS /////////////////////////////////////////////////////////////////// public static boolean verifyExistence(ItemStack stack, String tag) { - return !stack.isEmpty() && detectNBT(stack) && getNBT(stack).contains(tag); + return !stack.isEmpty() && stack.hasTag() && stack.getOrCreateTag().contains(tag); } - @Deprecated + @Deprecated(forRemoval = true) public static boolean verifyExistance(ItemStack stack, String tag) { return verifyExistence(stack, tag); } public static boolean getBoolean(ItemStack stack, String tag, boolean defaultExpected) { - return verifyExistence(stack, tag) ? getNBT(stack).getBoolean(tag) : defaultExpected; + return verifyExistence(stack, tag) ? stack.getOrCreateTag().getBoolean(tag) : defaultExpected; } public static byte getByte(ItemStack stack, String tag, byte defaultExpected) { - return verifyExistence(stack, tag) ? getNBT(stack).getByte(tag) : defaultExpected; + return verifyExistence(stack, tag) ? stack.getOrCreateTag().getByte(tag) : defaultExpected; } public static short getShort(ItemStack stack, String tag, short defaultExpected) { - return verifyExistence(stack, tag) ? getNBT(stack).getShort(tag) : defaultExpected; + return verifyExistence(stack, tag) ? stack.getOrCreateTag().getShort(tag) : defaultExpected; } public static int getInt(ItemStack stack, String tag, int defaultExpected) { - return verifyExistence(stack, tag) ? getNBT(stack).getInt(tag) : defaultExpected; + return verifyExistence(stack, tag) ? stack.getOrCreateTag().getInt(tag) : defaultExpected; } public static long getLong(ItemStack stack, String tag, long defaultExpected) { - return verifyExistence(stack, tag) ? getNBT(stack).getLong(tag) : defaultExpected; + return verifyExistence(stack, tag) ? stack.getOrCreateTag().getLong(tag) : defaultExpected; } public static float getFloat(ItemStack stack, String tag, float defaultExpected) { - return verifyExistence(stack, tag) ? getNBT(stack).getFloat(tag) : defaultExpected; + return verifyExistence(stack, tag) ? stack.getOrCreateTag().getFloat(tag) : defaultExpected; } public static double getDouble(ItemStack stack, String tag, double defaultExpected) { - return verifyExistence(stack, tag) ? getNBT(stack).getDouble(tag) : defaultExpected; + return verifyExistence(stack, tag) ? stack.getOrCreateTag().getDouble(tag) : defaultExpected; } /** If nullifyOnFail is true it'll return null if it doesn't find any * compounds, otherwise it'll return a new one. **/ public static CompoundTag getCompound(ItemStack stack, String tag, boolean nullifyOnFail) { - return verifyExistence(stack, tag) ? getNBT(stack).getCompound(tag) : nullifyOnFail ? null : new CompoundTag(); + return verifyExistence(stack, tag) ? stack.getOrCreateTag().getCompound(tag) : nullifyOnFail ? null : new CompoundTag(); } public static String getString(ItemStack stack, String tag, String defaultExpected) { - return verifyExistence(stack, tag) ? getNBT(stack).getString(tag) : defaultExpected; + return verifyExistence(stack, tag) ? stack.getOrCreateTag().getString(tag) : defaultExpected; } public static ListTag getList(ItemStack stack, String tag, int objtype, boolean nullifyOnFail) { - return verifyExistence(stack, tag) ? getNBT(stack).getList(tag, objtype) : nullifyOnFail ? null : new ListTag(); + return verifyExistence(stack, tag) ? stack.getOrCreateTag().getList(tag, objtype) : nullifyOnFail ? null : new ListTag(); } } diff --git a/src/main/java/org/violetmoon/zeta/util/RegistryUtil.java b/src/main/java/org/violetmoon/zeta/util/RegistryUtil.java index 9482c5b..4b7c379 100644 --- a/src/main/java/org/violetmoon/zeta/util/RegistryUtil.java +++ b/src/main/java/org/violetmoon/zeta/util/RegistryUtil.java @@ -1,15 +1,6 @@ package org.violetmoon.zeta.util; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.function.Function; - -import org.jetbrains.annotations.Nullable; -import org.violetmoon.zeta.Zeta; -import org.violetmoon.zeta.block.IZetaBlock; - +import com.google.common.collect.ImmutableList; import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; @@ -17,47 +8,68 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.level.block.Block; +import org.jetbrains.annotations.Nullable; +import org.violetmoon.zeta.Zeta; +import org.violetmoon.zeta.block.IZetaBlock; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; public class RegistryUtil { - - public static List massRegistryGet(Collection coll, Registry reg) { - return coll.stream().map(ResourceLocation::new).map(reg::get).filter(Objects::nonNull).toList(); - } - - public static List getTagValues(RegistryAccess access, TagKey tag) { - return access.registryOrThrow(tag.registry()) - .getTag(tag) - .map(holderset -> holderset.stream().map(Holder::value).toList()) //tag exists, grab all items from it - .orElseGet(Collections::emptyList); //tag doesn't exist - } - - //TODO: Can be made more 'static' when there's a nicer way to get a block's ID, instead of having to consult a particular Zeta - // (this is one reason i want to write the fancier block registry system - quat) - // This is just Duct taped as fuck to get quark-specific stuff out of IQuarkBlock so i can make it IZetaBlock - - protected final Zeta z; - - public RegistryUtil(Zeta z) { - this.z = z; - } - - public @Nullable String inheritQuark(IZetaBlock parent, String format) { - return inherit(parent.getBlock(), format); - } - - public @Nullable String inherit(Block parent, String format) { - ResourceLocation parentName = z.registry.getRegistryName(parent, BuiltInRegistries.BLOCK); - if(parentName == null) - return null; - else - return String.format(String.format("%s:%s", z.modid, format), parentName.getPath()); - } - - public @Nullable String inherit(Block parent, Function fun) { - ResourceLocation parentName = z.registry.getRegistryName(parent, BuiltInRegistries.BLOCK); - if(parentName == null) - return null; - else - return String.format(String.format("%s:%s", z.modid, fun.apply(parentName.getPath()))); - } + + /** + * Gets a list of objects from a collection of strings. These can be either IDS or Tags (prefixed by '#'). + * For tags to work tho you HAVE to call this AFTER the tags are loaded. + */ + public static List massRegistryGet(Collection coll, Registry reg) { + ImmutableList.Builder builder = new ImmutableList.Builder<>(); + for (String s : coll) { + if (s.startsWith("#")) { + TagKey tag = TagKey.create(reg.key(), new ResourceLocation(s.substring(1))); + reg.getTagOrEmpty(tag).forEach(tHolder -> builder.add(tHolder.value())); + } else { + reg.getOptional(new ResourceLocation(s)).ifPresent(builder::add); + } + } + return builder.build(); + } + + public static List getTagValues(RegistryAccess access, TagKey tag) { + return access.registryOrThrow(tag.registry()) + .getTag(tag) + .map(holderset -> holderset.stream().map(Holder::value).toList()) //tag exists, grab all items from it + .orElseGet(Collections::emptyList); //tag doesn't exist + } + + //TODO: Can be made more 'static' when there's a nicer way to get a block's ID, instead of having to consult a particular Zeta + // (this is one reason i want to write the fancier block registry system - quat) + // This is just Duct taped as fuck to get quark-specific stuff out of IQuarkBlock so i can make it IZetaBlock + + protected final Zeta z; + + public RegistryUtil(Zeta z) { + this.z = z; + } + + public @Nullable String inheritQuark(IZetaBlock parent, String format) { + return inherit(parent.getBlock(), format); + } + + public @Nullable String inherit(Block parent, String format) { + ResourceLocation parentName = z.registry.getRegistryName(parent, BuiltInRegistries.BLOCK); + if (parentName == null) + return null; + else + return String.format(String.format("%s:%s", z.modid, format), parentName.getPath()); + } + + public @Nullable String inherit(Block parent, Function fun) { + ResourceLocation parentName = z.registry.getRegistryName(parent, BuiltInRegistries.BLOCK); + if (parentName == null) + return null; + else + return String.format(String.format("%s:%s", z.modid, fun.apply(parentName.getPath()))); + } } diff --git a/src/main/java/org/violetmoon/zeta/util/handler/RecipeCrawlHandler.java b/src/main/java/org/violetmoon/zeta/util/handler/RecipeCrawlHandler.java index e52b305..ff0784e 100644 --- a/src/main/java/org/violetmoon/zeta/util/handler/RecipeCrawlHandler.java +++ b/src/main/java/org/violetmoon/zeta/util/handler/RecipeCrawlHandler.java @@ -3,9 +3,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Set; import java.util.function.Consumer; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import org.violetmoon.zeta.Zeta; import org.violetmoon.zeta.event.bus.IZetaPlayEvent; @@ -15,18 +15,13 @@ import org.violetmoon.zeta.event.load.ZTagsUpdated; import org.violetmoon.zeta.event.play.ZRecipeCrawl; import org.violetmoon.zeta.event.play.ZServerTick; -import org.violetmoon.zeta.util.RegistryUtil; import org.violetmoon.zeta.util.zetalist.ZetaList; import com.google.common.collect.HashMultimap; -import com.google.common.collect.Lists; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; -import com.google.common.collect.Streams; import net.minecraft.core.NonNullList; import net.minecraft.core.RegistryAccess; -import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.SimplePreparableReloadListener; import net.minecraft.util.profiling.ProfilerFiller; @@ -40,11 +35,13 @@ import net.minecraft.world.item.crafting.ShapedRecipe; import net.minecraft.world.item.crafting.ShapelessRecipe; +@ApiStatus.Internal public class RecipeCrawlHandler { - private static final List> recipesToLazyDigest = new ArrayList<>(); - private static final Multimap recipeDigestion = HashMultimap.create(); - private static final Multimap backwardsDigestion = HashMultimap.create(); + // this just includes vanilla recipe types. Custom recipes could have some conversion scheme that we can't predict + private static final List> vanillaRecipesToLazyDigest = new ArrayList<>(); + private static final Multimap vanillaRecipeDigestion = HashMultimap.create(); + private static final Multimap backwardsVanillaDigestion = HashMultimap.create(); private static final Object mutex = new Object(); private static boolean needsCrawl = false; @@ -75,45 +72,50 @@ private static void clear() { mayCrawl = false; fire(new ZRecipeCrawl.Reset()); } - + private static void fire(IZetaPlayEvent event) { ZetaList.INSTANCE.fireEvent(event); } - @SuppressWarnings("ConstantValue") // some nullchecks on stuff that is ostensibly non-null, but you never know with mods + @SuppressWarnings("ConstantValue") + // some nullchecks on stuff that is ostensibly non-null, but you never know with mods private static void load(RecipeManager manager, RegistryAccess access) { - if(!manager.getRecipes().isEmpty()) { + if (!manager.getRecipes().isEmpty()) { fire(new ZRecipeCrawl.Starting()); - recipesToLazyDigest.clear(); - recipeDigestion.clear(); - backwardsDigestion.clear(); + vanillaRecipesToLazyDigest.clear(); + vanillaRecipeDigestion.clear(); + backwardsVanillaDigestion.clear(); - for(Recipe recipe : manager.getRecipes()) { + for (Recipe recipe : manager.getRecipes()) { try { - if(recipe == null) + if (recipe == null) throw new IllegalStateException("Recipe is null"); - if(recipe.getIngredients() == null) + if (recipe.getIngredients() == null) throw new IllegalStateException("Recipe ingredients are null"); - if(recipe.getResultItem(access) == null) + if (recipe.getResultItem(access) == null) throw new IllegalStateException("Recipe getResultItem is null"); ZRecipeCrawl.Visit event; - if(recipe instanceof ShapedRecipe sr) + if (recipe instanceof ShapedRecipe sr) event = new ZRecipeCrawl.Visit.Shaped(sr, access); - else if(recipe instanceof ShapelessRecipe sr) + else if (recipe instanceof ShapelessRecipe sr) event = new ZRecipeCrawl.Visit.Shapeless(sr, access); - else if(recipe instanceof CustomRecipe cr) + else if (recipe instanceof CustomRecipe cr) event = new ZRecipeCrawl.Visit.Custom(cr, access); - else if(recipe instanceof AbstractCookingRecipe acr) + else if (recipe instanceof AbstractCookingRecipe acr) event = new ZRecipeCrawl.Visit.Cooking(acr, access); else event = new ZRecipeCrawl.Visit.Misc(recipe, access); - recipesToLazyDigest.add(recipe); + //misc recipes could have custom logic that we cant make many assumptions on. For example FD cutting board recipes are lossy. + //for instance a hanging sign can be cut into a plank. A hanging sign is magnetic but this does not mean planks are + if(!(event instanceof ZRecipeCrawl.Visit.Misc)) { + vanillaRecipesToLazyDigest.add(recipe); + } fire(event); } catch (Exception e) { - if(recipe == null) + if (recipe == null) Zeta.GLOBAL_LOG.error("Encountered null recipe in RecipeManager.getRecipes. This is not good"); else Zeta.GLOBAL_LOG.error("Failed to scan recipe " + recipe.getId() + ". This should be reported to " + recipe.getId().getNamespace() + "!", e); @@ -125,80 +127,49 @@ else if(recipe instanceof AbstractCookingRecipe acr) @PlayEvent public static void onTick(ZServerTick.Start tick) { synchronized (mutex) { - if(mayCrawl && needsCrawl) { + if (mayCrawl && needsCrawl) { RecipeManager manager = tick.getServer().getRecipeManager(); RegistryAccess access = tick.getServer().registryAccess(); load(manager, access); needsCrawl = false; } - if(!recipesToLazyDigest.isEmpty()) { - recipeDigestion.clear(); - backwardsDigestion.clear(); + if (!vanillaRecipesToLazyDigest.isEmpty()) { + vanillaRecipeDigestion.clear(); + backwardsVanillaDigestion.clear(); - for(Recipe recipe : recipesToLazyDigest) + for (Recipe recipe : vanillaRecipesToLazyDigest) digest(recipe, tick.getServer().registryAccess()); - recipesToLazyDigest.clear(); - fire(new ZRecipeCrawl.Digest(recipeDigestion, backwardsDigestion)); + vanillaRecipesToLazyDigest.clear(); + fire(new ZRecipeCrawl.Digest(vanillaRecipeDigestion, backwardsVanillaDigestion)); } } } private static void digest(Recipe recipe, RegistryAccess access) { + // we only digest vanilla recipe types. Custom recipes could have some conversion scheme that we can't predict ItemStack out = recipe.getResultItem(access); Item outItem = out.getItem(); NonNullList ingredients = recipe.getIngredients(); - for(Ingredient ingredient : ingredients) { - for(ItemStack inStack : ingredient.getItems()) { - recipeDigestion.put(inStack.getItem(), out); - backwardsDigestion.put(outItem, inStack); + for (Ingredient ingredient : ingredients) { + for (ItemStack inStack : ingredient.getItems()) { + //don't include catalyst items. This includes partial ones like buckets and such + if (inStack.getCraftingRemainingItem().isEmpty()) { + vanillaRecipeDigestion.put(inStack.getItem(), out); + backwardsVanillaDigestion.put(outItem, inStack); + } } } } - /* - * Derivation list -> items to add and then derive (raw materials) - * Whitelist -> items to add and not derive from - * Blacklist -> items to ignore - */ - - public static void recursivelyFindCraftedItemsFromStrings(@Nullable Collection derivationList, @Nullable Collection whitelist, @Nullable Collection blacklist, Consumer callback) { - List parsedDerivationList = derivationList == null ? null : RegistryUtil.massRegistryGet(derivationList, BuiltInRegistries.ITEM); - List parsedWhitelist = whitelist == null ? null : RegistryUtil.massRegistryGet(whitelist, BuiltInRegistries.ITEM); - List parsedBlacklist = blacklist == null ? null : RegistryUtil.massRegistryGet(blacklist, BuiltInRegistries.ITEM); - - recursivelyFindCraftedItems(parsedDerivationList, parsedWhitelist, parsedBlacklist, callback); + //delete this if you see it. Just here so this update doesnt crash with an old quark version + @Deprecated(forRemoval = true) + public void recursivelyFindCraftedItemsFromStrings(@Nullable Collection derivationList, @Nullable Collection whitelist, @Nullable Collection blacklist, Consumer callback) { } - public static void recursivelyFindCraftedItems(@Nullable Collection derivationList, @Nullable Collection whitelist, @Nullable Collection blacklist, Consumer callback) { - Collection trueDerivationList = derivationList == null ? Lists.newArrayList() : derivationList; - Collection trueWhitelist = whitelist == null ? Lists.newArrayList() : whitelist; - Collection trueBlacklist = blacklist == null ? Lists.newArrayList() : blacklist; - - Streams.concat(trueDerivationList.stream(), trueWhitelist.stream()).forEach(callback); - - Set scanned = Sets.newHashSet(trueDerivationList); - List toScan = Lists.newArrayList(trueDerivationList); - - while(!toScan.isEmpty()) { - Item scan = toScan.remove(0); - - if(recipeDigestion.containsKey(scan)) { - for(ItemStack digestedStack : recipeDigestion.get(scan)) { - Item candidate = digestedStack.getItem(); - - if(!scanned.contains(candidate)) { - scanned.add(candidate); - toScan.add(candidate); - - if(!trueBlacklist.contains(candidate)) - callback.accept(candidate); - } - } - } - } + @Deprecated(forRemoval = true) + public void recursivelyFindCraftedItems(@Nullable Collection derivationList, @Nullable Collection whitelist, @Nullable Collection blacklist, Consumer callback) { } - } diff --git a/src/main/java/org/violetmoon/zetaimplforge/event/load/Test.java b/src/main/java/org/violetmoon/zetaimplforge/event/load/Test.java new file mode 100644 index 0000000..13e9efa --- /dev/null +++ b/src/main/java/org/violetmoon/zetaimplforge/event/load/Test.java @@ -0,0 +1,42 @@ +package org.violetmoon.zetaimplforge.event.load; + +import net.minecraftforge.event.AddReloadListenerEvent; +import net.minecraftforge.eventbus.EventBus; +import net.minecraftforge.eventbus.api.Event; +import org.jetbrains.annotations.NotNull; +import org.violetmoon.zeta.event.bus.IZetaLoadEvent; +import org.violetmoon.zeta.event.bus.ZetaEventBus; + +import java.util.Map; +import java.util.function.Consumer; +import java.util.function.Function; + +// This made sense when i wrote it. Now i have no clue +// Please somebody finish this +public class Test { + + private static final Map, Function> FORGE_TO_ZETA = Map.of( + ForgeZAddReloadListener.class, (Function) ForgeZAddReloadListener::new + ); + + public static Consumer remap(Consumer zetaEventConsumer, Class cl) { + Function forgeToZeta = (Function) FORGE_TO_ZETA.get(cl); + return getEventConsumer(zetaEventConsumer, forgeToZeta); + } + + @NotNull + private static Consumer getEventConsumer(Consumer zetaEventConsumer, Function forgeToZeta) { + return event -> zetaEventConsumer.accept(forgeToZeta.apply(event)); + } + + + public static class ExampleZetaBus{ + private EventBus forgeBus; + + public void addListener(Consumer zetaEventConsumer, Class cl){ + forgeBus.addListener(remap(zetaEventConsumer, cl)); + } + + } + +}