#How to get all methods on an entity

389 messages · Page 1 of 1 (latest)

safe pond
#

I got probejs already installed, sadly entity.spawned event.entity is any,
I am trying to get all methods on the ender dragon because i want to check his state and do certain things depending on if hes in meele mode etc

eternal sphinxBOT
#

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

past verge
#

you need to run /probejs dump after the event fires for probejs to know the event exists and capture it's types

#

or you can use jsdocs to manually specify the type of something

/**
 * @type {Internal.EnderDragon}
*/
const entity = event.entity
safe pond
#

check this out

#

the 5 listed methods are from the text around it

past verge
#

huh

safe pond
#

when i type any method there listed ill get any

#

so getEntity returns any

safe pond
#

or am i just a dumb dumb rn?

#

i tried using a ts file and it showed me no sub methods

past verge
#

probes inner workings are magic to me

safe pond
#

also

past verge
#

when ive used it the global.d.ts file has had errors but its worked fine, so not sure if that should be worried about

past verge
past verge
# safe pond

it may be expecting stuff only added in 1.19.2, im not sure how much pruno backports

safe pond
#

I can also dumb it again if that helps

winged gorge
#

global.d.ts file has error is not normal

#

can you show what errors are they

safe pond
#

wait

#

why is get and set undefined

winged gorge
#

wtf

safe pond
#

is tsconfig wrongly configured?

winged gorge
#

Nope, it's some mixin or weird thing doing their magic again

#

I never expect calling getName on params can have such weird names

#

1.19.2? I'll fix it some time later

safe pond
#

1.18.2 *

winged gorge
#

rip

safe pond
#

not supported anymore?

winged gorge
#

Not really, I'm super busy recently

#

Try to manually replace <set-?> to param0 and see if it works

safe pond
#

oof, I guess aslong as i have the internal methods i can somewhat do things

#

one sec

winged gorge
#

Or any similar things

safe pond
#

what if i just remove set?

past verge
#

you would have to replace it with something

winged gorge
#

Use this

#

The problem is that the methods are having illegal param names

#

So usually it should be arg0 arg1 or whatever

safe pond
winged gorge
#

yes

#

But now it's <set-?> which breaks TS syntax

safe pond
#

resolved all errors

#

wtf

#

fixed everything

#

it works

winged gorge
#

Should be a workaround for now

safe pond
winged gorge
#

Are you using quilt?

past verge
#

forge

winged gorge
#

smh

past verge
#

based on post tags

safe pond
#

oh i forgot what quilt is

#

xd

#

i googled it lmao

#

ye forge

winged gorge
#

Must be some weird obfuscation/remap problem then

safe pond
#

this is so cool O:

winged gorge
#

Because in forge you have arg0 for those minecraft methods, and in fabric it's $$0, they all work for TS

past verge
winged gorge
past verge
safe pond
#

i got kotlin in here

winged gorge
#

Will fix it some time later

safe pond
#

@winged gorge are you the creator of probe.js?

winged gorge
#

yes

safe pond
#

Thank you for your hard work sir

#

@past verge also thank you for helping me

winged gorge
safe pond
#

ill go back now to buff the ender dragon

#

and let him shoot arrows or something depending on state

#

xd

#

Wait i just get the nearest player and let him aim on him so that he has to run xd

past verge
#

you dont have to run the fastest, just faster than the slowest

safe pond
#

(i resolve it in 2m)

safe pond
#

actually i keep it open if i get questions in the next 10m

#

xd

safe pond
#

im new to kotlin and i dont wanna run it tick based if possible

#

or worst case connect ticks to the ender dragon

safe pond
#

kubejs*

past verge
#

why are you writing scripts in kotlin

safe pond
#

not kotlin

#

im brain afk

past verge
#

oh phew

safe pond
#

xd

#

sorry just casual brain error

past verge
#

i dont think there are many events related to the ender dragon

safe pond
past verge
#

or just check the delta positions

safe pond
#

OH yeah

#

makes sense

#

how do i add an event listener to an internal tick of ender dragon?

#

and is tha tthe right location?

#

(couldnt find any event locations)

past verge
#

kind of

#

there is no entity tick event

#

due to the lag potentional

safe pond
#

(what im trying to avoid)

#

ahh events are on

past verge
#

those arent events

#

they are methods you can call on it

safe pond
#

i just noticed it

#

damn

past verge
#

