Posted May 11, 201411 yr I want to add a potion effect to to a player, if the player is near a block (10 square blocks for example), and remove it if the player goes away. Basically somethink like the beacon does, but i've not found anything
May 11, 201411 yr Try looking at the beacon code then. If all else fails use getEntityWithinAABB (and other methods)
May 11, 201411 yr Author Try looking at the beacon code then. If all else fails use getEntityWithinAABB (and other methods) Will this return a list of the players within 5 blocks from my custom one? double range = 5.0; List list = world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x - range, y - range, z - range, x + range, y + range, z + range));
May 11, 201411 yr Will this return a list of the players within 5 blocks from my custom one? double range = 5.0; List list = world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x - range, y - range, z - range, x + range, y + range, z + range)); No, It will return a list of the entities in 11*11*11 Box surrounding the block. If you want to get the lists of the entities in 10 block-distance, You have to check for each entity if the squared distance is smaller than 10*10. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
May 12, 201411 yr Author I have a problem with this code: public void updateEntity() { super.updateEntity(); float f = 5.0F; double minX = (float)this.xCoord - f; double minY = this.yCoord - f; double minZ = this.zCoord - f; double maxX = (this.xCoord + 1) + f; double maxY = (this.yCoord + 1) + f; double maxZ = (this.zCoord + 1) + f; List list = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getAABBPool().getAABB(minX, minY, minZ, maxX, maxY, maxZ)); if(list.size() != 0) { for(int i = 0; i < list.size(); ++i) { EntityPlayer entityPlayer = (EntityPlayer) list.get(i); entityPlayer.addPotionEffect(new PotionEffect(10, 2, 0, false)); } } If the player is nearer then 5 block from my custom one, the he gets a potion effect, but when he goes away more than 5 block, he still has the potion effect. How can i remove it if the player goes away?
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.