Posted March 27, 201312 yr Hey everyone, I'm currently in the middle of making a Mod called Omega Craft, a technical mod which I decided to make so that I can learn how to mod first hand. Now one of the blocks that I am making needs to know where the current position of the nearest mob is in a certain radius, I've tried a few things but nothing has worked so far. Now for example would anyone know how to find out if there is a creeper in a radius of 18 blocks of the block you place down? Any help will be hugely appreciated.
March 27, 201312 yr Step 1:Make an axis aligned BB Step 2:Make a list with it (it should have a method to convert it to a list) Step 3:Make an iterator of that list Ex Iterator iter = list.iterator Step 4:Do this while(iter.hasNext()){ if(iter.next() instanceof EntityCreeper){ EntityCreeper ent = (EntityCreeper)iter.next(); //do whatever you want to do with this entitycreeper } } You are now educated "you seem to be THE best modder I've seen imo." ~spynathan ლ(́◉◞౪◟◉‵ლ
March 28, 201312 yr Okay I forgot 1 thing, to get the list do world.getEtitiesWithinAABB(AABB, Entity.class) "you seem to be THE best modder I've seen imo." ~spynathan ლ(́◉◞౪◟◉‵ლ
March 28, 201312 yr Author How do you set the bounding box correctly? [embed=425,349] public double expand(double par1, double par3, double par5)[/embed]
March 29, 201312 yr AxisAlignedBB bb = new AxisAlignedBB(minx, miny, minz, maxx, maxy, maxz); "you seem to be THE best modder I've seen imo." ~spynathan ლ(́◉◞౪◟◉‵ლ
March 29, 201312 yr AxisAlignedBB bb = new AxisAlignedBB(minx, miny, minz, maxx, maxy, maxz); Wrong. The constructor of the AxisAlignedBB is protected. The correct call would be AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(minx, miny, minz, maxx, maxy, maxz); Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
March 29, 201312 yr Author So pretty much this: protected AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(1, 1, 1, 16, 16, 16);
April 12, 201312 yr Author After trailing and erroring, then finally giving up on this. I have decided to see it though, the biggest problem I had with making this work was, making it to list all the mobs nearby. How would I go about making an iterator to do this?
April 13, 201312 yr So pretty much this: protected AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(1, 1, 1, 16, 16, 16); hm, I will give you some code to get a List of all entities: First make a right AABB: AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(this.posX - 16, this.posY, this.posZ - 16, this.posX + 16, this.posY + 16, this.posZ + 16); 'this' is the entity instance which you want to be at the center (for example the player if you wanna check if there are entities around it) Next thing you do is to get a list of entities inside that bounding box. You have two possibillities: List<EntityCreeper> entities = worldObj.getEntitiesWithinAABB(EntityCreeper.class, bb); This will give you all entities which classes are equal to or are extending the class given (here you will get all entities which have EntityCreeper as a class or extend this class). This works also for interfaces (for example if you use IMob.class as parameter, it'll give you all entities which implement IMob, like Creepers, Zombies, Slimes etc). List entities = worldObj.getEntitiesWithinAABBExcludingEntity(EntityPlayer.class, bb); This will give you all entities (also paintings, arrows, fireballs etc.), so you have to check what entity it is when you iterate over the list. The class parameter in this will determine which entities won't be recognized, here the EntityPlayer. As above the rule is: Each entity which it's class is equal, extending or implementing the parameter class, will be excluded from the list. Now the rest you have to figure out yourself. If you have any questions or errors, post them. Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
April 13, 201312 yr Author The only error that I have got to far is that "worldObj" does not exist. I'm using 1.5.1 Forge.
April 13, 201312 yr The only error that I have got to far is that "worldObj" does not exist. I'm using 1.5.1 Forge. where do you want to use your code? Can I see what you've got so far? Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
April 13, 201312 yr Author private int blockposX = 0; private int blockposY = 0; private int blockposZ = 0; private Entity entities; private String texturePath; private AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(this.blockposX - 16, this.blockposY, this.blockposZ - 16, this.blockposX + 16, this.blockposY + 16, this.blockposZ + 16); public CreeperDetector(int par1, int par2, Material par3Material, String par4Str, String par5Str) { super(par1, par3Material); this.texturePath = par4Str; } public static void GetEntitys(){ List<EntityCreeper> entities = worldObj.getEntitiesWithinAABB(EntityCreeper.class, bb); while(entities != null){ if(((EntityCreeper) entities) instanceof EntityCreeper){ EntityCreeper ent = (EntityCreeper)entities; EntityWithinRadius(); } } } Basically when the block is finished the block will have two modes, defense which pushing the mob out of the radius and redstone which emits a redstone signal when a mob is in the radius.
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.