Posted January 7, 201312 yr Does anyone have an idea how i can get the distance from player to a specific block like placed torches? i tried "ModLoader.getMinecraftInstance().theWorld.getEntitiesWithinAABB" but it only works with entities like the name says xP... anyone knowing a good way? edit: on second page is a working solution
January 7, 201312 yr AxisAlignedBB var4 = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)this.xCoord, (double)this.yCoord, (double)this.zCoord, (double)(this.xCoord + 1), (double)(this.yCoord + 1), (double)(this.zCoord + 1)).expand(var1, var1, var1); List var5 = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, var4); Iterator var6 = var5.iterator(); EntityPlayer var7; while (var6.hasNext()) { var7 = (EntityPlayer)var6.next(); do stuff }
January 7, 201312 yr Author thanks! but i have a few questions.. ...this.xCoord... should this be the player position? or from the toch? is var1 the radius of the detection? Edit: and i dont want to use it in a new block i want to detect things that are already in the game..
January 7, 201312 yr oh i forgot this methods only works if the block has tile entity(because this must go in tile entity) also var1 is double var1 = (double)(4* 8 + ; this is from TileEntityBeacon
January 7, 201312 yr yea the xcord,ycord, and z cord are the block cords @Edit sorry for double post my ie9 its buggy
January 7, 201312 yr Author my problem is that i dont want to use it with new blocks i want to detect torches and things in vanilla...
January 7, 201312 yr Author hey like u can use world.setBlockTileEntity how do you mean that? i need the coordinates for the world.setBlockTileEntity...
January 7, 201312 yr in what method you are trying to get that?, in tickhandler?, in other block class?
January 7, 201312 yr this will return a list of colliding boxes AxisAlignedBB var4 = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)player.posX + how blocks u want(double)player.posY + how blocks u want(double)player.posZ + how blocks u want(double)(player.posX + 1), (double)(player.posY + 1), (double)(player.posZ + 1)); List list = Minecraft.getMinecraft().theWorld.getAllCollidingBoundingBoxes(var4);
January 7, 201312 yr Author but how do i use that to compare if its a specific block like a torch etc...? sry for the many questions...^^
January 7, 201312 yr Author list.equals(string) ok i tried this: AxisAlignedBB var4 = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)plX + 10,(double)plY + 10,(double)plZ + 10,(double)(plX + 1), (double)(plY + 1), (double)(plZ + 1)); List list = Minecraft.getMinecraft().theWorld.getAllCollidingBoundingBoxes(var4); Iterator var6 = list.iterator(); EntityPlayer var7; if(list.equals("50")) while (var6.hasNext()) { System.out.println("got one torch!"); var7 = (EntityPlayer)var6.next(); } but the list is empty xP
January 7, 201312 yr Author System.out.println(list); see what u get on console ok now i got the coordinates in the list like: [iNFO] [sTDOUT] [box[-295.0, 68.0, 277.0 -> -294.0, 69.0, 278.0], box[-295.0, 69.0, 277.0 -> -294.0, 70.0, 278.0], box[-295.0, 70.0, 277.0 -> -294.0, 71.0, 278.0], box[-295.0, 68.0, 278.0 -> -294.0, 69.0, 279.0],...] but how do i go through this with a block specific comparison? ^^ complete code: [hide] AxisAlignedBB var4 = AxisAlignedBB.getBoundingBox(plX, plY, plZ, plX + 1.0D, plY + 1.0D, plZ + 1.0D).expand(4D, 2D, 4D); List list = Minecraft.getMinecraft().theWorld.getAllCollidingBoundingBoxes(var4); Iterator var6 = list.iterator(); EntityPlayer var7; if(list.equals("50")) while (var6.hasNext()) { System.out.println("got one torch!"); var7 = (EntityPlayer)var6.next(); } System.out.println(list); [/hide]
January 7, 201312 yr Author String ing = list.toString(); System.out.println(ing); do you mean i have to write a function which goes through the string; takes the specific coordinates; compares them if they are torches; and gives a return statement? because the " System.out.println(ing);" output is the same...
January 7, 201312 yr Author do you have skype or something?, to talk better yes but i cant talk anymore girlfriend is asleep... i mean this comparison if the torch block is in the list is the last thing i have to find out...^^
January 7, 201312 yr Author sorry, torch dosent have aabb so change if(list.equals("50")) to if(!list) if(!list) is red underlined i took if(list != null)... but the game crashes in the while at: var7 = (EntityPlayer)var6.next(); edit: nevermind saw my bug^^ AxisAlignedBB var4 = AxisAlignedBB.getBoundingBox(plX, plY, plZ, plX + 1.0D, plY + 1.0D, plZ + 1.0D).expand(4D, 2D, 4D); List list = Minecraft.getMinecraft().theWorld.getAllCollidingBoundingBoxes(var4); Iterator var6 = list.iterator(); EntityPlayer var7; if(list != null) while (var6.hasNext()) { var7 = (EntityPlayer)var6.next(); } String ing = list.toString(); System.out.println(ing);
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.