Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command output type for rituals #22

Open
jozzo402 opened this issue Jul 30, 2023 · 9 comments
Open

Command output type for rituals #22

jozzo402 opened this issue Jul 30, 2023 · 9 comments

Comments

@jozzo402
Copy link

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
Copy link
Member

rlnt commented Jul 30, 2023

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
A Minecraft mod to create custom summoning rituals for items and mobs. - AlmostReliable/summoningrituals

@jozzo402
Copy link
Author

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
Copy link
Member

rlnt commented Jul 30, 2023

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

@jozzo402
Copy link
Author

jozzo402 commented Aug 4, 2023

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.

  • Is there any way to get a more human-friendly ID? Such as the name of the file, "ritual_zombie_boss.js"
  • Is there any way to set an ID when I make the recipe? Eg:
event.recipes.summoningrituals.altar("diamond").itemOutput("2x diamond").recipeId("diamond_doubling")

@rlnt
Copy link
Member

rlnt commented Aug 4, 2023

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
Copy link
Author

jozzo402 commented Aug 7, 2023

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
Copy link
Member

rlnt commented Aug 7, 2023

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
Copy link
Author

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 :)

@Dannieboi
Copy link

Is there any examples of using the summon command in kubejs in a instance like this i cant really find one and im new to it and the mob output function in summoning a mob is removing all the bosses weapons and armor so he cant do his moveset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants