From 37938021dccbe9e72aefd07e224088871f399e17 Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Fri, 12 Jul 2024 12:47:14 +0300 Subject: [PATCH] Updated neo, fixed few bugs with latest neo version --- gradle.properties | 8 ++-- .../mods/kubejs/block/SeedItemBuilder.java | 3 +- .../mods/kubejs/holder/KubeJSHolderSets.java | 32 +++++++++++++++- .../kubejs/holder/NamespaceHolderSet.java | 8 +++- .../mods/kubejs/holder/RegExHolderSet.java | 9 ++++- .../integration/jei/KubeJSJEIPlugin.java | 18 +++++++++ .../item/creativetab/CreativeTabCallback.java | 2 +- .../creativetab/CreativeTabCallbackForge.java | 38 ++++++------------- .../creativetab/CreativeTabKubeEvent.java | 4 +- .../resources/META-INF/neoforge.mods.toml | 2 +- 10 files changed, 83 insertions(+), 41 deletions(-) diff --git a/gradle.properties b/gradle.properties index 403b70a24..3895582dc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,11 +13,11 @@ modrinth_id=umyGl7zF minecraft_version=1.21 mod_version=2100.7.0 -neoforge_version=21.0.61-beta -parchment_version=2024.06.23 +neoforge_version=21.0.86-beta +parchment_version=2024.07.07 rhino_version=2100.2.5-build.41 -architectury_version=13.0.3 +architectury_version=13.0.4 rei_version=16.0.729 -jei_version=19.1.1.19 +jei_version=19.5.0.31 emi_version=1.1.10+1.21 \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/block/SeedItemBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/SeedItemBuilder.java index 5cd999f24..b2d000012 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/SeedItemBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/SeedItemBuilder.java @@ -9,6 +9,7 @@ import net.minecraft.world.entity.npc.Villager; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelReader; import net.neoforged.neoforge.common.SpecialPlantable; import org.jetbrains.annotations.Nullable; @@ -25,7 +26,7 @@ public boolean canPlacePlantAtPosition(ItemStack stack, LevelReader level, Block } @Override - public void spawnPlantAtPosition(ItemStack stack, LevelReader level, BlockPos pos, @Nullable Direction direction) { + public void spawnPlantAtPosition(ItemStack stack, LevelAccessor level, BlockPos pos, @Nullable Direction direction) { } @Override diff --git a/src/main/java/dev/latvian/mods/kubejs/holder/KubeJSHolderSets.java b/src/main/java/dev/latvian/mods/kubejs/holder/KubeJSHolderSets.java index 1942edf08..9e243825a 100644 --- a/src/main/java/dev/latvian/mods/kubejs/holder/KubeJSHolderSets.java +++ b/src/main/java/dev/latvian/mods/kubejs/holder/KubeJSHolderSets.java @@ -1,14 +1,42 @@ package dev.latvian.mods.kubejs.holder; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import dev.latvian.mods.kubejs.KubeJS; import net.minecraft.core.Holder; +import net.minecraft.core.Registry; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.resources.ResourceKey; import net.neoforged.neoforge.registries.DeferredRegister; import net.neoforged.neoforge.registries.NeoForgeRegistries; import net.neoforged.neoforge.registries.holdersets.HolderSetType; +import net.neoforged.neoforge.registries.holdersets.ICustomHolderSet; public interface KubeJSHolderSets { DeferredRegister REGISTRY = DeferredRegister.create(NeoForgeRegistries.Keys.HOLDER_SET_TYPES, KubeJS.MOD_ID); - Holder REGEX = REGISTRY.register("regex", () -> RegExHolderSet::codec); - Holder NAMESPACE = REGISTRY.register("namespace", () -> NamespaceHolderSet::codec); + Holder REGEX = REGISTRY.register("regex", () -> new HolderSetType() { + @Override + public MapCodec> makeCodec(ResourceKey> registryKey, Codec> holderCodec, boolean forceList) { + return RegExHolderSet.codec(registryKey); + } + + @Override + public StreamCodec> makeStreamCodec(ResourceKey> registryKey) { + return RegExHolderSet.streamCodec(registryKey); + } + }); + + Holder NAMESPACE = REGISTRY.register("namespace", () -> new HolderSetType() { + @Override + public MapCodec> makeCodec(ResourceKey> registryKey, Codec> holderCodec, boolean forceList) { + return NamespaceHolderSet.codec(registryKey); + } + + @Override + public StreamCodec> makeStreamCodec(ResourceKey> registryKey) { + return NamespaceHolderSet.streamCodec(registryKey); + } + }); } diff --git a/src/main/java/dev/latvian/mods/kubejs/holder/NamespaceHolderSet.java b/src/main/java/dev/latvian/mods/kubejs/holder/NamespaceHolderSet.java index f5b6e49eb..9ebbabe6b 100644 --- a/src/main/java/dev/latvian/mods/kubejs/holder/NamespaceHolderSet.java +++ b/src/main/java/dev/latvian/mods/kubejs/holder/NamespaceHolderSet.java @@ -8,6 +8,8 @@ import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderSet; import net.minecraft.core.Registry; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceKey; import net.minecraft.tags.TagKey; @@ -20,13 +22,17 @@ import java.util.Set; public class NamespaceHolderSet extends HolderSet.ListBacked implements ICustomHolderSet { - public static MapCodec> codec(ResourceKey> registryKey, Codec> holderCodec, boolean forceList) { + public static MapCodec> codec(ResourceKey> registryKey) { return RecordCodecBuilder.mapCodec(instance -> instance.group( RegistryOps.retrieveRegistryLookup(registryKey).forGetter(s -> s.registryLookup), Codec.STRING.fieldOf("namespace").forGetter(s -> s.namespace) ).apply(instance, NamespaceHolderSet::new)); } + public static StreamCodec> streamCodec(ResourceKey> registryKey) { + return null; + } + public final HolderLookup.RegistryLookup registryLookup; public final String namespace; diff --git a/src/main/java/dev/latvian/mods/kubejs/holder/RegExHolderSet.java b/src/main/java/dev/latvian/mods/kubejs/holder/RegExHolderSet.java index aeccf398a..e297621bf 100644 --- a/src/main/java/dev/latvian/mods/kubejs/holder/RegExHolderSet.java +++ b/src/main/java/dev/latvian/mods/kubejs/holder/RegExHolderSet.java @@ -1,7 +1,6 @@ package dev.latvian.mods.kubejs.holder; import com.mojang.datafixers.util.Either; -import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import dev.latvian.mods.kubejs.util.RegExpKJS; @@ -9,6 +8,8 @@ import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderSet; import net.minecraft.core.Registry; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceKey; import net.minecraft.tags.TagKey; @@ -22,13 +23,17 @@ import java.util.regex.Pattern; public class RegExHolderSet extends HolderSet.ListBacked implements ICustomHolderSet { - public static MapCodec> codec(ResourceKey> registryKey, Codec> holderCodec, boolean forceList) { + public static MapCodec> codec(ResourceKey> registryKey) { return RecordCodecBuilder.mapCodec(instance -> instance.group( RegistryOps.retrieveRegistryLookup(registryKey).forGetter(s -> s.registryLookup), RegExpKJS.CODEC.fieldOf("pattern").forGetter(s -> s.pattern) ).apply(instance, RegExHolderSet::new)); } + public static StreamCodec> streamCodec(ResourceKey> registryKey) { + return null; + } + public final HolderLookup.RegistryLookup registryLookup; public final Pattern pattern; diff --git a/src/main/java/dev/latvian/mods/kubejs/integration/jei/KubeJSJEIPlugin.java b/src/main/java/dev/latvian/mods/kubejs/integration/jei/KubeJSJEIPlugin.java index 41835d4c2..6b43a0875 100644 --- a/src/main/java/dev/latvian/mods/kubejs/integration/jei/KubeJSJEIPlugin.java +++ b/src/main/java/dev/latvian/mods/kubejs/integration/jei/KubeJSJEIPlugin.java @@ -20,6 +20,7 @@ import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.material.Fluid; import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.ModList; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.common.crafting.CompoundIngredient; import net.neoforged.neoforge.fluids.FluidStack; @@ -35,6 +36,7 @@ @JeiPlugin public class KubeJSJEIPlugin implements IModPlugin { public static final ResourceLocation ID = KubeJS.id("jei"); + public static final boolean DISABLED = ModList.get().isLoaded("emi"); private RecipeViewerData remote = null; public KubeJSJEIPlugin() { @@ -53,6 +55,10 @@ public void loadRemote(RemoteRecipeViewerDataUpdatedEvent event) { @Override public void onRuntimeAvailable(IJeiRuntime runtime) { + if (DISABLED) { + return; + } + var recipeManager = runtime.getRecipeManager(); var ingredientManager = runtime.getIngredientManager(); @@ -157,6 +163,10 @@ public void onRuntimeAvailable(IJeiRuntime runtime) { @Override public void registerRecipes(IRecipeRegistration registration) { + if (DISABLED) { + return; + } + for (var type : RecipeViewerEntryType.ALL_TYPES.get()) { var ingredientType = JEIIntegration.typeOf(type); @@ -198,6 +208,10 @@ public void registerRecipes(IRecipeRegistration registration) { @Override public void registerItemSubtypes(ISubtypeRegistration registration) { + if (DISABLED) { + return; + } + if (RecipeViewerEvents.REGISTER_SUBTYPES.hasListeners(RecipeViewerEntryType.ITEM)) { RecipeViewerEvents.REGISTER_SUBTYPES.post(ScriptType.CLIENT, RecipeViewerEntryType.ITEM, new JEIRegisterSubtypesKubeEvent(RecipeViewerEntryType.ITEM, VanillaTypes.ITEM_STACK, registration)); } @@ -215,6 +229,10 @@ public void registerItemSubtypes(ISubtypeRegistration registration) { @Override public void registerFluidSubtypes(ISubtypeRegistration registration, IPlatformFluidHelper platformFluidHelper) { + if (DISABLED) { + return; + } + if (RecipeViewerEvents.REGISTER_SUBTYPES.hasListeners(RecipeViewerEntryType.FLUID)) { RecipeViewerEvents.REGISTER_SUBTYPES.post(ScriptType.CLIENT, RecipeViewerEntryType.FLUID, new JEIRegisterSubtypesKubeEvent(RecipeViewerEntryType.FLUID, NeoForgeTypes.FLUID_STACK, registration)); } diff --git a/src/main/java/dev/latvian/mods/kubejs/item/creativetab/CreativeTabCallback.java b/src/main/java/dev/latvian/mods/kubejs/item/creativetab/CreativeTabCallback.java index ef308d35b..702e0d4f3 100644 --- a/src/main/java/dev/latvian/mods/kubejs/item/creativetab/CreativeTabCallback.java +++ b/src/main/java/dev/latvian/mods/kubejs/item/creativetab/CreativeTabCallback.java @@ -9,5 +9,5 @@ public interface CreativeTabCallback { void addBefore(ItemStack order, ItemStack[] items, CreativeModeTab.TabVisibility visibility); - void remove(ItemPredicate filter, boolean removeDisplay, boolean removeSearch); + void remove(ItemPredicate filter, boolean removeParent, boolean removeSearch); } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/item/creativetab/CreativeTabCallbackForge.java b/src/main/java/dev/latvian/mods/kubejs/item/creativetab/CreativeTabCallbackForge.java index aff4f0a00..169a4c61d 100644 --- a/src/main/java/dev/latvian/mods/kubejs/item/creativetab/CreativeTabCallbackForge.java +++ b/src/main/java/dev/latvian/mods/kubejs/item/creativetab/CreativeTabCallbackForge.java @@ -5,9 +5,7 @@ import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.Map; +import java.util.List; public record CreativeTabCallbackForge(BuildCreativeModeTabContentsEvent event) implements CreativeTabCallback { @Override @@ -25,34 +23,20 @@ public void addBefore(ItemStack order, ItemStack[] items, CreativeModeTab.TabVis } @Override - public void remove(ItemPredicate filter, boolean removeDisplay, boolean removeSearch) { - var entries = new ArrayList>(); - - for (var entry : event.getEntries()) { - if (filter.test(entry.getKey())) { - var visibility = entry.getValue(); - - if (removeDisplay && removeSearch) { - visibility = null; - } - - if (removeDisplay && visibility == CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS) { - visibility = CreativeModeTab.TabVisibility.SEARCH_TAB_ONLY; + public void remove(ItemPredicate filter, boolean removeParent, boolean removeSearch) { + if (removeParent) { + for (var is : List.copyOf(event.getParentEntries())) { + if (filter.test(is)) { + event.remove(is, CreativeModeTab.TabVisibility.PARENT_TAB_ONLY); } - - if (removeSearch && visibility == CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS) { - visibility = CreativeModeTab.TabVisibility.PARENT_TAB_ONLY; - } - - entries.add(new AbstractMap.SimpleEntry<>(entry.getKey(), visibility)); } } - for (var entry : entries) { - if (entry.getValue() == null) { - event.getEntries().remove(entry.getKey()); - } else { - event.getEntries().put(entry.getKey(), entry.getValue()); + if (removeSearch) { + for (var is : List.copyOf(event.getSearchEntries())) { + if (filter.test(is)) { + event.remove(is, CreativeModeTab.TabVisibility.SEARCH_TAB_ONLY); + } } } } diff --git a/src/main/java/dev/latvian/mods/kubejs/item/creativetab/CreativeTabKubeEvent.java b/src/main/java/dev/latvian/mods/kubejs/item/creativetab/CreativeTabKubeEvent.java index e6503d1b7..8629cc5fb 100644 --- a/src/main/java/dev/latvian/mods/kubejs/item/creativetab/CreativeTabKubeEvent.java +++ b/src/main/java/dev/latvian/mods/kubejs/item/creativetab/CreativeTabKubeEvent.java @@ -50,11 +50,11 @@ public void addBefore(ItemStack order, ItemStack[] items) { callback.addBefore(order, items, CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS); } - public void removeDisplay(ItemPredicate filter) { + public void removeFromParent(ItemPredicate filter) { callback.remove(filter, true, false); } - public void removeSearch(ItemPredicate filter) { + public void removeFromSearch(ItemPredicate filter) { callback.remove(filter, false, true); } diff --git a/src/main/resources/META-INF/neoforge.mods.toml b/src/main/resources/META-INF/neoforge.mods.toml index cc4e1b065..d78d930c9 100644 --- a/src/main/resources/META-INF/neoforge.mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -20,7 +20,7 @@ displayTest = "NONE" [[dependencies.kubejs]] modId = "neoforge" type = "required" -versionRange = "[21.0,)" +versionRange = "[21.0.86-beta,)" ordering = "NONE" side = "BOTH"