#How do I get an array of stuff in non-item tags?

71 messages · Page 1 of 1 (latest)

frigid delta
#

I want the array of entities in the #forge:bosses entity tag for example

pliant condorBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

frigid delta
#

i know i could do it in the tags event, but can i do it outside of that?

timber warrenBOT
#

inside your event u can do this, feel free to move the loadings outside of the event

const Registries = Java.loadClass("net.minecraft.core.registries.BuiltInRegistries")
const TagKey = Java.loadClass("net.minecraft.tags.TagKey")
const myTag = TagKey.create(Registries.ENTITY_TYPE.key(), "minecraft:frog_food")

let level = event.getLevel();
let entity = event.getEntity();
Registries.ENTITY_TYPE.getTag(myTag).flatMap(holders => holders.getRandomElement(level.getRandom())).ifPresent(holder => {
    let type = holder.value()
    let createdEntity = type.create(entity.getLevel())
    createdEntity.setPos(entity.x, entity.y, entity.z)
    entity.getLevel().addFreshEntity(createdEntity)
});
viral jetty
#

you can take an example here how to get entities by a tag

#

BuiltInRegistries.ENTITY_TYPE.getTagOrEmpty(tag) also exists. It returns an iterable of holders. The holder.value() returns the entity type then

frigid delta
#

kinda confused on what im looking at exactly though haha

frigid delta
# timber warren

at what part of this code is an array of stuff in that tag being returned?

#

also, where do i find the minecraft source code?

#

im assuming from some specific mapping but idk

#

is it const myTag = TagKey.create(Registries.ENTITY_TYPE.key(), "minecraft:frog_food")?

viral jetty
#

^ this create the TagKey object u need to lookup in the Registry yep

#

BuiltInRegistries.ENTITY_TYPE.getTagOrEmpty(myTag) returns a iterable you can loop over

for(let holder of BuiltInRegistries.ENTITY_TYPE.getTagOrEmpty(tag)) {
  let entityType = holder.value();
}
frigid delta
#

got it alright, thanks

#

now uhh.. how do i convert net.minecraft.world.entity.EntityType into its entity id

#

like instead of entity.aether.slider i want aether:slider

viral jetty
#

eh does holder.key().location() exists

#

idk KekDoggo

frigid delta
#

time to find out

#

constants/vars.js#10: TypeError: Cannot find function location in object entity.aether.slider.

#

:(

viral jetty
frigid delta
#

i was doing it in the declaration ```js
for (let holder of Registries.ENTITY_TYPE.getTagOrEmpty(myTag)) {
let entityType = holder.value().location()
}

#

so yea holder

viral jetty
#

no, you call location() on the entityType

#

holder.key().location()

frigid delta
#

oh wut

viral jetty
#

damn momo ASmadDannii

frigid delta
#

oh wait

#

whoops

viral jetty
#

alternative you can BuiltInRegistries.ENTITY_TYPE.getKey(entityType)

frigid delta
#

listen im running on 4 hours of sleep

#

ah yea that worked 💀 sorry

frigid delta
#

where do i find this class i wanna read some java despair

viral jetty
#

no, that returns you already a resourcelocation

viral jetty
frigid delta
#

yea but im lazy

viral jetty
#

BuiltInRegistries.ENTITY_TYPE.getKey(entityType).toString() is probably what u want

frigid delta
#

lmao

#

that does it though, thanks

#

is there a list of other tag types? how would i try to use biome tags or block tags?

#

assuming i just have to change ENTITY_TYPE

viral jetty
#

yes

#

use probejs, they should give u all possible registries

frigid delta
#

hm? how?

viral jetty
#

after dump it should be able to autocomplete BuiltInRegistries hmm

frigid delta
#

i guess not?

#

idk if this is what you meant lol

viral jetty
#

does it need a jsdoc for type hmm

#
/**
 * @type {Internal.BuiltInRegistries}
 */
const BuiltInRegistries = Java.loadClass("net.minecraft.core.registries.BuiltInRegistries")
#

not sure if thats the correct type

#

u have to check somehow

frigid delta
#

im rusty on my jsdoc but i know this should theoretically work right?

#

if that is the right type even

#

no clue how i'd check lol

viral jetty
#

yeah it's the wrong type name

#

you have to search in the typings file from probe

frigid delta
#

🤷‍♂️

viral jetty
#

@glacial nebula dinkDonk

#

he sleeps probably

#

but when he is awake, he will tell u heh

frigid delta
#

Alright hopefully lol

glacial nebula
#

The name changes between versions

#

You can use the RegistryInfo provided by kubejs

#

but I don't have pc around me now so you better figure out yourself