Counting Mobs In a Small Area.

Started by CodeLovingBison on

Topic category: Help with Minecraft modding (Java Edition)

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Counting Mobs In a Small Area.
Sat, 04/24/2021 - 11:07 (edited)

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.

---------------------------------------------------------------------

Edited by CodeLovingBison on Sat, 04/24/2021 - 11:07
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
this isn't really hard to…
Mon, 04/26/2021 - 09:27

this 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:

  1. make the procedure and add a local number variable called "mob_count" or something similar (set its initial value to 0)
  2. 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
  3. 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:

https://i.imgur.com/kfUmbUc.png

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

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
one small issue though: it…
Mon, 04/26/2021 - 09:40

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)".

Joined Oct 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
  Example: Every player tick…
Mon, 04/26/2021 - 10:47

MCreator 2021.1 Procedure Example no.0001

 

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.

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
O my god, thank you so much!…
Mon, 04/26/2021 - 11:23

O my god, thank you so much!

I can't thank you guys enough!!!

 

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
NOW MY DREAMS WILL COME TRUE…
Mon, 04/26/2021 - 11:24

NOW MY DREAMS WILL COME TRUE!

 

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
haha, that's good to hear!…
Mon, 04/26/2021 - 11:31

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! :)

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sorry for me being so…
Mon, 04/26/2021 - 12:19

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!

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I tried applying the same…
Mon, 04/26/2021 - 21:47

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!

-------------------------------------------------------

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The code was written "On…
Tue, 04/27/2021 - 08:09

The code was written "On Entity Tick Update" of my custom entity...

 

Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can I see your Mod a bit…
Wed, 05/12/2021 - 09:38

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!

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The mod is currently is not…
Sat, 05/29/2021 - 20:01

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