#how to get all item ids from one mod

114 messages · Page 1 of 1 (latest)

midnight pivot
#

i want to get an array of all the items from one mod

exotic boltBOT
#

Once your question has been answered, please close this post with </resolve:1050379261372006400> command!

long mantle
#
Ingredient.of('@mekanism').stacks

then you can go through them like
Ingredient.of('@mekanism').stacks.forEach(item => {})

midnight pivot
#

yeah i read about it but because im a bit curious could i ask what would .stacks do

#

i rea dabout is the same as just looking at some code from someone else and not understanding it lmao

long mantle
#

you have the option of using .stacks or .itemIds
stacks gives you a list of ItemStack
itemIds gives you a list of just item IDs

midnight pivot
#

imma look a bit into what an itemstack is and be back for some more questions 🙂

long mantle
#

ItemStack is basically an item that you have in your inventory with all the data it holds

#

so things like count, ID, tags, etc

#

NBT

midnight pivot
#

ok

#

wait so what could be an example of what i would get if i called .stacks on @botania

long mantle
#

lets say you have the apothecary from botania

midnight pivot
#

yeah

long mantle
#

with itemIds you only have botania:apothecary, but with stacks you have the equivalent of Item.of('botania:apothecary')

midnight pivot
#

maybe we could vc about this

#

i have too many questions lol

long mantle
#

i dont really do voicechat heh

midnight pivot
#

ah ok

long mantle
#

but im happy to answer if i know the answer

midnight pivot
#

so what would item.of return on it

midnight pivot
midnight pivot
long mantle
#

thats the item stack, so you can have stuff like i mentioned above

long mantle
midnight pivot
#

ok

long mantle
#

the item stack basically holds all info about that specific item

midnight pivot
#

ok

long mantle
#

one of which is the ID

midnight pivot
#

ok

#

what would doing .stream() after the .stacks do

long mantle
#

as far as i know that would just convert it to a different type of list, so you can have other methods to use on it

midnight pivot
#

oh thanks a lot for the link

#

been searching for it for the past 10 mins lol

long mantle
#

xD

#

this time its java, not JS

#

maybe thats why you were having difficulties

midnight pivot
#

yeah isee

#

well now the second part i was gonna ask is what does the "@mekanism" part mean

long mantle
#

the @ is the mod selector

#

same as JEI does

midnight pivot
#

ok

long mantle
#

you can also replace with /^mekanism:/

midnight pivot
#

ok

#

well whatever i could replace it with is even more confusing xd

long mantle
#

its regex, ^ means "start with" so basically says "any ID that starts with mekanism:"

midnight pivot
#

ok

#

so you specify its regex with / and end iwth / ?

long mantle
#

yes, instead of "something here" you do /something here/

midnight pivot
#

ok

#

so now im confused about what events are

#

as you shouldnt be able to just get ids from nowhere

long mantle
#

it gets the IDs from the game's registry

#

which in super simple terms, is a list of all items in the game

midnight pivot
#

ok

#

so doing .stacks basically tells it its getting it fro mthe registry or am i stupid

#

/ just not understanding anything

long mantle
#

yeah, it basically gets the items with your "search term" and gives you a list

midnight pivot
#

ah nice

#

so its like some function?

#

or whatever of the million things it could be

long mantle
#

i think its a beaned function

modern boneBOT
#

Kubejs has a feature known as beans which allows you to make scripts a tad more readable.
Anything getXy() can be gotten with xy, anything setXy(value) can be set with xy = value and anything isXy() can be checked with just xy.

This allows us to shorten our code! For example, to get a list of all online players you can do: event.getServer().getPlayers(). With beans this can be shortened to event.server.players!

Note that get and is beans only work if the method has no parameters. This means a method like getHeldItem(InteractionHand hand) cannot be shortened to heldItem.
For set the method needs to have a single parameter.

midnight pivot
#

oh ok

#

so thats why i got so confused

#

so i could do .itemids?

long mantle
#

capital I i think

#

.itemIds

midnight pivot
#

yeha yeah

#

and to be sure, that would return an array right?

#

and it would be like mechanism:atomically_reactive_grenade or whatever such

long mantle
#

yes

midnight pivot
#

ok

midnight pivot
#

ok

long mantle
#

whoops wait

#

there we go, messed up the line number

midnight pivot
#

ok

#

als owould ingredient become an array or do i need to do something else to get it to be one

#

im just curious about it

#

probs wont use it like that

long mantle
#

not sure what you mean

#

i mean, i guess in a way Ingredient is a list

midnight pivot
#

when ido ingredient.of does that mean ingredient becomes an array

long mantle
#

in a way yes

midnight pivot
#

or whatever it could

long mantle
#

but you still need those 2 functions

midnight pivot
#

so i could later use ingredient to do a foreach?

#

im guessing no as its probably used to create an array that is used once and then never used again

long mantle
#

i mean you can reuse it as many times as you want

midnight pivot
#

ok

#
onEvent('tags.items', event => {

event.add('environmentz:warm_armor', '@mcda')
});```
#

also why does this work

long mantle
midnight pivot
#

like my reaction was wtf how did my friend make this work

long mantle
#

i think the event might be item.tags

midnight pivot
#

im guessing this works right? js Ingredient.of('@mcda').itemIds.forEach(id => { event.add('environmentz:warm_armor', id) })

long mantle
midnight pivot
#

it is tags.items

#

1.18.2

long mantle
#

i also see this, kinda confused which one is the correct one lmao

midnight pivot
#

lmao

long mantle
#

if you put a console.log('test') in that event, will it show up in the server logs?

midnight pivot
#

gonna see if my friend pushed changes to repo

modern boneBOT
#

Paste version of server.txt from @midnight pivot

midnight pivot
#

thx gnom

long mantle
#

thanks gnome

long mantle
midnight pivot
#

ok

midnight pivot
#

Cool thing... My script wasnt working correctly so i had to fix my config. Every change i did was overwritten i will try again today

exotic boltBOT
#

@midnight pivot Unresolved thread still hasn't been closed! If your question was answered, please close this post with </ticket close:1054771505520717835> command!