diff --git a/build.gradle b/build.gradle index a8253a7..419227d 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,7 @@ runs { sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { + mavenLocal() maven { url "https://dl.cloudsmith.io/public/klikli-dev/mods/maven/" content { diff --git a/gradle.properties b/gradle.properties index 05a441d..410ad3a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -42,8 +42,8 @@ mod_description=KubeJS Plugin for Occultism kubejs_version=2101.7.0-build.171 kubejs_version_range=[2101.7.0-build.171,) -occultism_version=1.153.2 -occultism_version_range=[1.146.0,) +occultism_version=1.160.0 +occultism_version_range=[1.160.0,) #curios_version=5.2.0-beta.3 #jei_version=15.2.0.23 #geckolib_version=4.4 diff --git a/runs/client/kubejs/server_scripts/example.js b/runs/client/kubejs/server_scripts/example.js index 1a8cd3e..a850061 100644 --- a/runs/client/kubejs/server_scripts/example.js +++ b/runs/client/kubejs/server_scripts/example.js @@ -19,15 +19,37 @@ ServerEvents.recipes((event) => { '#occultism:miners/master' ) event.recipes.occultism.ritual( - 'occultism:spirit_lantern', - [ - "lapis_lazuli", - "#c:raw_materials", - "minecraft:coal" - ], - '#c:stones', - 'occultism:craft_afrit' - ).dummy("kubejs:dummy_ritual_thing") - .useItem('minecraft:egg') - .entityToSacrifice(EntityToSacrifice.of("minecraft:cows", "Cows"))//it would be better to use a translation key instead of "Cows" to allow translating to other languages. E.g. "tags.entities.cows" -> but that also needs a corresponding translation in en_us.json and other lang files. + 'occultism:spirit_lantern', //result + RitualRequirementSettings.of( + 'occultism:craft_afrit', //pentacleId + [ + "lapis_lazuli", + "#c:raw_materials", + "minecraft:coal" + ], //ingredients + '#c:stones', //activationItem + 10, //optional, duration + ), + RitualStartSettings.of( + EntityToSacrifice.of( + "minecraft:cows", //the tag of entities to sacrifice + "Cows" + //the text to show in recipe viewers such as JEI/EMI/... + //it would be better to use a translation key instead of "Cows" to allow translating to other languages. E.g. "tags.entities.cows" -> but that also needs a corresponding translation in en_us.json and other lang files. + ), //optional entity to sacrifice (use null if none) + 'minecraft:egg', //optional item to use (use null if none) + IsInBiomeCondition.of("minecraft:plains"), //optional condition (use null if none). Wrappers provided by OccultismKubeJS: IsInBiomeCondition, IsInBiomeWithTagCondition, IsInDimensionCondition, IsInDimensionTypeCondition. Also supports neoforge default conditions, but there is no kubejs wrapper for them yet. + ), + ).dummy("kubejs:dummy_ritual_thing") //the ritual dummy, used to allow viewing recipes in JEI/EMI/... + .ritualType("occultism:craft") //the ritual type. If omitted, it will default to "occultism:craft" + .entityToSummonSettings( + EntityToSummonSettings.of( + "minecraft:zombie", //the id of the entity to summon. Use null if you want to use a tag instead. + null, //"minecraft:cows", the tag of entities to summon. Use null if you want to use an id instead. + null, //the nbt of the entity to summon. Use null if you don't want to specify nbt. + "occultism:crush_tier1", //the spirit job type. Use null if you don't want to summon a spirit. Works only on occultism spirit entities. + -1, //the max age of the spirit. Use -1 if want the spirit to last forever. Works only on occultism spirit entities (ignored for other entities). + 1 //the number of entities to summon. Use 1 if you want to summon only one entity. + ) + ); }) diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/EntityToSacrificeWrapper.java b/src/main/java/com/klikli_dev/occultism_kubejs/EntityToSacrificeWrapper.java deleted file mode 100644 index 53fb51c..0000000 --- a/src/main/java/com/klikli_dev/occultism_kubejs/EntityToSacrificeWrapper.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.klikli_dev.occultism_kubejs; - -import com.klikli_dev.occultism.crafting.recipe.RitualRecipe; -import com.klikli_dev.occultism.crafting.recipe.result.RecipeResult; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import dev.latvian.mods.kubejs.KubeJS; -import dev.latvian.mods.kubejs.component.DataComponentWrapper; -import dev.latvian.mods.kubejs.item.ItemStackJS; -import dev.latvian.mods.kubejs.typings.Info; -import dev.latvian.mods.kubejs.util.RegistryAccessContainer; -import dev.latvian.mods.rhino.Wrapper; -import net.minecraft.core.component.DataComponentPredicate; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.ItemTags; -import net.minecraft.tags.TagKey; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.crafting.Ingredient; -import org.jetbrains.annotations.Nullable; - -@Info("Various entity to sacrifice related helper methods") -public interface EntityToSacrificeWrapper { - - @Info("Returns an RitualRecipe.EntityToSacrifice of the input") - static RitualRecipe.EntityToSacrifice of(RitualRecipe.EntityToSacrifice in) { - return in; - } - - @Info("Returns an RitualRecipe.EntityToSacrifice of the input") - static RitualRecipe.EntityToSacrifice of(TagKey> tag, String displayName) { - return new RitualRecipe.EntityToSacrifice(tag, displayName); - } -} diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/KubeJSOccultismPlugin.java b/src/main/java/com/klikli_dev/occultism_kubejs/KubeJSOccultismPlugin.java index ac4d350..113e6be 100644 --- a/src/main/java/com/klikli_dev/occultism_kubejs/KubeJSOccultismPlugin.java +++ b/src/main/java/com/klikli_dev/occultism_kubejs/KubeJSOccultismPlugin.java @@ -25,6 +25,7 @@ import com.klikli_dev.occultism.crafting.recipe.result.RecipeResult; import com.klikli_dev.occultism.crafting.recipe.result.WeightedRecipeResult; import com.klikli_dev.occultism.registry.OccultismRecipes; +import com.klikli_dev.occultism_kubejs.component.*; import dev.latvian.mods.kubejs.plugin.KubeJSPlugin; import dev.latvian.mods.kubejs.recipe.schema.RecipeComponentFactoryRegistry; import dev.latvian.mods.kubejs.recipe.schema.RecipeSchemaRegistry; @@ -43,12 +44,11 @@ public void registerBuilderTypes(BuilderTypeRegistry registry) { @Override public void registerRecipeSchemas(RecipeSchemaRegistry registry) { - registry.register(OccultismRecipes.SPIRIT_FIRE.getId(), OccultismRecipeSchema.SPIRIT_FIRE); registry.register(OccultismRecipes.SPIRIT_TRADE.getId(), OccultismRecipeSchema.SPIRIT_TRADE); registry.register(OccultismRecipes.CRUSHING.getId(), OccultismRecipeSchema.CRUSHING); registry.register(OccultismRecipes.MINER.getId(), OccultismRecipeSchema.MINER); -// registry.register(OccultismRecipes.RITUAL.getId(), RitualRecipeSchema.SCHEMA); //now loaded from json + registry.register(OccultismRecipes.RITUAL.getId(), RitualRecipeSchema.SCHEMA); //now loaded from json } @Override @@ -56,6 +56,9 @@ public void registerRecipeComponents(RecipeComponentFactoryRegistry registry) { registry.register(RecipeResultComponent.RECIPE_RESULT); registry.register(WeightedRecipeResultComponent.WEIGHTED_RECIPE_RESULT); registry.register(EntityToSacrificeComponent.ENTITY_TO_SACRIFICE); + registry.register(RitualStartSettingsComponent.RITUAL_START_SETTINGS); + registry.register(RitualRequirementSettingsComponent.RITUAL_REQUIREMENT_SETTINGS); + registry.register(EntityToSummonSettingsComponent.ENTITY_TO_SUMMON_SETTINGS); } @Override @@ -63,6 +66,11 @@ public void registerBindings(BindingRegistry bindings) { bindings.add("RecipeResult", RecipeResultWrapper.class); bindings.add("WeightedRecipeResult", WeightedRecipeResultWrapper.class); bindings.add("EntityToSacrifice", EntityToSacrificeWrapper.class); + bindings.add("RitualStartSettings", RitualStartSettingsWrapper.class); + bindings.add("RitualRequirementSettings", RitualRequirementSettingsWrapper.class); + bindings.add("EntityToSummonSettings", EntityToSummonSettingsWrapper.class); + bindings.add("EntityToSummonSettings", EntityToSummonSettingsWrapper.class); + bindings.add("IsInBiomeCondition", IsInBiomeConditionWrapper.class); } @Override diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/OccultismRecipeSchema.java b/src/main/java/com/klikli_dev/occultism_kubejs/OccultismRecipeSchema.java index c8d7341..303a46b 100644 --- a/src/main/java/com/klikli_dev/occultism_kubejs/OccultismRecipeSchema.java +++ b/src/main/java/com/klikli_dev/occultism_kubejs/OccultismRecipeSchema.java @@ -2,6 +2,8 @@ import com.klikli_dev.occultism.crafting.recipe.result.RecipeResult; import com.klikli_dev.occultism.crafting.recipe.result.WeightedRecipeResult; +import com.klikli_dev.occultism_kubejs.component.RecipeResultComponent; +import com.klikli_dev.occultism_kubejs.component.WeightedRecipeResultComponent; import dev.latvian.mods.kubejs.recipe.RecipeKey; import dev.latvian.mods.kubejs.recipe.component.*; import dev.latvian.mods.kubejs.recipe.schema.RecipeSchema; diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/RitualRecipeSchema.java b/src/main/java/com/klikli_dev/occultism_kubejs/RitualRecipeSchema.java index 62c68f3..880c4fc 100644 --- a/src/main/java/com/klikli_dev/occultism_kubejs/RitualRecipeSchema.java +++ b/src/main/java/com/klikli_dev/occultism_kubejs/RitualRecipeSchema.java @@ -1,6 +1,10 @@ package com.klikli_dev.occultism_kubejs; import com.klikli_dev.occultism.crafting.recipe.RitualRecipe; +import com.klikli_dev.occultism_kubejs.component.EntityToSacrificeComponent; +import com.klikli_dev.occultism_kubejs.component.EntityToSummonSettingsComponent; +import com.klikli_dev.occultism_kubejs.component.RitualRequirementSettingsComponent; +import com.klikli_dev.occultism_kubejs.component.RitualStartSettingsComponent; import dev.latvian.mods.kubejs.recipe.RecipeKey; import dev.latvian.mods.kubejs.recipe.component.*; import dev.latvian.mods.kubejs.recipe.schema.RecipeSchema; @@ -15,35 +19,24 @@ import java.util.List; public interface RitualRecipeSchema { - RecipeKey RESULT = ItemStackComponent.ITEM_STACK.outputKey("result").allowEmpty(); - RecipeKey> INGREDIENTS = IngredientComponent.INGREDIENT.asList().inputKey("ingredients"); RecipeKey RITUAL_TYPE = StringComponent.ID.inputKey("ritual_type").alt("ritualType").optional("occultism:craft").alwaysWrite(); - RecipeKey ENTITY_TO_SUMMON = StringComponent.ID.inputKey("entity_to_summon").alt("entityToSummon").alt("summon").defaultOptional(); - RecipeKey>> ENTITY_TAG_TO_SUMMON = TagKeyComponent.ENTITY_TYPE.inputKey("entity_tag_to_summon").alt("entityTagToSummon").alt("summonTag").defaultOptional(); - RecipeKey ENTITY_NBT = StringComponent.ANY.inputKey("entity_nbt").alt("entityNbt").defaultOptional(); - RecipeKey ACTIVATION_ITEM = IngredientComponent.INGREDIENT.inputKey("activation_item").alt("activationItem"); - RecipeKey PENTACLE_ID = StringComponent.ID.inputKey("pentacle_id").alt("pentacleId").alt("pentacle"); - RecipeKey DURATION = TimeComponent.TICKS.inputKey("duration").optional(TickDuration.wrap(30)); - RecipeKey SPIRIT_MAX_AGE = NumberComponent.INT.inputKey("spirit_max_age").alt("spiritMaxAge").alt("maxAge").optional(-1); - RecipeKey SPIRIT_JOB_TYPE = StringComponent.ID.inputKey("spirit_job_type").alt("spiritJobType").alt("jobType").defaultOptional(); + RecipeKey RITUAL_REQUIREMENT_SETTINGS = RitualRequirementSettingsComponent.RITUAL_REQUIREMENT_SETTINGS.inputKey("ritual_requirement_settings").alt("ritualRequirementSettings").alwaysWrite(); + RecipeKey RITUAL_START_SETTINGS = RitualStartSettingsComponent.RITUAL_START_SETTINGS.inputKey("ritual_start_settings").alt("ritualStartSettings").alwaysWrite(); + RecipeKey ENTITY_TO_SUMMON_SETTINGS = EntityToSummonSettingsComponent.ENTITY_TO_SUMMON_SETTINGS.outputKey("entity_to_summon_settings").alt("entityToSummonSettings") + .defaultOptional(); RecipeKey RITUAL_DUMMY = ItemStackComponent.ITEM_STACK.outputKey("ritual_dummy").alt("ritualDummy").alt("dummyItem").alt("dummy") // apparently there is never any static reference to this item, so let's just hope klikli never changes this lmao .optional(new ItemStack(BuiltInRegistries.ITEM.get(ResourceLocation.parse("occultism:ritual_dummy/custom_ritual")))) .alwaysWrite(); - - RecipeKey ENTITY_TO_SACRIFICE = EntityToSacrificeComponent.ENTITY_TO_SACRIFICE - .inputKey("entity_to_sacrifice").alt("entityToSacrifice").alt("sacrifice") - .defaultOptional(); - RecipeKey ITEM_TO_USE = IngredientComponent.INGREDIENT.inputKey("item_to_use") - .alt("itemToUse").alt("useItem").optional(Ingredient.EMPTY).allowEmpty(); + RecipeKey RESULT = ItemStackComponent.ITEM_STACK.outputKey("result").allowEmpty(); RecipeKey COMMAND = StringComponent.ANY.inputKey("command").defaultOptional(); RecipeSchema SCHEMA = new RecipeSchema( // all the required keys first - RESULT, INGREDIENTS, ACTIVATION_ITEM, PENTACLE_ID, + RESULT, + RITUAL_REQUIREMENT_SETTINGS, RITUAL_START_SETTINGS, // and now all the optionals... - DURATION, SPIRIT_MAX_AGE, SPIRIT_JOB_TYPE, RITUAL_DUMMY, RITUAL_TYPE, - ENTITY_TO_SUMMON, ENTITY_TAG_TO_SUMMON, ENTITY_NBT, ENTITY_TO_SACRIFICE, ITEM_TO_USE, COMMAND + ENTITY_TO_SUMMON_SETTINGS, RITUAL_DUMMY, RITUAL_TYPE, COMMAND ).uniqueId(RITUAL_DUMMY); } diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/EntityToSacrificeComponent.java b/src/main/java/com/klikli_dev/occultism_kubejs/component/EntityToSacrificeComponent.java similarity index 96% rename from src/main/java/com/klikli_dev/occultism_kubejs/EntityToSacrificeComponent.java rename to src/main/java/com/klikli_dev/occultism_kubejs/component/EntityToSacrificeComponent.java index f691ae4..d062d5f 100644 --- a/src/main/java/com/klikli_dev/occultism_kubejs/EntityToSacrificeComponent.java +++ b/src/main/java/com/klikli_dev/occultism_kubejs/component/EntityToSacrificeComponent.java @@ -1,4 +1,4 @@ -package com.klikli_dev.occultism_kubejs; +package com.klikli_dev.occultism_kubejs.component; import com.google.gson.JsonObject; import com.klikli_dev.occultism.crafting.recipe.RitualRecipe; diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/component/EntityToSacrificeWrapper.java b/src/main/java/com/klikli_dev/occultism_kubejs/component/EntityToSacrificeWrapper.java new file mode 100644 index 0000000..10a14d4 --- /dev/null +++ b/src/main/java/com/klikli_dev/occultism_kubejs/component/EntityToSacrificeWrapper.java @@ -0,0 +1,20 @@ +package com.klikli_dev.occultism_kubejs.component; + +import com.klikli_dev.occultism.crafting.recipe.RitualRecipe; +import dev.latvian.mods.kubejs.typings.Info; +import net.minecraft.tags.TagKey; +import net.minecraft.world.entity.EntityType; + +@Info("Various entity to sacrifice related helper methods") +public interface EntityToSacrificeWrapper { + + @Info("Returns an RitualRecipe.EntityToSacrifice of the input") + static RitualRecipe.EntityToSacrifice of(RitualRecipe.EntityToSacrifice in) { + return in; + } + + @Info("Returns an RitualRecipe.EntityToSacrifice of the input") + static RitualRecipe.EntityToSacrifice of(TagKey> tag, String displayName) { + return new RitualRecipe.EntityToSacrifice(tag, displayName); + } +} diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/component/EntityToSummonSettingsComponent.java b/src/main/java/com/klikli_dev/occultism_kubejs/component/EntityToSummonSettingsComponent.java new file mode 100644 index 0000000..cbdca5a --- /dev/null +++ b/src/main/java/com/klikli_dev/occultism_kubejs/component/EntityToSummonSettingsComponent.java @@ -0,0 +1,40 @@ +package com.klikli_dev.occultism_kubejs.component; + +import com.google.gson.JsonObject; +import com.klikli_dev.occultism.crafting.recipe.RitualRecipe; +import com.mojang.serialization.Codec; +import com.mojang.serialization.JsonOps; +import dev.latvian.mods.kubejs.recipe.KubeRecipe; +import dev.latvian.mods.kubejs.recipe.component.RecipeComponent; +import dev.latvian.mods.rhino.Context; +import dev.latvian.mods.rhino.type.TypeInfo; + +public record EntityToSummonSettingsComponent(String name, Codec codec) implements RecipeComponent { + public static final RecipeComponent ENTITY_TO_SUMMON_SETTINGS = new EntityToSummonSettingsComponent("occultism:entity_to_summon_settings", RitualRecipe.EntityToSummonSettings.CODEC); + + public static final TypeInfo TYPE_INFO = TypeInfo.of(EntityToSummonSettingsComponent.class); + + @Override + public TypeInfo typeInfo() { + return TYPE_INFO; + } + + @Override + public String toString() { + return this.name; + } + + @Override + public RitualRecipe.EntityToSummonSettings wrap(Context cx, KubeRecipe recipe, Object from) { + if (from instanceof RitualRecipe.EntityToSummonSettings k) { + return k; + } + + if (from instanceof JsonObject json) { + return this.codec.decode(JsonOps.INSTANCE, json).result().orElseThrow().getFirst(); + } + + return (RitualRecipe.EntityToSummonSettings) cx.jsToJava(from, this.typeInfo()); + + } +} diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/component/EntityToSummonSettingsWrapper.java b/src/main/java/com/klikli_dev/occultism_kubejs/component/EntityToSummonSettingsWrapper.java new file mode 100644 index 0000000..5b6a8c7 --- /dev/null +++ b/src/main/java/com/klikli_dev/occultism_kubejs/component/EntityToSummonSettingsWrapper.java @@ -0,0 +1,48 @@ +package com.klikli_dev.occultism_kubejs.component; + +import com.klikli_dev.occultism.crafting.recipe.RitualRecipe; +import dev.latvian.mods.kubejs.typings.Info; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.entity.EntityType; +import org.jetbrains.annotations.Nullable; + +@Info("Various entity to sacrifice related helper methods") +public interface EntityToSummonSettingsWrapper { + + @Info("Returns an RitualRecipe.EntityToSummonSettings of the input") + static RitualRecipe.EntityToSummonSettings of(RitualRecipe.EntityToSummonSettings in) { + return in; + } + + @Info("Returns an RitualRecipe.EntityToSummonSettings of the input") + static RitualRecipe.EntityToSummonSettings of(@Nullable EntityType entityToSummon, + @Nullable TagKey> entityTagToSummon, + @Nullable CompoundTag entityNbt, + @Nullable ResourceLocation spiritJobType, + int spiritMaxAge, + int summonNumber) { + return new RitualRecipe.EntityToSummonSettings(entityToSummon, entityTagToSummon, entityNbt, spiritJobType, spiritMaxAge, summonNumber); + } + + @Info("Returns an RitualRecipe.EntityToSummonSettings of the input") + static RitualRecipe.EntityToSummonSettings ofEntity(@Nullable EntityType entityToSummon, + @Nullable CompoundTag entityNbt, + @Nullable ResourceLocation spiritJobType, + int spiritMaxAge, + int summonNumber + ) { + return new RitualRecipe.EntityToSummonSettings(entityToSummon, null, entityNbt, spiritJobType, spiritMaxAge, summonNumber); + } + + @Info("Returns an RitualRecipe.EntityToSummonSettings of the input") + static RitualRecipe.EntityToSummonSettings ofTag(@Nullable TagKey> entityTagToSummon, + @Nullable CompoundTag entityNbt, + @Nullable ResourceLocation spiritJobType, + int spiritMaxAge, + int summonNumber + ) { + return new RitualRecipe.EntityToSummonSettings(null, entityTagToSummon, entityNbt, spiritJobType, spiritMaxAge, summonNumber); + } +} diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/component/IsInBiomeConditionWrapper.java b/src/main/java/com/klikli_dev/occultism_kubejs/component/IsInBiomeConditionWrapper.java new file mode 100644 index 0000000..ef73206 --- /dev/null +++ b/src/main/java/com/klikli_dev/occultism_kubejs/component/IsInBiomeConditionWrapper.java @@ -0,0 +1,20 @@ +package com.klikli_dev.occultism_kubejs.component; + +import com.klikli_dev.occultism.crafting.recipe.conditionextension.condition.IsInBiomeCondition; +import dev.latvian.mods.kubejs.typings.Info; +import net.minecraft.core.Holder; +import net.minecraft.world.level.biome.Biome; + +@Info("Various IsInBiomeCondition related helper methods") +public interface IsInBiomeConditionWrapper { + + @Info("Returns an IsInBiomeCondition of the input") + static IsInBiomeCondition of(IsInBiomeCondition in) { + return in; + } + + @Info("Returns an IsInBiomeCondition of the input") + static IsInBiomeCondition of(Holder biome) { + return new IsInBiomeCondition(biome); + } +} diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/RecipeResultComponent.java b/src/main/java/com/klikli_dev/occultism_kubejs/component/RecipeResultComponent.java similarity index 96% rename from src/main/java/com/klikli_dev/occultism_kubejs/RecipeResultComponent.java rename to src/main/java/com/klikli_dev/occultism_kubejs/component/RecipeResultComponent.java index d258769..0aec9f6 100644 --- a/src/main/java/com/klikli_dev/occultism_kubejs/RecipeResultComponent.java +++ b/src/main/java/com/klikli_dev/occultism_kubejs/component/RecipeResultComponent.java @@ -1,4 +1,4 @@ -package com.klikli_dev.occultism_kubejs; +package com.klikli_dev.occultism_kubejs.component; import com.google.gson.JsonObject; import com.klikli_dev.occultism.crafting.recipe.result.RecipeResult; diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/RecipeResultWrapper.java b/src/main/java/com/klikli_dev/occultism_kubejs/component/RecipeResultWrapper.java similarity index 98% rename from src/main/java/com/klikli_dev/occultism_kubejs/RecipeResultWrapper.java rename to src/main/java/com/klikli_dev/occultism_kubejs/component/RecipeResultWrapper.java index ea0f0ef..179b6c4 100644 --- a/src/main/java/com/klikli_dev/occultism_kubejs/RecipeResultWrapper.java +++ b/src/main/java/com/klikli_dev/occultism_kubejs/component/RecipeResultWrapper.java @@ -1,4 +1,4 @@ -package com.klikli_dev.occultism_kubejs; +package com.klikli_dev.occultism_kubejs.component; import com.klikli_dev.occultism.crafting.recipe.result.RecipeResult; import com.mojang.brigadier.StringReader; @@ -11,7 +11,6 @@ import dev.latvian.mods.rhino.Wrapper; import net.minecraft.core.component.DataComponentPredicate; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.ItemTags; import net.minecraft.tags.TagKey; diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/component/RitualRequirementSettingsComponent.java b/src/main/java/com/klikli_dev/occultism_kubejs/component/RitualRequirementSettingsComponent.java new file mode 100644 index 0000000..9e380dd --- /dev/null +++ b/src/main/java/com/klikli_dev/occultism_kubejs/component/RitualRequirementSettingsComponent.java @@ -0,0 +1,40 @@ +package com.klikli_dev.occultism_kubejs.component; + +import com.google.gson.JsonObject; +import com.klikli_dev.occultism.crafting.recipe.RitualRecipe; +import com.mojang.serialization.Codec; +import com.mojang.serialization.JsonOps; +import dev.latvian.mods.kubejs.recipe.KubeRecipe; +import dev.latvian.mods.kubejs.recipe.component.RecipeComponent; +import dev.latvian.mods.rhino.Context; +import dev.latvian.mods.rhino.type.TypeInfo; + +public record RitualRequirementSettingsComponent(String name, Codec codec) implements RecipeComponent { + public static final RecipeComponent RITUAL_REQUIREMENT_SETTINGS = new RitualRequirementSettingsComponent("occultism:ritual_requirement_settings", RitualRecipe.RitualRequirementSettings.CODEC); + + public static final TypeInfo TYPE_INFO = TypeInfo.of(RitualRequirementSettingsComponent.class); + + @Override + public TypeInfo typeInfo() { + return TYPE_INFO; + } + + @Override + public String toString() { + return this.name; + } + + @Override + public RitualRecipe.RitualRequirementSettings wrap(Context cx, KubeRecipe recipe, Object from) { + if (from instanceof RitualRecipe.RitualRequirementSettings k) { + return k; + } + + if (from instanceof JsonObject json) { + return this.codec.decode(JsonOps.INSTANCE, json).result().orElseThrow().getFirst(); + } + + return (RitualRecipe.RitualRequirementSettings) cx.jsToJava(from, this.typeInfo()); + + } +} diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/component/RitualRequirementSettingsWrapper.java b/src/main/java/com/klikli_dev/occultism_kubejs/component/RitualRequirementSettingsWrapper.java new file mode 100644 index 0000000..a5f096e --- /dev/null +++ b/src/main/java/com/klikli_dev/occultism_kubejs/component/RitualRequirementSettingsWrapper.java @@ -0,0 +1,37 @@ +package com.klikli_dev.occultism_kubejs.component; + +import com.klikli_dev.occultism.crafting.recipe.RitualRecipe; +import dev.latvian.mods.kubejs.typings.Info; +import net.minecraft.core.NonNullList; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.crafting.Ingredient; + +import java.util.List; + +@Info("Various ritual requirement settings related helper methods") +public interface RitualRequirementSettingsWrapper { + + @Info("Returns an RitualRecipe.RitualRequirementSettings of the input") + static RitualRecipe.RitualRequirementSettings of(RitualRecipe.RitualRequirementSettings in) { + return in; + } + + @Info("Returns an RitualRecipe.RitualRequirementSettings of the input") + static RitualRecipe.RitualRequirementSettings of( + ResourceLocation pentacleId, + List ingredients, + Ingredient activationItem, + int duration + ) { + return new RitualRecipe.RitualRequirementSettings(pentacleId, NonNullList.copyOf(ingredients), activationItem, duration, -1); + } + + @Info("Returns an RitualRecipe.RitualRequirementSettings of the input") + static RitualRecipe.RitualRequirementSettings of( + ResourceLocation pentacleId, + List ingredients, + Ingredient activationItem + ) { + return of(pentacleId, ingredients, activationItem, RitualRecipe.DEFAULT_DURATION); + } +} diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/component/RitualStartSettingsComponent.java b/src/main/java/com/klikli_dev/occultism_kubejs/component/RitualStartSettingsComponent.java new file mode 100644 index 0000000..10ae851 --- /dev/null +++ b/src/main/java/com/klikli_dev/occultism_kubejs/component/RitualStartSettingsComponent.java @@ -0,0 +1,40 @@ +package com.klikli_dev.occultism_kubejs.component; + +import com.google.gson.JsonObject; +import com.klikli_dev.occultism.crafting.recipe.RitualRecipe; +import com.mojang.serialization.Codec; +import com.mojang.serialization.JsonOps; +import dev.latvian.mods.kubejs.recipe.KubeRecipe; +import dev.latvian.mods.kubejs.recipe.component.RecipeComponent; +import dev.latvian.mods.rhino.Context; +import dev.latvian.mods.rhino.type.TypeInfo; + +public record RitualStartSettingsComponent(String name, Codec codec) implements RecipeComponent { + public static final RecipeComponent RITUAL_START_SETTINGS = new RitualStartSettingsComponent("occultism:ritual_start_settings", RitualRecipe.RitualStartSettings.CODEC); + + public static final TypeInfo TYPE_INFO = TypeInfo.of(RitualStartSettingsComponent.class); + + @Override + public TypeInfo typeInfo() { + return TYPE_INFO; + } + + @Override + public String toString() { + return this.name; + } + + @Override + public RitualRecipe.RitualStartSettings wrap(Context cx, KubeRecipe recipe, Object from) { + if (from instanceof RitualRecipe.RitualStartSettings k) { + return k; + } + + if (from instanceof JsonObject json) { + return this.codec.decode(JsonOps.INSTANCE, json).result().orElseThrow().getFirst(); + } + + return (RitualRecipe.RitualStartSettings) cx.jsToJava(from, this.typeInfo()); + + } +} diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/component/RitualStartSettingsWrapper.java b/src/main/java/com/klikli_dev/occultism_kubejs/component/RitualStartSettingsWrapper.java new file mode 100644 index 0000000..c1770b8 --- /dev/null +++ b/src/main/java/com/klikli_dev/occultism_kubejs/component/RitualStartSettingsWrapper.java @@ -0,0 +1,25 @@ +package com.klikli_dev.occultism_kubejs.component; + +import com.klikli_dev.occultism.crafting.recipe.RitualRecipe; +import dev.latvian.mods.kubejs.typings.Info; +import net.minecraft.world.item.crafting.Ingredient; +import net.neoforged.neoforge.common.conditions.ICondition; +import org.jetbrains.annotations.Nullable; + +@Info("Various ritual start settings related helper methods") +public interface RitualStartSettingsWrapper { + + @Info("Returns an RitualRecipe.RitualStartSettings of the input") + static RitualRecipe.RitualStartSettings of(RitualRecipe.RitualStartSettings in) { + return in; + } + + @Info("Returns an RitualRecipe.RitualStartSettings of the input") + static RitualRecipe.RitualStartSettings of( + @Nullable RitualRecipe.EntityToSacrifice entityToSacrifice, + @Nullable Ingredient itemToUse, + @Nullable ICondition condition + ) { + return new RitualRecipe.RitualStartSettings(entityToSacrifice, itemToUse, condition); + } +} diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/WeightedRecipeResultComponent.java b/src/main/java/com/klikli_dev/occultism_kubejs/component/WeightedRecipeResultComponent.java similarity index 96% rename from src/main/java/com/klikli_dev/occultism_kubejs/WeightedRecipeResultComponent.java rename to src/main/java/com/klikli_dev/occultism_kubejs/component/WeightedRecipeResultComponent.java index e430417..9b34201 100644 --- a/src/main/java/com/klikli_dev/occultism_kubejs/WeightedRecipeResultComponent.java +++ b/src/main/java/com/klikli_dev/occultism_kubejs/component/WeightedRecipeResultComponent.java @@ -1,4 +1,4 @@ -package com.klikli_dev.occultism_kubejs; +package com.klikli_dev.occultism_kubejs.component; import com.google.gson.JsonObject; import com.klikli_dev.occultism.crafting.recipe.result.WeightedRecipeResult; diff --git a/src/main/java/com/klikli_dev/occultism_kubejs/WeightedRecipeResultWrapper.java b/src/main/java/com/klikli_dev/occultism_kubejs/component/WeightedRecipeResultWrapper.java similarity index 99% rename from src/main/java/com/klikli_dev/occultism_kubejs/WeightedRecipeResultWrapper.java rename to src/main/java/com/klikli_dev/occultism_kubejs/component/WeightedRecipeResultWrapper.java index ffae5d4..3acb336 100644 --- a/src/main/java/com/klikli_dev/occultism_kubejs/WeightedRecipeResultWrapper.java +++ b/src/main/java/com/klikli_dev/occultism_kubejs/component/WeightedRecipeResultWrapper.java @@ -1,4 +1,4 @@ -package com.klikli_dev.occultism_kubejs; +package com.klikli_dev.occultism_kubejs.component; import com.klikli_dev.occultism.crafting.recipe.result.WeightedRecipeResult; import com.mojang.brigadier.StringReader;