#How to disable a skeleton's bow without removing its AI or bow

1 messages · Page 1 of 1 (latest)

limpid ginkgo
#

is there a way to stop a skeleton from shooting temporarily (for like a few seconds) without removing its ai or its bow?

I don't want to remove it's ai because that disables gravity for the mob, and I don't want to remove the bow because it will look jank.

I'm trying to add a cool down to how fast skeletons can shoot arrows, and this would make it incredibly easy if it's possible.

lucid flickerBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 If nobody has answered you by <t:1743779750:t>, feel free to use the Summon Helpers button to ping our helper team.

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

wind knot
#

There is no real way to achieve this (other than what you mentioned) so it will always come with some jank

#

You could use teams with friendly fire turned off, then skeletons are passive to players in the same team

#

But entities can only be In one team at a time, so teams are always bad for comparability

#

You can also try setting its follow distance to 0 but iirc that won’t stop skeletons who are already locked onto you

limpid ginkgo
#

I'll have to check it when I get home

supple fox
#

maybe changing the bow to a different item with the item_model of a bow?

limpid ginkgo
supple fox
wind knot
#

Should work in 1.21.3+ iirc

limpid ginkgo
#

oh aw

wind knot
#

1.21.2 added it

#

Oof

#

(It would have been the item_model component)

timid bramble
#

I never tried, but would a skeleton use it's bow if you move it to it's off hand

#

I know some skeletons can be left handed, but in this case I think their left hand counts as their main hand

#

Test it if you want, if it works then you can move the bow to the skeletons off hand

#

oh i just read what you want

#

well removing the bow or even disabling it will cause the skeleton to charge at you like a zombie, im not sure that's what you are aiming for

#

Try and test what happens if you take the bow out of the skeleton's hand and return it quickly when it's trying to shoot

jaunty folio
#

Give it a different item that uses the bow's item_model

timid bramble
#

sadly they're on 1.21.1

mental bluff
#

maybe switch the skeleton's main hand to force it into melee mode?

limpid ginkgo
#

i got around to trying some of this stuff

follow range: setting follow range to 0 works, but causes glitchy behavior and the skeleton will constantly raise and lower its bow while chasing the player

item model: doesn't work on 1.21.1

switching the skeleton's main hand: interrupts firing, but only for a tiny fraction of a second. the bow switches to the new main hand and the skeleton continues shooting. i'm not 100% sure if there is a way to manually switch the bow from one hand to the other at the same time, while keeping all of the bow's enchants and other properties in-tact.

#

it seems that if i disable and reenable the skeleton's ai on every tick, he act like friend and keeps his gravity

#

it would be cool if it would let the skeleton keep its bow raised for this though

#

im not sure if that would be possible with any solution though, i think making the skeleton non-aggroed always makes it lower the bow

limpid ginkgo
jaunty folio
#

It is expensive but mostly because you're modifying NBT, which isn't very performant. That's also the reason for the behavior, when you modify an entity's NBT repeatedly they kinda stop behaving

#

In lieu of changing the item model, just give them a new item with custom model data to make it look like a bow

limpid ginkgo
#

im on 1.21.1

#

ive been told that feature didnt exist yet

jaunty folio
#

Custom model data does

limpid ginkgo
#

oh wait

#

when you spawn an item with a unique number that a texture pack recognizes and replaces the texture of the item?

jaunty folio
#

That is an accurate description of the behavior of custom model data

limpid ginkgo
#

i was planning to make this a standalone datapack, this would be the one and only feature to require any kind of resource pack

jaunty folio
#

Then you need to deal with the other jankier solutions offered

limpid ginkgo
#

i suppose first i should just see what the performance impact is of disabling and enabling the ai

limpid ginkgo
#

the impact is that the datapack takes 3.5% of each tick on average instead of the original 2%

#

im not sure, but it doesn't sound that bad

wind knot
# limpid ginkgo i got around to trying some of this stuff **follow range:** setting follow rang...

Switching the bow to the other hand is very easy actually
You can use item replace … from … to copy the bow from its mainhand to its offhand and then you can use item replace … with air to delete the bow in its mainhand.
And ofc the other way around when switching back.
This solution will very likely be a lot better in terms of performance compared to modifying its nbt every tick (if that’s what you are doing instead).

limpid ginkgo
#

ooohhh

#

i did not know about that command

#

thank you i bet this will work :]

#

will try it now

#

is there any place i can store an item in limbo temporarily?

#

i would ideally want to keep whatever item might be in the offhand

wind knot
#

That’s more difficult

#

You can either have an item display somewhere and store the item there

#

Or you can use a macro to swap the items in place

#

But if you are not sure if the bow has custom components at all, that would be an extra check and a macro, probably still better than an extra entity

limpid ginkgo
#

do macros exist on 1.21.1?

wind knot
#

function ~/swap_hands_macro:
    item replace entity @s weapon.offhand from entity @s weapon.mainhand
    $loot replace entity @s weapon.mainhand loot {"pools":[{"rolls":1,"entries":[{"type":"minecraft:item","name":"$(id)","functions":[{"function":"minecraft:set_count","count":$(count)},{"function":"minecraft:set_components","components":$(components)}]}]}]}

# and then you can use this as the skeleton to swap items
function ~/swap_hands_macro with entity @s HandItems[1]
#

This is using an inline loot table that is filled with the id, count and components of the item stack the skeleton is holding in the offhand

#

This would fail if the offhand item has no components

#

So you'd need to check that first, and run the same function without the "components" part in the loot table instead

#

There may be some small errors in the code I sent, I’m on phone lol

limpid ginkgo
#

ohhh

#

i think i need to learn how to use macros and what they do exactly

limpid ginkgo
#

so if the first line replaces the offhand with the mainhand, how does it remember what the mainhand used to be?

#

is it storing that somewhere? there's not really any commands above that

wind knot
#

All the macro variables ($(variable_name)) get replaced when the function is called

#

So it doesn’t matter if the source of these variables is replaced inside of the macro function

#

So - Yesn’t, they are not stored but when the function is called they are placed in the commands and not loaded again

limpid ginkgo
#

ahhh ok

limpid ginkgo
#
item replace entity @s weapon.offhand from entity @s weapon.mainhand
execute unless items entity @s weapon.mainhand * run return fail
$loot replace entity @s weapon.mainhand loot {"pools":[{"rolls":1,"entries":[{"type":"minecraft:item","name":"$(id)","functions":[{"function":"minecraft:set_count","count":$(count)},{"function":"minecraft:set_components","components":$(components)}]}]}]}
#

so far i have this

#

it doesn't seem to work though, sometimes items exist but don't have components somehow...?

#

well, also it says HandItems is not an element

#

i'm confused though, because it should exist

#

oh bruh ive been testing this on 1.21.5, i thought i was on 1.21.1 rn 😭

#

i am trying to support all current versions along with 1.21.5 though

#

so ideally i get it working for both

wind knot
# limpid ginkgo well, also it says HandItems is not an element

You can check using data get entity <SKELETON> … how HandItems looks.

Id do the checks beforehand, so in pseudo code:

if offhand has components -> return run swap with components
if offhand has no components -> return run swap without components

And then have 2 macro functions, one with the whole components block and one without, so a really small loot table or even an item replace, since you only need the id and count

wind knot
#

If you still want to support multiple, you may use overlays, these are files that are loaded if the client is using a specified version of minecraft

limpid ginkgo
#

ive been using overlays for it

#

hm

#

it seems there have been some big changes to held item nbt though

wind knot
#

Not really, it’s just all in equipment.<slot> instead of HandItems and ArmorItems

limpid ginkgo
#

equipment: {mainhand: {id "minecraft:bow", count:1 }}

#

i think this also means i have to send different info into the macro function ...?

#

im still not fully understanding how they work, ive read the documentation but its kind of hard to understand

wind knot
#

Yeah, the macro functions themselves (if you do the checks outside of them) should be the same but how you check the nbt and how you give the nbt into them is different since the path changed

limpid ginkgo
#

i would expect to be able to write something like this:

item replace entity @s weapon.offhand from entity @s weapon.mainhand
execute if data entity @s equipment.mainhand.components run return run $loot replace entity @s weapon.mainhand loot {"pools":[{"rolls":1,"entries":[{"type":"minecraft:item","name":"$(id)","functions":[{"function":"minecraft:set_count","count":$(count)},{"function":"minecraft:set_components","components":$(components)}]}]}]}
$loot replace entity @s weapon.mainhand loot {"pools":[{"rolls":1,"entries":[{"type":"minecraft:item","name":"$(id)","functions":[{"function":"minecraft:set_count","count":$(count)}]}]}]}
#

but it doesn't like when i move $loot to a different place

#

im not sure why

#

it stops the function from being validated so i cant run it

wind knot
#

Macro functions must start with $

#

So you’d need to place it infront of the execute

limpid ginkgo
#

oh

wind knot
#