without a tool like mixin you cant modify the code that is called when that method is ran

#

there is a player tick event, a level tick event and a server tick event.
for any of those you could look for an ender dragon and do stuff on it, but that is costly as you would have to loop through all entities to find the dragons
or you could store the dragon in a list/variable dclared outside the event, so you dont have to keep searching for it. just need to make sure its not dead.

or, the probably best option, is detecting when an ender dragon spawns and then storing that, and having a callback run every x ticks, checking if its dead

safe pond
#

when its getting loaded does that count as spawn?

#

with specific parameters?

past verge
#

on forge, yes

safe pond
#

OH okay

#

good to know

past verge
#

im not sure about other loaders

safe pond
#

okay, its mostly for a friend modpack

#

where i wanna spice things up so its fine

#

but im wondering how i can trigger an event when he for example gets damage

past verge
#

entity.hurt

safe pond
#

but isnt that for all entitites?

past verge
#

check the entities type

safe pond
#

then id have to add an ender dragon check which would be wastefull

past verge
#

if (event.entity.type != 'minecraft:ender_dragon') return

past verge
safe pond
#

am i overestimating the cost of things like that

#

oh sadge

past verge
#

yes

safe pond
#

im really performance driven dev, so this is kind of hard for me rn

#

xd

past verge
#

yuo could probably loop over all entities evey tick and not notice it, but if you suddenly get a farm overflow with items, or a lot of players loading lots of entities, it could get noticeable

past verge
#

yeah

safe pond
#

i did not expect that

past verge
#

datapacks do it all the time

safe pond
#

not that i will do it

#

WHAT

#

wait

#

thats terrible?

#

wtf

past verge
#

any @e or @a, even if it has a filter, requires looping over all entities

safe pond
#

?

past verge
#

well @a is players

safe pond
#

no i get it but like why

past verge
safe pond
#

does mc not keep an array with all players

#

why then do that?

past verge
#

it does keep a list of players seperarely, and im pretty sure @a uses that, but thats the only entity type they do that for

safe pond
#

bruh

past verge
#

hmm

#

mc does keep a few lists related to bosses, but i dont think theres one of the actual bosses

safe pond
#

when entities despawn, do they count as died?

past verge
#

but you may be able to get the entity from something like the boss bar list

past verge
#

tho thats not public

safe pond
#

my goal was to conditionally register the event

safe pond
past verge
safe pond
#

damnnit

past verge
#

