Skip to content

Commit

Permalink
Added a type wrapper for recipe type to simplify passing references a…
Browse files Browse the repository at this point in the history
…round.
  • Loading branch information
Hunter19823 committed Jun 14, 2024
1 parent 4f7604c commit 6ca4bde
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
26 changes: 26 additions & 0 deletions common/src/main/java/pie/ilikepiefoo/AdditionsPlugin.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package pie.ilikepiefoo;

import dev.architectury.platform.Platform;
import dev.latvian.mods.kubejs.KubeJSPlugin;
import dev.latvian.mods.kubejs.event.EventGroup;
import dev.latvian.mods.kubejs.level.BlockContainerJS;
import dev.latvian.mods.kubejs.script.BindingsEvent;
import dev.latvian.mods.kubejs.script.ScriptType;
import dev.latvian.mods.rhino.util.wrap.TypeWrappers;
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.core.BlockPos;
import net.minecraft.data.worldgen.Structures;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.levelgen.feature.Feature;
import pie.ilikepiefoo.compat.jade.JadeEvents;
import pie.ilikepiefoo.compat.jei.JEIEvents;
import pie.ilikepiefoo.compat.jei.events.JEIEventJS;
import pie.ilikepiefoo.events.AdditionalEvents;
import pie.ilikepiefoo.events.custom.ArchEventRegisterEventJS;
import pie.ilikepiefoo.player.CustomDamageSourceJS;
Expand Down Expand Up @@ -57,6 +62,27 @@ public void registerTypeWrappers(ScriptType type, TypeWrappers typeWrappers) {
}
return ChunkPos.ZERO;
});

if (Platform.isModLoaded("jei")) {
typeWrappers.registerSimple(RecipeType.class, (object) -> {
if (object instanceof RecipeType<?> recipeType) {
return recipeType;
}
if (object instanceof IRecipeCategory<?> category) {
return category.getRecipeType();
}
if (JEIEventJS.JEI_HELPERS == null) {
return null;
}
if (object instanceof String recipeType) {
return JEIEventJS.JEI_HELPERS.getRecipeType(new ResourceLocation(recipeType)).orElse(null);
}
if (object instanceof ResourceLocation recipeType) {
return JEIEventJS.JEI_HELPERS.getRecipeType(recipeType).orElse(null);
}
return null;
});
}
}

public interface EmptyHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public CustomRecipeCategory<?> custom(ResourceLocation recipeType, Consumer<Reci
return register(getOrCreateCustomRecipeType(recipeType), categoryConsumer);
}

public <T> CustomRecipeCategory<T> wrap(ResourceLocation recipeType, IRecipeCategory<T> existingCategory, Consumer<RecipeCategoryWrapperBuilder<T>> categoryConsumer) {
public <T> CustomRecipeCategory<T> wrap(RecipeType<T> recipeType, IRecipeCategory<T> existingCategory, Consumer<RecipeCategoryWrapperBuilder<T>> categoryConsumer) {
RecipeCategoryWrapperBuilder<T> builder = new RecipeCategoryWrapperBuilder<>(
getOrCreateCustomOverriddenRecipeType(recipeType, existingCategory.getRecipeType()),
recipeType,
data.getJeiHelpers(),
existingCategory
);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enabled_platforms=fabric,forge
archives_base_name=kubejsadditions
mod_id=kubejsadditions
mod_name=KubeJS Addditions
mod_version=4.3.1
mod_version=4.3.2
mod_description=A mod that adds a bunch of additional features to KubeJS.
mod_author=ILIKEPIEFOO2
mod_icon=assets/kubejsadditions/kubejs_logo.png
Expand Down

0 comments on commit 6ca4bde

Please sign in to comment.