Also - it’s generally better to have smaller macro commands and function since all macro commands need to be parsed at runtime

limpid ginkgo
#

i had a fundamental misunderstanding, i thought that was just how you chose a variable name 😭

wind knot
wind knot
limpid ginkgo
#

ahh

wind knot
#

$say THIS IS A MACRO COMMAND, THIS WHOLE THING, BUT A VARIABLE IS $(this)

limpid ginkgo
#

so this is my swap handitems file (no components version)

$loot replace entity @s weapon.mainhand loot {"pools":[{"rolls":1,"entries":[{"type":"minecraft:item","name":"$(id)","functions":[{"function":"minecraft:set_count","count":$(count)}]}]}]}```

and this is my toggle bow file:

function betta_balance:swap_handedness
execute if data entity @s equipment.mainhand.components run return run function betta_balance:swap_handitems_with_components with entity @s equipment.mainhand
function betta_balance:swap_handitems with entity @s equipment.mainhand

#

there are no errors, but nothing happens

wind knot
#

Hm, that looks pretty correct on first glance

teal totemBOT
#
Logs

When making or debugging Minecraft datapacks, it is useful to have the Minecraft logs open in order to view errors quickly.

To open the logs:

  1. Enable the logs in the Minecraft Launcher (see image)
  2. Start Minecraft

The logs should open in a separate window. Datapack errors are shown in the when you /reload and are almost always in red text or yellow text.

wind knot
#

The logs are probably quickest to spot errors

#

Though watch out, all errors are printed when loading the pack but macro errors are printed on execution

#

Also, you can try running the swap command through chat

#

To see the error in chat directly

limpid ginkgo
#

oh i meant in logs

#

there arent any errors

#

none when i run the commands manually either

wind knot
#

Hm, maybe try adding say commands to see if the correct stuff executes

#

And also to give out macro variables

limpid ginkgo
#

so as far as i can tell, literally everything is functional, and the macros have the right values, it's just this line specifically that doesn't do what it's supposed to: $loot replace entity @s weapon.offhand loot {"pools":[{"rolls":1,"entries":[{"type":"minecraft:item","name":"$(id)","functions":[{"function":"minecraft:set_count","count":$(count)},{"function":"minecraft:set_components","components":$(components)}]}]}]}

#

it's weird, because when i run the command with the same formatting on a specific skeleton, just without the macroed loot table, i can give skeletons acacia logs, swords, etc in their offhand

#

it just doesn't seem to work with the in-line loot table

#

maybe loot replace doesnt work for air?

#

yeah ok, that seems to be the case...

#

i tried it out manually

#

it says 0 item dropped, which i guess makes sense

#

so it didnt replace anything

wind knot
#

Mhm, you can probably solve this using a item replace with air before calling the loot table

#

That way the item gets deleted if the macro fails/drops nothing

limpid ginkgo
#

ahh ok

wind knot
#

assuming that is the intended behavior

limpid ginkgo
#

oh

#

so its working now

#

and i feel like ive learned a lot

#

but i guess i should have checked first if putting bow in offhand and making the skeleton other handed actually disabled the bow 😭

#

it does not

#

the skeleton uses the bow like usual, with the only change being that it uses the old skeleton bow holding animation instead of the new one

#

although... that is pretty neat and fits with the vibe of my datapack

#

so at this point, as far as im aware, my only real option is to constantly disable/reenable the skeleton's ai, or put the skeleton and the player on the same team (but this seems messy, could have bad compatibility, and also would make the skeleton visibly lose interest in the player for a brief period of time)

#

or maybe i can combine other-handedness with a follow range of 0? the only glitchy thing about the 0 follow range was the glitched animations, but maybe this fixes that...

wind knot
limpid ginkgo
#

nope, animation still glitches out unfortunately

#

hm

wind knot
#

That’s sad

limpid ginkgo
#

i think i now know how to use them for other things

#

so i guess maybe i should try to find the minimum delay with which a skeleton can pull back a bow and shoot an arrow, and at that exact interval i should disable and re-enable the skeleton's ai

#

i assume they can't shoot in the same tick after getting their ai back

limpid ginkgo
#

if i swap handedness and the items 1 tick after a skeleton spawns, i can make its nbt tags say that nothing is in its mainhand, meanwhile it is holding bows in both hands and using the mainhand bow on me

#

not sure why that is

#

it works if i wait for a while after the skeleton spawned

limpid ginkgo
wind knot
#

If you schedule a function, it returns the gametime at which it will run

#

This should be further optimized using predicates and tags but this should server as an explanation of the tech