#how do I detect the item in an entities main hand?

19 messages · Page 1 of 1 (latest)

tidal prism
#

I'm trying to write a script that detects certain items in an entities hand, and then deletes them, but I can't seem to figure out how to detect what items entities are holding

marble vortexBOT
#

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

median roost
#

It's normally just entity.mainHand

tidal prism
#

...is it really that simple

#

sigh yeah that tracks for me

#

I mean it doesn't crash when I run the script anymore but it still isn't detecting items

#

weird

#

might be an issue with the detection not the other part tho, so Ig that answers my question

fallow bridge
#

let me see if i can find my fix rq

#
event.getEntity().getMainHandItem()

i took this from a BlockEvent.broken script. you have to explicitly request the item itself, not the slot.

sleek zephyr
# fallow bridge ```js event.getEntity().getMainHandItem() ``` i took this from a `BlockEvent.br...

I'm messing with this idea myself, but whenever I try and run the script, I just crash, could you enlighten me a bit?(I'm VERY new to KubeJS, so if it's something dumb I'm sorry 😭)

                let eyePos = player.eyePosition;
                let aabb = AABB.of(eyePos.x(), eyePos.y(), eyePos.z(), endPos.x(), endPos.y(), endPos.z());
                let searchArea = aabb.of(
                    player.x - 7, player.y - 7, player.z - 7,
                    player.x + 7, player.y + 7, player.z + 7
                );
                let nearbyEntities = player.level.getEntities(searchArea, entity => entity !== player);

                nearbyEntities.forEach(otherEntity => {
                    player.tell(`Entity: ${otherEntity.getType().getId()}, Position: ${otherEntity.position()}`);
                });
soft fractalBOT
#

Please send your KubeJS server log. It can be found at /minecraft/logs/kubejs/server.log.
If you are on 1.18 or 1.16 it will be called server.txt.
Please send the file directly, without links or snippets.

fallow bridge
soft fractalBOT
#

Paste version of chiseling.js, item_application.js from @fallow bridge

burnt brook
#

I had to do something similar in my own script, ended up just needing one line to do it:

player.mainHandItem.count--

#

The .count-- just says to remove 1 from the inventory