#How to get all methods on an entity
389 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
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
interesting, ill try that, but what i also dont understand is that global.d.ts and my editor are not in sync wreidly
check this out
the 5 listed methods are from the text around it
huh
the globa.d.ts file has 78 erroes if that matters
or am i just a dumb dumb rn?
i tried using a ts file and it showed me no sub methods
probes inner workings are magic to me
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
it may be expecting stuff only added in 1.19.2, im not sure how much pruno backports
I can also dumb it again if that helps
wtf
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
1.18.2 *
rip
not supported anymore?
Not really, I'm super busy recently
Try to manually replace <set-?> to param0 and see if it works
Or any similar things
you would have to replace it with something
Use this
The problem is that the methods are having illegal param names
So usually it should be arg0 arg1 or whatever
?
Should be a workaround for now
Are you using quilt?
forge
smh
based on post tags
Must be some weird obfuscation/remap problem then
this is so cool O:
Because in forge you have arg0 for those minecraft methods, and in fabric it's $$0, they all work for TS
looks like it might be kotlin

i got kotlin in here
Will fix it some time later
@winged gorge are you the creator of probe.js?
yes

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
you dont have to run the fastest, just faster than the slowest
(i resolve it in 2m)
do you actually know if i can get the current state of the ender dragon / trigger events on state change / when he gets damage?
im new to kotlin and i dont wanna run it tick based if possible
or worst case connect ticks to the ender dragon
kubejs*
why are you writing scripts in kotlin
oh phew
i dont think there are many events related to the ender dragon
so i would need to compare always pos 1 to pos 2 to see if hes moving or not, since hes only not moving when hes on meele mode
or just check the delta positions
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)
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
but what if the server restarts or the dragon unloads
when its getting loaded does that count as spawn?
with specific parameters?
on forge, yes
im not sure about other loaders
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
entity.hurt
but isnt that for all entitites?
check the entities type
then id have to add an ender dragon check which would be wastefull
if (event.entity.type != 'minecraft:ender_dragon') return
there is no way around that
yes
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
Really?
yeah
i did not expect that
datapacks do it all the time
any @e or @a, even if it has a filter, requires looping over all entities
?
well @a is players
no i get it but like why
in command entity selectors
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
bruh
hmm
mc does keep a few lists related to bosses, but i dont think theres one of the actual bosses
when entities despawn, do they count as died?
but you may be able to get the entity from something like the boss bar list
oh, interesting
tho thats not public
my goal was to conditionally register the event
yes
for that you need 1.19
damnnit
EntityEvents.spawned('ender_dragon', event => {
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)
level == dimension
okay thank you
well, actualy
level == dimension && side
cause tehre is a server level and a client level per dimension
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
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.
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
you can send particles to the client for them to display from the server
just like how the client has to keep asking the server to change blocks
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)
yeah that makes sense
can i also save / load data / save them directly on entities?
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
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)
oof
okay i just write a string as json
xd
if i need to
event.level.players
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
global in kubejs tends to refer to stuff that is across all script types
instead on global across the server
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
if (event.server.tickCount % 20 != 0) return
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?)
technically no
lastHurtByMob
the player isnt a mob, but that method doesnt return mobs
it returns living entities
blame mojanks weird naming schemes
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
/cofh invuln
assuming you have cofh core installed
or ```js
onEvent('entity.hurt', event => {
if (event.entity.player)
event.cancel()
})
sadly i dont have cofh
the script will still work without it
https://wiki.latvian.dev/books/kubejs-legacy/page/list-of-all-events but this list doesnt have it?
This is a list of all events. It's possible that not all events are listed here, but this list will...
entity.attack got renamed to entity.hurt in 1.18
its entity being attacked
kinda
mods can change it?
numeric ids mostly arent used these days
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
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')

Are there inbuild functions for trig calculations or do i need to do them on my own?
for example distance between entity and mob
entity1.distanceTo(entity2)
thank you!
monsters have distanceTo, players have it named differently lol
i just do it reversed
players should have it too
and there doesnt seem to be anything in kubejs renaming it
intellij's search in a kubejs dev enviroment
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
maybe
if you can differentiate between that and a regular arrow/explosion in the hurt event you can
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
it shouldnt do
/ hurt
yeah
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
making it pahse through the dragon will be more trouble than its worth
i see, i just increase the spawn arc and let it not dmg the dragon
yeah
is this too far with kubejs (i assume ppl would say at this point use java)
Also
returns nan
investigating
never
someone remade a good portion of thaumcraft in kubejs
because at that point you should really be using java
but its sometimes easier/faster in js, and also its a nice challenge
a fair portion of my knowledge of java comes from reading kubejs source
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
it might be called something different in 1.18
check for things to do with ticks on event.server
time?
nop
just scheduel in Ticks
huh
its also not on the event
youll need to use a counter then
Yey
but thats wreid isnt it?
what if you wanna calculate durations?
i dont need to really
but out of curiousity
you can use javascripts Date object to get real time
Oh
or there must be some method soemwhere for in game time
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
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
the ied told that it was distanceTo
1.18.2 still has the wrappers
wrappers?
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)
OHH
i completely forgot
how can i modify this so this reflects
this also explains previous player method error
this doesnt work
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
does EntityJS even accept generics?
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 
