Sjele Posted July 13, 2013 Share Posted July 13, 2013 I am trying to make a sort of shield type thing, that will kill all the closest hostile mobs within a 5 block circle. To do this I think i need to get the closet entity and then kill it, but how would i go about and find all or just the closest hostile entity within a 5 radius circle? Thanks in advance Quote Link to comment Share on other sites More sharing options...
Mazetar Posted July 13, 2013 Share Posted July 13, 2013 I guess you could look at the worldObj's loadedEntityList and search trough their positions to see if they are within the area and then do whatever you want with them? There may be better ways of course, but I guess that's ONE way to do it Quote If you guys dont get it.. then well ya.. try harder... Link to comment Share on other sites More sharing options...
Chibill Posted July 13, 2013 Share Posted July 13, 2013 You could get the positions and subtract the position of the player for there's and then see it they are less than 5 but not smaller then 0. Quote Link to comment Share on other sites More sharing options...
Guff Posted July 13, 2013 Share Posted July 13, 2013 To find all of the hostile mobs within 5 blocks, List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(player, player.boundingBox.expand(5.0D, 5.0D, 5.0D)); and then run through those and see which ones are hostile via instanceof. Then, if they are, entity.setDead(). 1 Quote Link to comment Share on other sites More sharing options...
Mazetar Posted July 13, 2013 Share Posted July 13, 2013 To find all of the hostile mobs within 5 blocks, List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(player, player.boundingBox.expand(5.0D, 5.0D, 5.0D)); and then run through those and see which ones are hostile via instanceof. Then, if they are, entity.setDead(). That's probably the most efficient answer! It's the one I would have used, so try it and thank the man Quote If you guys dont get it.. then well ya.. try harder... Link to comment Share on other sites More sharing options...
Sjele Posted July 13, 2013 Author Share Posted July 13, 2013 To find all of the hostile mobs within 5 blocks, List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(player, player.boundingBox.expand(5.0D, 5.0D, 5.0D)); and then run through those and see which ones are hostile via instanceof. Then, if they are, entity.setDead(). Thanks but I think i did not make this clear, it's a block and not around the player. Sorry. Quote Link to comment Share on other sites More sharing options...
Mazetar Posted July 13, 2013 Share Posted July 13, 2013 Then use the same principle just around the block instead of a player then? Quote If you guys dont get it.. then well ya.. try harder... Link to comment Share on other sites More sharing options...
Guff Posted July 14, 2013 Share Posted July 14, 2013 Thanks but I think i did not make this clear, it's a block and not around the player. Sorry. Assuming you have the block's coordinates i, j, k: AxisAlignedBB aabb = AxisAlignedBB.getBoundingBoxFromPool(i - 5, j - 5, k - 5, i + 5, j + 5, k + 5); Then just use the same thing I showed you before. Quote Link to comment Share on other sites More sharing options...
Sjele Posted July 14, 2013 Author Share Posted July 14, 2013 Thanks but I think i did not make this clear, it's a block and not around the player. Sorry. Assuming you have the block's coordinates i, j, k: AxisAlignedBB aabb = AxisAlignedBB.getBoundingBoxFromPool(i - 5, j - 5, k - 5, i + 5, j + 5, k + 5); Then just use the same thing I showed you before. I need to tick the block to check if there are any near by mobs, i read somewhere i should use a tile entity for this? Should i do that or should i use the built in methods in Block class? Quote Link to comment Share on other sites More sharing options...
Guff Posted July 14, 2013 Share Posted July 14, 2013 Use a Tile Entity, since they are updated every tick. Block's randomDisplayTick() is not ideal since it is just that; random. Quote Link to comment Share on other sites More sharing options...
Sjele Posted July 14, 2013 Author Share Posted July 14, 2013 Thank you so much! Now I just need to read up on how to use tile entites, I'll spend some time reading, if i can't get it working i'll ask again , thanks Quote Link to comment Share on other sites More sharing options...
Guff Posted July 14, 2013 Share Posted July 14, 2013 You're welcome. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.