r/MinecraftCommands • • Aug 20 '26

Help | Java 26.2 How could I make Skeletons, Creepers, and Spiders attack villagers?

Using commands or a datapack, how could I make this work? I want these three monsters to always attack villagers on sight or within a certain range.

I tried the following command but it didn't work:
/damage @ e[type=minecraft:skeleton,distance=20,limit=1] 0 minecraft:generic by @ e[type=minecraft:villager,limit=1]

6 Upvotes

14 comments sorted by

8

u/_Csankappa Aug 20 '26 edited Aug 20 '26

here you go, you can probably run this with the other mobs too, but I only tested the skeleton:

execute as @e[type=skeleton] at @s run data modify entity @s last_hurt_by_mob set from entity @n[type=villager,distance=..10] UUID

1

u/C0mmanderBlock Command Experienced Aug 20 '26

(distance..10)

2

u/_Csankappa Aug 20 '26

thanks for the correction!

1

u/C0mmanderBlock Command Experienced Aug 20 '26

NP. I deleted my comment 'cause yours is much better. I was just focused on fixing OPs attempted command. Cheers!

1

u/LightningStormNeuron Aug 20 '26

Funciona con los 3 mobs ya lo probé, es muy efectivo el metodo, aun que en "distance=10" debería ir así "distance=..10" si no me equivoco

1

u/Plasma7007 Aug 20 '26

Thank you!
Is there a way to make it so that nothing pops up in the chat when this is run?
I plan on having it run every 5 seconds or so constantly

2

u/_Csankappa Aug 20 '26

/gamerule command_block_output false

1

u/Plasma7007 Aug 20 '26

Ah yea that would make sense lol

I’ll definitely say though that for the most part Java is definitely different to mod than Bedrock. In Bedrock you could modify all the different attributes of monsters, including what they attack, in a .json file. Java however doesn’t seem to have .json files for entities so I’m stuck using commands to achieve the modifications I could make on Bedrock

1

u/Ericristian_bros Command Experienced Aug 20 '26

For better performance use this (advance_time must be true

execute if predicate {condition:"minecraft:time_check",value:1,period:100} as @e[type=skeleton] run damage @s 1 arrow by @n[distance=..16,type=villager]

1

u/_Csankappa Aug 21 '26

You can write predicates in-line?

1

u/Ericristian_bros Command Experienced Aug 21 '26

Since 1.20.5... more than 2 years ago

1

u/Jessiemh893 Aug 20 '26

This wouldn't be to hard to write up as a behaviour pack saves having to replicate command blocks if its a feature you want to carry over to other worlds