Counting Mobs In A Small Area. - MCreator
Maybe your like
Topic category: Help with Minecraft modding (Java Edition)
For my mod, I need a procedure that counts mobs..
---------------------------------------------------------------------
Example: If there are 5 mobs nearby --> /say hi
---------------------------------------------------------------------
I know you can do it with /scoreboard command, but this procedure is made for entitys, so adding scoreboards for each mob is very frustrating...
---------------------------------------------------------------------
Please help! I will be very thankful to people, who can answer this hard question.
---------------------------------------------------------------------
Jump to top Edited by CodeLovingBison on Sat, 04/24/2021 - 11:07this isn't really hard to make in MCreator since 2020.5, which introduced the entity iterator in a procedure and makes this task easier! so here's how you can do it:
- make the procedure and add a local number variable called "mob_count" or something similar (set its initial value to 0)
- drop a "for each entity as [entity iterator] at x y z in square cube with size [n]" procedure, where "n" should be equal to the length & width (in blocks) of cube you want the procedure to detect. then, add "if (not entity iterator = event/target entity) do (set [local:mob_count] to [get local:mob_count + 1])" under it. we want the variable to increase by 1 everytime a nearby entity is detected, but we don't want the procedure to also detect the mob who's using it (player in this case) to prevent miscounting
- finally, add an if-else procedure, with 2 else-ifs, that will count the mob_count variable and see what its value is in the condition, and send a message to the player depending on the number of detected mobs based on the variable. it will look like this:

you can download the procedure at https://www.mediafire.com/file/r5787t3yh71tz1d/mob_counter.ptpl/file and import it in MCreator.
and that's all! :D
Jump to top Permalink- Log in or register to post comments
one small issue though: it sends a decimal (double) in the message instead of a whole number (integer), so something like 7 mobs around you would send "7.0" instead of just "7", which looks ugly (we're obviously counting mobs, so it's clear to use only whole numbers). but it's actually quite easy to fix by editing the code.
first, find where the local variable is declared. you will see that it looks like "double mob_count = 0", and in the next line is "mob_count = (double) 0". we don't want a double variable type, since it's a decimal number. so remove the line "mob_count = (double) 0;" and change "double" to "int".
after that, go find
for (Entity entityiterator : _entfound) { if ((!(entityiterator == entity))) { mob_count = (double) ((mob_count) + 1); } }and remove "(double)".
Jump to top Permalink- Log in or register to post comments
Example:
Every player tick update, the variable mob_count is getting increased by 1 for each entity at XYZ in cube² with size 16. As long as mob_count is => 5, your fall distance is getting overridden with 0 blocks for the next tick, which means, you'll not being able to get any fall damage the next tick.
Jump to top Permalink- Log in or register to post comments
Here's the picture.
Jump to top Permalink- Log in or register to post comments
O my god, thank you so much!
I can't thank you guys enough!!!
Jump to top Permalink- Log in or register to post comments
NOW MY DREAMS WILL COME TRUE!
Jump to top Permalink- Log in or register to post comments
haha, that's good to hear! go wild with what you can do under different conditions, there are so many possibilities with it by adapting the procedure! :)
Jump to top Permalink- Log in or register to post comments
Sorry for me being so annoying, but what do you think of my mod? (You can see it in my icon)
Its my first mod, and im really proud of it.
It even has dino stampedes!
Jump to top Permalink- Log in or register to post comments
I tried applying the same code but for nbt virables (since this procedure is made for entitys).
-------------------------------------------------------
Example: if there is an entity(of type) next to 5 custom_entitys, "say hi"
-------------------------------------------------------
And when I spawn a single entity(of type), (even tho, it needs to be more than one!)
next to my custom_entity, it executes the code "say hi" for every tick without stopping, unless you get out of range.
-------------------------------------------------------
Conclusion: 1. Executes the code without five entitys..
2.Executes the code for every tick (more than one time)..
-------------------------------------------------------
Here's the code: https://ibb.co/Mh3x4cY
-------------------------------------------------------
TRUST ME, ITS IMPORTANT!
-------------------------------------------------------
Jump to top Permalink- Log in or register to post comments
The code was written "On Entity Tick Update" of my custom entity...
Jump to top Permalink- Log in or register to post comments
Can I see your Mod a bit more nearly? Is it uploaded somewhere? Cus than I can say more about it. But the Dino in your icon looks cool!
Jump to top Permalink- Log in or register to post comments
The mod is currently is not released. Will be released (not soon). And thanks for asking!
If you want to see, I have some spoilers of the upcoming mobs wich live in the new cave biomes..
Morganocudon: (lives in big colony's underground): https://ibb.co/DVBrJy0
Gue Lizard: (A small lizard, wich lives in the new "Gue Caves" Gue in the caves.. Well call it sculks older brother.): https://ibb.co/20zKr4V
Jump to top Permalink- Log in or register to post comments
Related forum topics
0Does anybody know why my loot table isnt working Last update 1 day 11 hours ago 6The inventory function inside the item does not work. Last update 3 weeks 2 days ago 4"Did you forget to update the mod id in the entrypoint?" error Last update 1 month 1 week ago 2How to make a custom model WITH an animated texture ? Last update 4 weeks 1 day ago 2How would I make my custom blocks break when one of them breaks if they are touching Last update 1 month 1 week ago 2Shield doesn't block status effects (2025.3) Last update 6 days 21 hours agoRecent forum topics
0generate blocks like cocoa beans Last update 3 seconds ago 0Armour removed trigger Last update 3 seconds ago 0The funny mod Last update 1 second ago 2how do i copy and paste code for different mods Last update 6 hours 48 minutes ago 0Mod worked on for years totally wiped. Is there any way to recover? Last update 7 hours 7 minutes ago 0Problem loading Gradle for MCreator Last update 7 hours 6 minutes ago 0Need help with head movement and animations not syncing with the secondary model Last update 8 hours 56 minutes agoMod of the week
Better Tools and ArmorSubmit your mod now
Tag » How To Count Entities In Minecraft
-
How To Count Entities With Commands/check If There Are Only One Or A ...
-
How To Count Players/mobs In Minecraft - YouTube
-
How To Count Entities In A Given Area [1.14]? - Minecraft: Java Edition
-
How To Use Commands To Count The Number Of Mobs? - Reddit
-
Block/entity/ Player Count Command - Minecraft Feedback
-
Count Entities And Add To Scoreboard - Planet Minecraft
-
Minecraft Count Entities ~ Arqade
-
Entity - Minecraft Wiki - Fandom
-
Entity Count | SpigotMC - High Performance Minecraft - Spigot
-
Minecraft Entity List (Java Edition 1.19) - DigMinecraft
-
Useful Guide For Minecraft Bedrock Commands And MCFunction
-
Mob And Entity Counter (No Command Block Needed) - MCPEDL
-
[1.16.5] Count Entities For Exporting - Modder Support - Forge Forums
-
10 Cool Minecraft Console Commands For 2022 | HP® Tech Takes