Skip to content

Commit

Permalink
feat: update to occultism recipe runtime conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
klikli-dev committed Sep 28, 2024
1 parent 90d1413 commit c81bb43
Show file tree
Hide file tree
Showing 20 changed files with 335 additions and 76 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 33 additions & 11 deletions runs/client/kubejs/server_scripts/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
)
);
})

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,26 +44,33 @@ 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
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
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,35 +19,24 @@
import java.util.List;

public interface RitualRecipeSchema {
RecipeKey<ItemStack> RESULT = ItemStackComponent.ITEM_STACK.outputKey("result").allowEmpty();
RecipeKey<List<Ingredient>> INGREDIENTS = IngredientComponent.INGREDIENT.asList().inputKey("ingredients");
RecipeKey<String> RITUAL_TYPE = StringComponent.ID.inputKey("ritual_type").alt("ritualType").optional("occultism:craft").alwaysWrite();
RecipeKey<String> ENTITY_TO_SUMMON = StringComponent.ID.inputKey("entity_to_summon").alt("entityToSummon").alt("summon").defaultOptional();
RecipeKey<TagKey<EntityType<?>>> ENTITY_TAG_TO_SUMMON = TagKeyComponent.ENTITY_TYPE.inputKey("entity_tag_to_summon").alt("entityTagToSummon").alt("summonTag").defaultOptional();
RecipeKey<String> ENTITY_NBT = StringComponent.ANY.inputKey("entity_nbt").alt("entityNbt").defaultOptional();
RecipeKey<Ingredient> ACTIVATION_ITEM = IngredientComponent.INGREDIENT.inputKey("activation_item").alt("activationItem");
RecipeKey<String> PENTACLE_ID = StringComponent.ID.inputKey("pentacle_id").alt("pentacleId").alt("pentacle");
RecipeKey<TickDuration> DURATION = TimeComponent.TICKS.inputKey("duration").optional(TickDuration.wrap(30));
RecipeKey<Integer> SPIRIT_MAX_AGE = NumberComponent.INT.inputKey("spirit_max_age").alt("spiritMaxAge").alt("maxAge").optional(-1);
RecipeKey<String> SPIRIT_JOB_TYPE = StringComponent.ID.inputKey("spirit_job_type").alt("spiritJobType").alt("jobType").defaultOptional();
RecipeKey<RitualRecipe.RitualRequirementSettings> RITUAL_REQUIREMENT_SETTINGS = RitualRequirementSettingsComponent.RITUAL_REQUIREMENT_SETTINGS.inputKey("ritual_requirement_settings").alt("ritualRequirementSettings").alwaysWrite();
RecipeKey<RitualRecipe.RitualStartSettings> RITUAL_START_SETTINGS = RitualStartSettingsComponent.RITUAL_START_SETTINGS.inputKey("ritual_start_settings").alt("ritualStartSettings").alwaysWrite();
RecipeKey<RitualRecipe.EntityToSummonSettings> ENTITY_TO_SUMMON_SETTINGS = EntityToSummonSettingsComponent.ENTITY_TO_SUMMON_SETTINGS.outputKey("entity_to_summon_settings").alt("entityToSummonSettings")
.defaultOptional();
RecipeKey<ItemStack> 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<RitualRecipe.EntityToSacrifice> ENTITY_TO_SACRIFICE = EntityToSacrificeComponent.ENTITY_TO_SACRIFICE
.inputKey("entity_to_sacrifice").alt("entityToSacrifice").alt("sacrifice")
.defaultOptional();
RecipeKey<Ingredient> ITEM_TO_USE = IngredientComponent.INGREDIENT.inputKey("item_to_use")
.alt("itemToUse").alt("useItem").optional(Ingredient.EMPTY).allowEmpty();
RecipeKey<ItemStack> RESULT = ItemStackComponent.ITEM_STACK.outputKey("result").allowEmpty();
RecipeKey<String> 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);

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<EntityType<?>> tag, String displayName) {
return new RitualRecipe.EntityToSacrifice(tag, displayName);
}
}
Original file line number Diff line number Diff line change
@@ -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<RitualRecipe.EntityToSummonSettings> codec) implements RecipeComponent<RitualRecipe.EntityToSummonSettings> {
public static final RecipeComponent<RitualRecipe.EntityToSummonSettings> 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());

}
}
Original file line number Diff line number Diff line change
@@ -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<EntityType<?>> 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<EntityType<?>> entityTagToSummon,
@Nullable CompoundTag entityNbt,
@Nullable ResourceLocation spiritJobType,
int spiritMaxAge,
int summonNumber
) {
return new RitualRecipe.EntityToSummonSettings(null, entityTagToSummon, entityNbt, spiritJobType, spiritMaxAge, summonNumber);
}
}
Original file line number Diff line number Diff line change
@@ -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> biome) {
return new IsInBiomeCondition(biome);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Loading

0 comments on commit c81bb43

Please sign in to comment.