#(Solved!)How to make entities block (with or without shield), what component do I need to add?
1 messages · Page 1 of 1 (latest)
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.
I'm new, but I do understand the concept of environment_sensor, but I wasn't able to make it work, and also in Events I am just starting out
But I did get events to work
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
I am trying to make it block when a there is a incomming attack, but random blocking will be ok
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
Thanks
Also
Just wondering, can I replace it with ressistance instead of a timer or is it realy needed?
Not needed because of the damage sensor
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 ] } }
So is this the last step? And just asking will the entity still be able to attack?
one more step and yes. it will still move around like normal and attack the player with melee or delayed attack whichever you use
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
Thanks mate, I will try this out, this is a big help))
THANK YOU IT WORKS!!!
I've been trying to make them to be able to block for months and finaly they can, I also found out my environment sensor wasn't working because I used format version 1.10.0 instead of higher ones, your help made me fix a problem I had before plus this ability to block, from the bottom of my heart Thank You!!! May God bless you man))
LETS GOOOO!! Anytime... I so wish I would have found this server sooner because I was at one point stumbling around in the dark without help trying to teach myself via documentation, but sometimes it is nice to talk to a real person.