-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add component type and wrapper for entity to sacrifice
the component builder seems not to work the way we want This may fix EnigmaticaModpacks/Enigmatica10#90 Closes #5 because the server run now has an example for the entity to sacrifice
- Loading branch information
1 parent
88ba5ca
commit a6e37fa
Showing
6 changed files
with
84 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/klikli_dev/occultism_kubejs/EntityToSacrificeComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.klikli_dev.occultism_kubejs; | ||
|
||
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 EntityToSacrificeComponent(String name, Codec<RitualRecipe.EntityToSacrifice> codec) implements RecipeComponent<RitualRecipe.EntityToSacrifice> { | ||
public static final RecipeComponent<RitualRecipe.EntityToSacrifice> ENTITY_TO_SACRIFICE = new EntityToSacrificeComponent("occultism:entity_to_sacrifice", RitualRecipe.EntityToSacrifice.CODEC); | ||
|
||
public static final TypeInfo TYPE_INFO = TypeInfo.of(EntityToSacrificeComponent.class); | ||
|
||
@Override | ||
public TypeInfo typeInfo() { | ||
return TYPE_INFO; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.name; | ||
} | ||
|
||
@Override | ||
public RitualRecipe.EntityToSacrifice wrap(Context cx, KubeRecipe recipe, Object from) { | ||
if (from instanceof RitualRecipe.EntityToSacrifice k) { | ||
return k; | ||
} | ||
|
||
if (from instanceof JsonObject json) { | ||
return this.codec.decode(JsonOps.INSTANCE, json).result().orElseThrow().getFirst(); | ||
} | ||
|
||
return (RitualRecipe.EntityToSacrifice) cx.jsToJava(from, this.typeInfo()); | ||
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/klikli_dev/occultism_kubejs/EntityToSacrificeWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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<EntityType<?>> tag, String displayName) { | ||
return new RitualRecipe.EntityToSacrifice(tag, displayName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters