AlmostReliable / summoningrituals

A Minecraft mod to create custom summoning rituals for items and mobs.
https://www.curseforge.com/minecraft/mc-mods/summoningrituals
GNU Lesser General Public License v3.0
10 stars 5 forks source link

Command output type for rituals #22

Open jozzo402 opened 11 months ago

jozzo402 commented 11 months ago

Describe the feature/addition!

An additional output type that executes commands upon ritual completion. Example (in datapack format):

"outputs": [
        { "item": "minecraft:diamond" },
        { "mob": "minecraft:cat" },
        { "command": "kill @e[type=minecraft:creeper,distance=0..100]"
]

This ritual's output would create a diamond, summon a cat, then kill all creepers within a 100 block radius.

Why would like to see this feature/addition?

Commands would add unlimited flexibility to ritual outputs - teleporting, weather-changing, potion effects, /fill, etc. It may also help compatibility with other mods, eg. in the case of #17, a /summon command could be used to properly apply modded NBT to the mob that's summoned:

event.recipes.summoningrituals.altar("minecraft:bone")
      .commandOutput(
            'summon minecraft:wolf ~ ~ ~ { cardinal_components: { "apoli:powers": { Powers: [{ Type: "cot:buff_wolf", Sources: ["cot:test"], Data: {} }] } }, "apathy-spawnType": "spawner" }'
      )

Personally I want this feature so I can have Eldritch Mobs as the result of rituals, using the /summon_eldritch command provided by that mod.

rlnt commented 11 months ago

That's already possible by using the KubeJS completion event for the ritual: https://github.com/AlmostReliable/summoningrituals/wiki/Events#complete-event

However, making this a possible output type would have the benefit of it showing up in the JEI/REI integration if properly implemented. Not sure what that would look like. Maybe a command block with a custom tooltip that you can define per command output.

But I don't really see the need for that since it's already possible with the event. And the symbol for a command output within JEI/REI will be possible when I find the time to implement dummy outputs. Dummy outputs are outputs you can define in your recipe that will not actually be handled by the altar and they are just there for display purposes. You can use them if you do some custom behavior with the aforementioned event.

The only difference would be the data pack support but I recommend using KubeJS anyways so that's likely a "no" from me.

GitHub
Events
A Minecraft mod to create custom summoning rituals for items and mobs. - AlmostReliable/summoningrituals
jozzo402 commented 11 months ago

No worries, I'm more familiar with datapacks so that's what I've been using for making rituals, didn't know commands could already be done with KubeJS. I guess I've got some learning to do, thanks for the links!

rlnt commented 11 months ago

I'll keep that open for now for consideration when I have more time to think about it. Thanks for the idea tho!

jozzo402 commented 11 months ago

Making some progress using KubeJS for this. In the Complete Event I need a way to identify which ritual was completed to trigger the accompanying command, however the ID that's returned is a long string of random letters/numbers:

SummoningRituals.complete(event => {
    event.server.runCommand("say " + event.recipe.getId())
});

Results in: [Server] summoningrituals:kjs_brg9q9x6208sb95ezre724m1d

I was planning to have an if statement checking the ID for each ritual I've made, but after seeing that output I figured there must be a better way.

rlnt commented 11 months ago

KubeJS assigns a dynamic ID if you don't specify one explicitly resulting in the mess you see there. To assign an ID manually, you can append the .id() function on all KubeJS recipes.

event.recipes.summoningrituals.altar("diamond").id("kubejs:summoning/diamond")

This example would use KubeJS as the namespace. It doesn't matter what the recipe ID will be as long as it's unique or it will override other recipes with the same ID. The namespace (the string before the colon) will define which mod this recipe belongs to. Modpack developers usually choose KubeJS or a custom namespace matching their pack name to make it clear that the recipe was custom-made. This is only relevant when you hover over the recipe in JEI or REI because it will say something like "Recipe by KubeJS".

jozzo402 commented 11 months ago

Awesome explanation, thank you! Just discovered ProbeJS so I'm having a much better time with this now.

One last thing, do recipe inputs support NBT? I can assign NBT to the output item, but doing the same to the input has no effect and the ritual accepts any version of that item (eg. enchanted book with Sharpness I is considered the same as Sharpness V). I've tried these both:

.input(Item.of("enchanted_book", 1, {StoredEnchantments:[{id:"minecraft:sharpness",lvl:5}]}))
.input(Item.withNBT("enchanted_book", {StoredEnchantments:[{id:"minecraft:sharpness",lvl:5}]}))

I have the NBT Crafting mod installed.

rlnt commented 11 months ago

These are all basic KubeJS questions you should ask on the KubeJS Discord. 😀

Items ignore NBT by default. You have to explicitly tell it to check NBT. There might also be a problem with the number in the object you pass to the item as well. In JavaScript, all numbers are floating point and when converting it to Java, this mostly results in a double which will not be accepted by Minecraft because it's not valid for enchantments. This can be avoided by passing the whole NBT object as a string.

Two solutions:

Item.of("enchanted_book", 1, `{StoredEnchantments:[{id:"minecraft:sharpness",lvl:5}]}`).strongNBT()
Item.of("enchanted_book").enchant('minecraft:sharpness', 5)
jozzo402 commented 11 months ago

Ah alright, thanks again! Sorry for the irrelevant questions, still new to this so not sure where the line between your mod and KubeJS was. I've joined the discord and any further questions will be asked there :)