#How to make bees attack your attacker?

1 messages · Page 1 of 1 (latest)

modest sonnet
#

Version 26.1.2
I'm working on a chestplate enchantment called Buzzy that has a chance to summon three bees when you're hit. These bees are supposed to then get angry at and sting your attacker, but I have been unable to make the bees get angry. I've done a great deal of research and tried a great many things but nothing quite works, so I'm here asking for help.
I will post everything as text under this, as it is too long for this message.

modest sonnet
#

Here is the enchantment:

    "anvil_cost": 3,
    "description": "Buzzy",
    "effects": {
        "location_changed": [
            {
                "effect": {
                    "type": "apply_mob_effect",
                    "to_apply": "slow_falling",
                    "min_duration": 5,
                    "max_duration": 10,
                    "min_amplifier": 1,
                    "max_amplifier": 255
                },
                "requirements": {
                    "condition": "entity_properties",
                    "entity": "this",
                    "predicate": {
                        "movement": {
                            "fall_distance": {
                                "min": 20,
                                "max": 40
                            }
                        }
                    }
                }
                
            }
        ],
      "post_attack": [
        {
            "affected": "victim",
            "effect": {
                "type": "run_function",
                "function": "summonbees"
                
            },
            "enchanted": "victim",
            "requirements": {
                "chance": {
                    "type": "minecraft:enchantment_level",
                    "amount": {
                        "type": "minecraft:linear",
                        "base": 0.1,
                        "per_level_above_first": 0.1

                    }
                },
                "condition": "random_chance"
            }
        }
      ]
    },
    "exclusive_set": "#exclusive_set/thorns",
    "max_cost": {
        "base": 15,
        "per_level_above_first": 10
    },
    "max_level": 3,
    "min_cost": {
        "base": 5,
        "per_level_above_first": 2
    },
    "primary_items": "#minecraft:enchantable/chest_armor",
    "slots": [
        "chest"
    ],
    "supported_items": "#minecraft:enchantable/chest_armor",
    "weight": 9
}```
#

Here is the function ran by the enchantment:

summon bee ~ ~1 ~ {Tags:[SummonedByBuzzy],CannotEnterHiveTicks:999999999}
summon bee ~ ~1 ~ {Tags:[SummonedByBuzzy],CannotEnterHiveTicks:999999999}
damage @e[type=bee,tag=SummonedByBuzzy,limit=1] 0 generic by @n[predicate=!isbuzzy,tag=!SummonedByBuzzy]```
#

Here is the predicate which ensures players wearing a chestplate with Buzzy do not get attacked:

    "condition": "entity_properties",
    "entity": "this",
    "predicate": {
        "slots": {
            "armor.chest": {
                "predicates": {
                    "enchantments": [
                        {
                            "enchantments": "buzzy"
                        }
                    ]
                }
            }
        }
    }
}```
thorny musk
#

you can chnage execute context with execute on attacker subcommand so it will run as the attacker

#

Then damage the bees as the attacker

#

You could also change the way your enchantment works by runing the function not as the vitim but as the attacker and use damage by @s

modest sonnet
#

so here's what I've added to the enchantment:

            "affected": "attacker",
            "enchanted": "victim",
            "effect": {
                "type": "run_function",
                "function": "angerbees"
            }
        }```
and here's the new function:
`damage @n[type=bee,tag=SummonedByBuzzy,limit=1] 0 generic by @s`
however, due to both the bees being summoned and damaged on the same tick, they won't attack until the player is damaged again. i've tried to add the angerbees function with a 2 tick delay to the original function and have it be run fully by the attacker, but this causes the bees to simply not attack at all
is there a way for me to make this function run on a delay and still work, or just another way at all to get this to work? if not, I can settle for this, since it's better than not working at all, and I really appreciate the help!
thorny musk
#

Note that when scheduling functions, (with /schedule), all the context is lost so as @s will be the server and at @s will be at 0 0 0

modest sonnet
#

i see, so that's why scheduling it in the original function didn't work

