I want to test a mob farm I'm making, and can't currently install things like carpet mod, I tried using:
execute
if @e[type=zombified_piglin]
positioned x y z
run give @s diorite 1
on a repeating command block, but it just gave me diorite even if it was not in the right position. I also think that this command probably wouldn't work for a farm because not every entity would be at the specified block at any given time.
Best Answer
You could use a dummy scoreboard to count the amount.
Then add a player or an invaluable armor stand with a custom name like Zombified Pinglings.
or
You can then display the score on the screen with:
Then using the x y z and dx dy dz in the target selector:
You can specify a cube/rectangle area.
Then set up a repeating command block followed by 2 chain command blocks with the code. This block finds any zombified piglings in the area of 40 56 -1 with a distance of up to 2 blocks, and then adds a tag to the entity:
2:nd block; executes all enteties that got the last tag and adds a point to the dummy scoreboard that was set up earlier:
The last block; adds an additional tag to the entity so that the previous blocks don't add more than 1 point to the score:
This will make sure the counter only goes up by 1 for every unique entity. If this will be used at a mob farm, you could specify the whole spawn area and the mobs would get counted when they spawn. And naming an invaluable armor stand different mob names you could count any mob separately. Remember that if the armor stand/player that the dummy scoreboard is added to would die the score would reset, i.e. the score will set to null.
If you want to specify a cube/rectangle area remove
distance=...
and adddx=...,dy=...,dz=...
If you want to use the 'give diorite' system you could replace the scoreboard part
scoreboard players add SemlanBakelsen Counter 1
withgive SemlanBakelsen minecraft:diorite 1
, of course replacing my name with whoever should get the item.This site can be useful for custom armor stands: https://haselkern.com/Minecraft-ArmorStand/