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.

Featured Replies

Posted

Hi everyone im trying to make a grenade that blinds entities in the are but

i mess with codes somehow but no luck it dont work

 

package MHF.Net.Client.Entity.Projectile;


import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import MHF.Net.Client.Item.MHFItem;

public class MHFEntityGrenadeIncenerate extends MHFEntityBombMaterial
{
    protected String BOUNCE_SOUND;
    
    static final double MAX_DISTANCE = 32D;
    static final double MIN_DISTANCE = 8D;
    static final float MAX_ANGLE = 180F;
    static final float MIN_PITCH_ANGLE = 15F;
    static final float MIN_YAW_ANGLE = 15F;
    public static final int MAX_FLASH_TIME_PLAYER = 500;
    public static final int MAX_FLASH_TIME_ENTITY = 200;

    public MHFEntityGrenadeIncenerate(World world)
    {
        super(world);
        setEntityItemStack(new ItemStack(MHFItem.MHFIncenerateBomb, 1, 0));
    }

    public MHFEntityGrenadeIncenerate(World world, double d, double d1, double d2)
    {
        super(world, d, d1, d2);
        setEntityItemStack(new ItemStack(MHFItem.MHFIncenerateBomb, 1, 0));
    }

    public MHFEntityGrenadeIncenerate(World world, EntityLivingBase entityliving)
    {
        super(world, entityliving);
        setEntityItemStack(new ItemStack(MHFItem.MHFIncenerateBomb, 1, 0));
    }

    public void onUpdate()
    {
        super.onUpdate();
        List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox);

        if (list.size() > 0)
        {
            Entity entity = (Entity)list.get(0);

            if (entity instanceof EntityLiving)
            {
            	((EntityLiving) entity).addPotionEffect((new PotionEffect(Potion.blindness.id, 100, 6)));
                entity.setFire(300);
                explode();
            }
        }
    }

    protected void handleBounce()
    {
        explode();
    }

    protected void explode()
    {
        if (!exploded)
        {
            exploded = true;
            worldObj.playSoundAtEntity(this, Block.glass.stepSound.getBreakSound(), (Block.glass.stepSound.getVolume() + 1.0F) / 2.0F, Block.glass.stepSound.getPitch() * 0.8F);
            int i = (int)Math.floor(posX);
            int j = (int)Math.floor(posY);
            int k = (int)Math.floor(posZ);

            for (int l = -2; l <= 2; l++)
            {
                for (int i1 = -2; i1 <= 2; i1++)
                {
                    for (int j1 = -2; j1 <= 2; j1++)
                    {
                        int k1 = Math.abs(l) + Math.abs(i1) + Math.abs(j1);

                        if (k1 <= 2 && worldObj.isAirBlock(i + l, j + i1, k + j1))
                        {
                            worldObj.setBlock(i + l, j + i1, k + j1, Block.fire.blockID);
                        }
                    }
                }
            }

            setDead();
        }
    }
}



Hi

 

I'm having a bit of trouble seeing how your code is supposed to work.

As far as I can tell, you use onUpdate to see if any living entities touch the grenade (collide with the boundingbox), and when they do, apply a blindness effect and explode the grenade.

 

Is that what you intended?  And if so, what doesn't work?

 

-TGG

  • Author

So you mean that my boundingBox is whenever the entity touched the grenade that is thrown ?

 

Im kinda confuse a little but what i want is when the grenade is thrown all entities in the area that seen the grenade will be blind

boundingBox is set by Entity#setSize(...).

I assume you don't want your grenade to be bigger, so I'd recommend using AxisAlignedBB#expand(double,double,double) on boundingBox.

By the way, EntityPlayer is not an EntityLiving in recent Minecraft versions, you may want to check for EntityLivingBase instead.

You will probably need a counter too, to avoid the grenade exploding in the player hands.

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.