Jump to content

[1.7.2] Add potion effect to player if he's within certain distance from a block


Recommended Posts

Posted

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

Posted

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));

Posted

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.

Posted

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.