thorny musk
#

Does anything change if instead of damaging 0, you damage a small amount ?

modest sonnet
#

i shall try that right now!

thorny musk
#

And you can summon the bees in the attacker function so that you ensure the bees are summoned before the damage command is ran

modest sonnet
#

a small amount of damage seems to change nothing unfortunately

#

changing the function to be like this:

summon bee ~ ~1 ~ {Tags:[SummonedByBuzzy],CannotEnterHiveTicks:999999999}
summon bee ~ ~1 ~ {Tags:[SummonedByBuzzy],CannotEnterHiveTicks:999999999}
damage @n[type=bee,tag=SummonedByBuzzy,limit=1] 0.1 generic by @s```
and have it ran by the attacker in the enchantment also does not seem to fix the issue
thorny musk
#

Make sure you exit and reenter the world when modifying enchantments as /reload won't actually reload them.

modest sonnet
#

yes, i learned that the hard way in an event i tried to run a week ago lol

thorny musk
#

And also, you need to target @e[type=bee,tag=SummonedByBuzzy,limit=3]

#

what happens when you get hit 2 times in a row ?

modest sonnet
thorny musk
#

Oh didn't know that

modest sonnet
#

otherwise i wouldn't even use a limit at all

thorny musk
#

Then /execute as @e... and you need to tag the attacker so you can easily target them

modest sonnet
#

like this?
execute as @e[type=bee,tag=SummonedByBuzzy] on attacker run damage @n[type=bee,tag=SummonedByBuzzy,limit=1] 0.1 generic by @s

thorny musk
#

nope that won't work

modest sonnet
#

also putting the two functions together does seem to remove the bees getting angry at all, even before changing it to /execute
it seems the only way it worked was with two separate functions, and that would only work on second time hit

thorny musk
#
tag @s add temp
summon ...
execute as @e[type=bee,tag=SummonedByBuzzy] run damage @s 0 generic by @e[tag=temp]
tag @s remove temp
#

Alternatively, bees have an angry_at tag that you could use for your use case

modest sonnet
# thorny musk ``` tag @s add temp summon ... execute as @e[type=bee,tag=SummonedByBuzzy] run d...

unfortunately, this does not cause the bees to attack, unless i've done it wrong. here's how i did it:

summon bee ~ ~1 ~ {Tags:[SummonedByBuzzy],CannotEnterHiveTicks:999999999}
summon bee ~ ~1 ~ {Tags:[SummonedByBuzzy],CannotEnterHiveTicks:999999999}
summon bee ~ ~1 ~ {Tags:[SummonedByBuzzy],CannotEnterHiveTicks:999999999}
execute as @e[type=bee,tag=SummonedByBuzzy] on attacker run damage @s 0 generic by @n[tag=TargetedByBuzzy]
tag @s remove TargetedByBuzzy```
#

oh whoops i did do it wrong i see

#

please hold, my apologies

#

fixed it, however the first set of bees summoned will not attack, it's only when the second set is summoned that they get angry

thorny musk
#

does the second set attack right away ?

modest sonnet
#

the second set does attack right away, and it angers the first set and subsequent sets as well

thorny musk
#

I tried some stuff on my own but it seems that bees cannot be angered on the tick they are spawned so you will need to schedule a function

modest sonnet
#

how can i schedule it in a way where the context isn't lost? or would i simply need to try doing it in a different way

thorny musk
#

Actually I manage to do it

#

You just need to summon your bees with a AngerTime set to something more than 20

modest sonnet
#

i see

#

i set AngerTime to 300, it did in fact summon the bees in an angry state, but they did not attack until the second set of bees were summoned

thorny musk
#

execute as @e[bee selector] run data modify entity @s AngryAt set from entity @n[target selector] UUID

#

Yep it didn't work with the /damage command but it does work with this ^

modest sonnet
#

it wasn't working at first, but when i changed AngryAt to angry_at, it began working

#

thank you so much!

#

i'm going to do some more testing and ensure it works consistently before closing this

thorny musk