#(Solved!)How to make entities block (with or without shield), what component do I need to add?

1 messages · Page 1 of 1 (latest)

primal cove
#

Is there any vanilla examples of entities that can block? And also what query or variable in aniamtion controllers is needed to detect when the entity is blocking?

sterile vector
#

Hello again... I have done this before, but there is no vanilla example. What I did was I modeled the shield on my entity (which I'm guessing you did) then setup a "randomizer" for him to start blocking. How good is your knowledge of minecraft:environment_sensor and entity structure like component groups and events? Because the method I used will take quite a bit longer to explain if you do not already understand what these things do.

primal cove
#

But I did get events to work

sterile vector
#

I'll start by asking, what are you trying to achieve in detail? Is it a mob that will block randomly like I did? Because my system is sum up like this. The mob will randomly use its shield. When the shield is it up it will take 0 damage until a timer runs out or the player hits the entity with an axe to disable the shield.

#

If this system seems desirable to what you are trying to achieve, I have all the answers

primal cove
sterile vector
#

alright STEP 1 "minecraft:environment_sensor": { "triggers": [ { "filters": { "all_of": [ { "test": "//any other filters you want like distance to target or whatever" }, { "test": "has_target", //makes it to where it will only start blocking when it has a target "value": true }, { "test": "has_tag", "operator": "not", //tag that will be active when he is blocking "value": "blocking" } ] }, "event": "start_block_randomize"//event to run every tick while these filters are true } ] }

#

this part of the sensor will run an event every tick when the filters are true

#

STEP 2 "start_block_randomize": { "randomize": [ { "weight": 200 }, { "weight": 1, "trigger": { "event": "block_start" } } ] }

#

This is the event that will run every tick when the sensor is true. it has a 1 in 200 chance of running every tick

#

roughly every ten seconds or so. Change the weight values to whatever you desire for the frequency it will enter the blocking stage

#

STEP 3 the actual start event "block_start": { "add": { "component_groups": [ "shielded" // component group that we will make to add the damage sensor and timer ] }, "queue_command": { "command": [ "tag @s add blocking", // tag that we used earlier "effect @s slowness 10000000 1 true"// I gave my guy slowness whenever he was shielded so he would walk a little slower but this is not necessary ] } }

#

This is the event that has a 1/200 chance of triggering every tick when the sensor is true

#

STEP 4 component group```
"shielded": {
"minecraft:timer": {
"time_down_event": {
"event": "block_done"//event that will end the blocking
},
"looping": true,
"time": [
3,// the time range in seconds that the block will last
10
]
},
"minecraft:is_saddled":{},// I use is_saddled here to trigger the query.is_saddled molang statement in animation controllers. This will allow you to play the animation of him blocking

"minecraft:damage_sensor": { //damage sensor to remove damage and play a sound when the player strikes the shield WE WILL ADD TO THIS LATER
"triggers": [
    {
        "cause": "all",
        "deals_damage": false,
        "damage_multiplier": 0,
        "on_damage": {
            "event": "shield_sound"
        }
    }
]

}
}```

#

This is the actual component that adds the damage sensor and the timer. Note a few things: The msg by the minecraft:is_saddled component and that we will return to our damage_sensor event later to add the removing the shield when hit by an axe

primal cove
#

Thanks

primal cove
#

Just wondering, can I replace it with ressistance instead of a timer or is it realy needed?

sterile vector
#

STEP 5 the sound event and axe test

    "queue_command": {
        "command": [
            "playsound item.shield.block @a ~ ~ ~ 1 0.6"// Plays the shield sound
        ]
    },
    "trigger": {
        
                "event": "shield_broken",
        "filters": {
            "any_of": [
                {
                    "test": "has_equipment",
                    "subject": "other",
                    "operator": "==",
                    "domain": "hand",
                    "value": "minecraft:diamond_axe"
                },
                {
                    "test": "has_equipment",
                    "subject": "other",
                    "operator": "==",
                    "domain": "hand",
                    "value": "minecraft:wooden_axe"
                },
                {
                    "test": "has_equipment",
                    "subject": "other",
                    "operator": "==",
                    "domain": "hand",
                    "value": "minecraft:stone_axe"
                },
                {
                    "test": "has_equipment",
                    "subject": "other",
                    "operator": "==",
                    "domain": "hand",
                    "value": "minecraft:iron_axe"
                },
                {
                    "test": "has_equipment",
                    "subject": "other",
                    "operator": "==",
                    "domain": "hand",
                    "value": "minecraft:golden_axe"
                },
                {
                    "test": "has_equipment",
                    "subject": "other",
                    "operator": "==",
                    "domain": "hand",
                    "value": "minecraft:netherite_axe"
                }
            ]
        }
    }
}```
#

This event plays the sound when the shield is hit and tests for if the player that hit it has an axe in their hand

#

STEP 6 the remove event "block_done": { "remove": { // removes the component group "component_groups": [ "shielded" ] }, "queue_command": { "command": [ "tag @s remove blocking", // removes the tag from earlier and the slowness "effect @s slowness 0" ] } }

#

this is when the timer runs down. I have a separate event to run when the player breaks the shield because I wanted a sound to signify that

#

STEP 7 shield_broken event "shield_broken": { "trigger": { "event": "block_done" //triggers the previous event }, "queue_command": { "command": [ "playsound random.break @a ~ ~ ~ 1 0.7" // plays the breaking sound ] } }

primal cove
#

So is this the last step? And just asking will the entity still be able to attack?

sterile vector
#

FINAL STEP the last part of the environment sensor "minecraft:environment_sensor": { "triggers": [ { "filters": { "all_of": [ { "test": "any filters you want like distance to target or whatever" }, { "test": "has_target", "value": true }, { "test": "has_tag", "operator": "not", "value": "blocking" } ] }, "event": "start_block_random"//What we did before }, { "filters": { // this stops the blocking when the entity loses its target "all_of": [ { "test": "has_target", "value": false }, { "test": "has_tag", "value": "blocking" } ] }, "event": "block_done" } ] }

#

With all of these things we have made a trigger to run a 1/200 chance for this entity to run this behavior, we have defined the behavior and allows animations to be played, and we have created a balance of breaking the shield or the timer running out.

#

I will say. If your entity has any of the components in the component group such as minecraft:timer or minecraft:damage_sensor anywhere else, you will have to add them to a seperate component group that will be active when the entity is not blocking. If that is the case just make the group and remove it when it starts blocking and add it when it stops.

#

Wheeeew... that was probably overwhelming, but I hope it helped

#

Ask any questions if you need help

primal cove
primal cove
sterile vector