Skip to content

Commit

Permalink
Updated neo, fixed few bugs with latest neo version
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Jul 12, 2024
1 parent afc5679 commit 3793802
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 41 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/dev/latvian/mods/kubejs/holder/KubeJSHolderSets.java
Original file line number Diff line number Diff line change
@@ -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<HolderSetType> REGISTRY = DeferredRegister.create(NeoForgeRegistries.Keys.HOLDER_SET_TYPES, KubeJS.MOD_ID);

Holder<HolderSetType> REGEX = REGISTRY.register("regex", () -> RegExHolderSet::codec);
Holder<HolderSetType> NAMESPACE = REGISTRY.register("namespace", () -> NamespaceHolderSet::codec);
Holder<HolderSetType> REGEX = REGISTRY.register("regex", () -> new HolderSetType() {
@Override
public <T> MapCodec<? extends ICustomHolderSet<T>> makeCodec(ResourceKey<? extends Registry<T>> registryKey, Codec<Holder<T>> holderCodec, boolean forceList) {
return RegExHolderSet.codec(registryKey);
}

@Override
public <T> StreamCodec<RegistryFriendlyByteBuf, ? extends ICustomHolderSet<T>> makeStreamCodec(ResourceKey<? extends Registry<T>> registryKey) {
return RegExHolderSet.streamCodec(registryKey);
}
});

Holder<HolderSetType> NAMESPACE = REGISTRY.register("namespace", () -> new HolderSetType() {
@Override
public <T> MapCodec<? extends ICustomHolderSet<T>> makeCodec(ResourceKey<? extends Registry<T>> registryKey, Codec<Holder<T>> holderCodec, boolean forceList) {
return NamespaceHolderSet.codec(registryKey);
}

@Override
public <T> StreamCodec<RegistryFriendlyByteBuf, ? extends ICustomHolderSet<T>> makeStreamCodec(ResourceKey<? extends Registry<T>> registryKey) {
return NamespaceHolderSet.streamCodec(registryKey);
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,13 +22,17 @@
import java.util.Set;

public class NamespaceHolderSet<T> extends HolderSet.ListBacked<T> implements ICustomHolderSet<T> {
public static <T> MapCodec<NamespaceHolderSet<T>> codec(ResourceKey<? extends Registry<T>> registryKey, Codec<Holder<T>> holderCodec, boolean forceList) {
public static <T> MapCodec<NamespaceHolderSet<T>> codec(ResourceKey<? extends Registry<T>> 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 <T> StreamCodec<RegistryFriendlyByteBuf, NamespaceHolderSet<T>> streamCodec(ResourceKey<? extends Registry<T>> registryKey) {
return null;
}

public final HolderLookup.RegistryLookup<T> registryLookup;
public final String namespace;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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;
import net.minecraft.core.Holder;
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;
Expand All @@ -22,13 +23,17 @@
import java.util.regex.Pattern;

public class RegExHolderSet<T> extends HolderSet.ListBacked<T> implements ICustomHolderSet<T> {
public static <T> MapCodec<RegExHolderSet<T>> codec(ResourceKey<? extends Registry<T>> registryKey, Codec<Holder<T>> holderCodec, boolean forceList) {
public static <T> MapCodec<RegExHolderSet<T>> codec(ResourceKey<? extends Registry<T>> 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 <T> StreamCodec<RegistryFriendlyByteBuf, RegExHolderSet<T>> streamCodec(ResourceKey<? extends Registry<T>> registryKey) {
return null;
}

public final HolderLookup.RegistryLookup<T> registryLookup;
public final Pattern pattern;

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

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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));
}
Expand All @@ -215,6 +229,10 @@ public void registerItemSubtypes(ISubtypeRegistration registration) {

@Override
public <T> void registerFluidSubtypes(ISubtypeRegistration registration, IPlatformFluidHelper<T> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Map.Entry<ItemStack, CreativeModeTab.TabVisibility>>();

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

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ displayTest = "NONE"
[[dependencies.kubejs]]
modId = "neoforge"
type = "required"
versionRange = "[21.0,)"
versionRange = "[21.0.86-beta,)"
ordering = "NONE"
side = "BOTH"

Expand Down

0 comments on commit 3793802

Please sign in to comment.