Ever since I started playing minecraft there's always been one thing bothering me: why do mobs only attack the player? Shouldn't they attack each other and wild animals too? Well I got to talking with some friends earlier today about it and I decided to take a crack at it. Well it's almost 4am and I still can't get it working the right way.
I found the right method in EntityMob.java, findPlayerToAttack gets the closest player within 16 blocks and attacks it. In order to find the closest player, it calls the getClosestPlayerToEntity method from World.java. All I had to do was write a new method that would return the closest Entity that the mob should attack instead of just players, this is what I came up with
It isn't the easiest thing to read since it comes from a deobfuscator and I copypasta'd it from getClosestPlayer, but basically it picks the entity closest to the mob by looking at the list returned by getEntitiesWithinAABB. (Note: it also ignores entities less than 1 away. Funny story, I had creepers blowing up the instant they spawned and skeletons shooting at their own feet trying to kill themselves before I fixed this)
With these changes, minecraft compiles and runs. But the performance is TERRIBLE. Frame rates start normal and quickly deteriorate to sub 1fps. CPU usage is normal if not a tad high (12% on an i7) but it memory leaks like a boss, 700Mb after a minute or two. Also the F3 debug stuff shows the item count skyrocketing into the tens of thousands and I can't find out why.
It's probably because if it is actually a fully working code, it is causing every hostile mob to attack things all at once, in every cave, every dungeon, and every dark area, in the 30-40 chunk area.
It's probably because if it is actually a fully working code, it is causing every hostile mob to attack things all at once, in every cave, every dungeon, and every dark area, in the 30-40 chunk area.
Once a mob has a target, it will stop checking for new ones until its target is out of range or dead.
Mobs do fight each other. It's a matter of getting them to hit each other first. If you can manage to get a skeleton to shoot a monster between you and him, then the monster that got hit will attack the skeleton. You have to use monsters as shields, in other words.
Mobs do fight each other. It's a matter of getting them to hit each other first. If you can manage to get a skeleton to shoot a monster between you and him, then the monster that got hit will attack the skeleton. You have to use monsters as shields, in other words.
Did you read my post? I'm changing the code in minecraft so that they will actually attack other creatures and asking for help with it. I think the final result will be simple but cool to watch. Last night I saw two skeletons attack a cow together, then proceeded to fight each other, but a creeper came in and blew them all up. It was pretty entertaining to watch!
Did you read my post? I'm changing the code in minecraft so that they will actually attack other creatures and asking for help with it. I think the final result will be simple but cool to watch. Last night I saw two skeletons attack a cow together, then proceeded to fight each other, but a creeper came in and blew them all up. It was pretty entertaining to watch!
can u give me a guide how /or make a mod? Would be awesome! looking for something like that for a good time
I found the right method in EntityMob.java, findPlayerToAttack gets the closest player within 16 blocks and attacks it. In order to find the closest player, it calls the getClosestPlayerToEntity method from World.java. All I had to do was write a new method that would return the closest Entity that the mob should attack instead of just players, this is what I came up with
It isn't the easiest thing to read since it comes from a deobfuscator and I copypasta'd it from getClosestPlayer, but basically it picks the entity closest to the mob by looking at the list returned by getEntitiesWithinAABB. (Note: it also ignores entities less than 1 away. Funny story, I had creepers blowing up the instant they spawned and skeletons shooting at their own feet trying to kill themselves before I fixed this)
With these changes, minecraft compiles and runs. But the performance is TERRIBLE. Frame rates start normal and quickly deteriorate to sub 1fps. CPU usage is normal if not a tad high (12% on an i7) but it memory leaks like a boss, 700Mb after a minute or two. Also the F3 debug stuff shows the item count skyrocketing into the tens of thousands and I can't find out why.
Anyone here have any idea what's going on?
Once a mob has a target, it will stop checking for new ones until its target is out of range or dead.
Nope.
Did you read my post? I'm changing the code in minecraft so that they will actually attack other creatures and asking for help with it. I think the final result will be simple but cool to watch. Last night I saw two skeletons attack a cow together, then proceeded to fight each other, but a creeper came in and blew them all up. It was pretty entertaining to watch!
i just learned this today so i am not 100% sure.