EntityEvents.spawned('ender_dragon', event => {

safe pond
#

in my case im stuck here

#

wait

safe pond
#

i just noticed

#

What is this?

past verge
#

fired for some entities before they spawn

#

for conditions like light level checks

safe pond
#

Ohh

#

Is level.tick same as dimension.tick? (since the enderdragon is end only i could reduce the impact that way or?)

#

(should be fine since i controll the modpack)

past verge
#

level == dimension

safe pond
#

okay thank you

past verge
#

well, actualy
level == dimension && side
cause tehre is a server level and a client level per dimension

safe pond
#

oh

#

wait

#

whats the differnce?

#

wait i should just do global tick, otherwise with level.tick i would need to check the dimension and it would have additional overhead

past verge
#

one is on the server, one is on the client. (if you are playing singleplayer there is a mini server running in the background)
because the server is the authorative one, that is where you can do things like change blocks, spawn entities ect
the client is the pretty one, and its where you do things like spawn particles or sounds.

safe pond
#

Ohh

#

wait this is troublesome

#

since if i for example wanna spawn particles before the dragon lets say makes his arrow laser, i would need to somehow check that each tick in the FE or rather the varaible

#

i would have an enderDragonDoes something initital check then a more specific ones for the detailed particle

past verge
#

you can send particles to the client for them to display from the server

safe pond
#

OH

#

okay thanks godness

past verge
#

just like how the client has to keep asking the server to change blocks

safe pond
#

OHH

#

yeah makes sense

#

this is so much fun

#

xd

past verge
#

the client level does keep a record of what blocks are where, and technically you can change those, but they will get reset when the server sends those blocks again (ie you mine them)

safe pond
#

yeah that makes sense

safe pond
past verge
#

yep

#

event.entity.persistentData.someValue = "hello world"
console.log(event.entity.persistentData.someValue)

#

note that uses nbt as a storage medium, which can be... finnicky

#

booleans are converted to 0 or 1 and deleting properties is hard

safe pond
#

one more question (sorry that i use you like an oncall support)
How do i access global variables like all players / all players in a specific level (wanna get closest player)

safe pond
#

okay i just write a string as json

#

xd

#

if i need to

safe pond
#

oh

#

Ohh

#

im going though event rn

#

i expected to have far less data

#

i see so via event i can acess global things and narrow down via the objects to what i need

#

i see

past verge
#

global in kubejs tends to refer to stuff that is across all script types

#

instead on global across the server

safe pond
#

to make interval checks like getting all palyers in a dim with a server tick i can just have a counter go up to 20 and run code depending on that right? or is there a better way

past verge
#

if (event.server.tickCount % 20 != 0) return

safe pond
#

or like that

#

is a planer seen as a mob? (but wreid that byMob and byPlayer are different for set but not for get, i assume its bec of archivements / stratistics?)

past verge
#

technically no

safe pond
#

oh

#

so how do we get last hurt by player?

#

last hurt and compare to by mob?

past verge
#

lastHurtByMob

#

the player isnt a mob, but that method doesnt return mobs

#

it returns living entities

#

blame mojanks weird naming schemes

safe pond
#

ahh okay i get it

#

naming things is hard, i know it as a dev (im a dev but i was so focused with other things i forgot how to code properly 💀)

#

oh players in creative mode dont display

#

so how do i test this without constantly dying 💀

#

brb

past verge
#

/cofh invuln

#

assuming you have cofh core installed

#

or ```js
onEvent('entity.hurt', event => {
if (event.entity.player)
event.cancel()
})

past verge
#

the script will still work without it

safe pond
past verge
#

entity.attack got renamed to entity.hurt in 1.18

safe pond
#

wait entity.attack is us attacking and not entity attacking

#

oh

past verge
#

its entity being attacked

safe pond
#

ah yeha

#

i forgor

#

im an entity

#

xd

#

Say, the end was dimension id 1 right?

past verge
#

kinda

safe pond
#

mods can change it?

past verge
#

numeric ids mostly arent used these days

safe pond
#

but the get method needed a number if im not wrong

#

i tried the_end and minecrat:the end or something similar and it failed

past verge
#

allLevels returns an Iterable

#

so you need to iterate over it

#

if you want to get the end just use event.server.getDimension('the_end')

safe pond
#

there is no getDimension

past verge
#

huh

#

ah

#

getLevel

safe pond
#

Are there inbuild functions for trig calculations or do i need to do them on my own?

#

for example distance between entity and mob

past verge
#

entity1.distanceTo(entity2)

safe pond
#

thank you!

#

monsters have distanceTo, players have it named differently lol

#

i just do it reversed

past verge
#

players should have it too

safe pond
past verge
#

that is very weird

#

cause its on Entity, and all entities inherit from that

safe pond
#

yeah

#

wait lemme remove the abc one

past verge
#

and there doesnt seem to be anything in kubejs renaming it

safe pond
past verge
#

AHH

#

EntityJS doesnt exist anymore

#

wait im on 1.19

safe pond
#

whats that menu?

#

and how can i get that

#

xd

past verge
#

intellij's search in a kubejs dev enviroment

safe pond
#

ohh

#

Good news, it actually gets players in creative mode, so i can continue testing without dying lol

#

Is it possible to create projectiles which wont collide with some entities, for example arrows which go though the dragon or that the dragon does not get dmg from that arrow bomb

#

or explosions if i add some

past verge
#

maybe

#

if you can differentiate between that and a regular arrow/explosion in the hurt event you can

safe pond
#

so i can basically cancel that an entity is being hurt, cancelling that, would it cancel also the removal of that item?

#

so i spawn it with special data info, and use that for my checks on arrow entity collisions

past verge
#

it shouldnt do

safe pond
#

/ hurt

safe pond
#

if it does not cancel the arrow removal i would need to respawn it with same direction which would be bad for performance

#

i guess i will see once im there

past verge
#

making it pahse through the dragon will be more trouble than its worth

safe pond
#

i see, i just increase the spawn arc and let it not dmg the dragon

past verge
#

yeah

safe pond
#

is this too far with kubejs (i assume ppl would say at this point use java)

#

Also

#

returns nan

#

investigating

past verge
safe pond
#

Really

#

wait so why do people say that?

#

is undefined O.O

past verge
#

because at that point you should really be using java

safe pond
past verge
#

but its sometimes easier/faster in js, and also its a nice challenge

safe pond
#

(or youre too lazy to learn java)

#

xd

past verge
#

a fair portion of my knowledge of java comes from reading kubejs source

safe pond
#

makes sense, since they had to figure it all out and create an effective mapping / understand whats usefull and important

#

you can scheduel events, this is cool

past verge
#

check for things to do with ticks on event.server

safe pond
#

i searched for tick related keywords on server and event nothing

#

just

past verge
#

time?

safe pond
#

nop

safe pond
past verge
#

huh

safe pond
#

its also not on the event

past verge
#

youll need to use a counter then

safe pond
#

Yey

#

but thats wreid isnt it?

#

what if you wanna calculate durations?

#

i dont need to really

#

but out of curiousity

past verge
#

you can use javascripts Date object to get real time

safe pond
#

Oh

past verge
#

or there must be some method soemwhere for in game time

safe pond
#

yeah

#

i forgor

#

] Error occurred while handling event 'server.tick': TypeError: Cannot find function distanceTo in object Ender Dragon-739b619a-4f7b-4413-a8a6-338ca1a8f6a1. (server_scripts:orepatch

#

wat

opaque spearBOT
#
List of Mojang (via TSRG2) Mappings for 1.18.2 (Page 1/6)

Linkie is now also on the web, it is easier to use!

Method: net/minecraft/world/entity/Entity#distanceTo
Name: e => m_20270_ => distanceTo
Mixin Target: Lnet/minecraft/world/entity/Entity;distanceTo(Lnet/minecraft/world/entity/Entity;)F
AT: public net.minecraft.world.entity.Entity m_20270_(Lnet/minecraft/world/entity/Entity;)F # distanceTo

Method: net/minecraft/world/phys/HitResult#distanceTo
Name: a => m_82448_ => distanceTo
Mixin Target: Lnet/minecraft/world/phys/HitResult;distanceTo(Lnet/minecraft/world/entity/Entity;)D
AT: public net.minecraft.world.phys.HitResult m_82448_(Lnet/minecraft/world/entity/Entity;)D # distanceTo

Method: net/minecraft/world/level/pathfinder/Node#distanceTo
Name: a => m_164697_ => distanceTo
Mixin Target: Lnet/minecraft/world/level/pathfinder/Node;distanceTo(Lnet/minecraft/core/BlockPos;)F
AT: public net.minecraft.world.level.pathfinder.Node m_164697_(Lnet/minecraft/core/BlockPos;)F # distanceTo

Method: net/minecraft/world/level/pathfinder/Node#distanceTo
Name: a => m_77293_ => distanceTo
Mixin Target: Lnet/minecraft/world/level/pathfinder/Node;distanceTo(Lnet/minecraft/world/level/pathfinder/Node;)F
AT: public net.minecraft.world.level.pathfinder.Node m_77293_(Lnet/minecraft/world/level/pathfinder/Node;)F # distanceTo

past verge
#

it definitely exists on 1.18.2

#

maybe kubejs renames it?

safe pond
#

the ied told that it was distanceTo

past verge
#

oh wait

#

aaahhhh

safe pond
#

wait bec i passed on an entity

#

instead of pos?

past verge
#

1.18.2 still has the wrappers

safe pond
#

wrappers?

past verge
#

EntityJS, LevelJS, ServerJS

#

which arent the actual thing

#

they just hold the actual thing and have (some) methods for interacting with the actual thing

#

entity1.minecraftEntity.distanceTo(entity2.minecraftEntity)

safe pond
#

OHH

past verge
#

i completely forgot

safe pond
#

how can i modify this so this reflects

#

this also explains previous player method error

#

this doesnt work

past verge
#

capital s

#

also the [] says its an array

safe pond
#

yeah i know

#

i wanna later spawn multiple

#

for now i code it semi for one

#

xd

#

@past verge i made capital S, but it says that enderDragons[0] is any

#

okay i know what i need to do

past verge
#

does EntityJS even accept generics?

safe pond
#

yeah

#

thats what i wanted to say, it prob does not

#

and i need to extract it out and then type it

#

oh wait

#

the array was at the wrong loc

#

moment

#

nop no generic

#

i gotta do it like that

#

@past verge I need to go for now, thank you again for all of your help, Ill hit you up when my dragon is causing complains bec hes killing everyone love