Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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

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

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.

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.