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

I finally made a throw-able explosion, but i have 2 issues:

1.when it explodes it will explode again 1 second later

2.The entity visually stays in the world and you can't get rid of it, not even exiting and reloading the world works.

 

EntityBomb.class:

ackage dudesmods.lozmod;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class EntityBomb extends EntityItem
{

    public EntityBomb(World world)
    {
        super(world);
        setSize(0.5F, 0.5F);
        yOffset = height / 2.0F;
        bounceFactor = 0.6;
        exploded = false;
        stopped = false;
        fuse = 100;
    }
    public EntityBomb(World world, double x, double y, double z, float yaw, float pitch, double force, int fuseLength)
    {
        this(world);

       setRotation(yaw, 0);
       double xHeading = -MathHelper.sin((yaw * 3.141593F) / 180F);
       double zHeading = MathHelper.cos((yaw * 3.141593F) / 180F);
        motionX = force*xHeading*MathHelper.cos((pitch / 180F) * 3.141593F);
        motionY = -force*MathHelper.sin((pitch / 180F) * 3.141593F);
        motionZ = force*zHeading*MathHelper.cos((pitch / 180F) * 3.141593F);

        setPosition(x+xHeading*0.8, y, z+zHeading*0.;
        prevPosX = posX;
        prevPosY = posY;
        prevPosZ = posZ;

        fuse = fuseLength;
    }
    public EntityBomb(World world, Entity entity)
    {
        this(world, entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch, 0.5, 50);
    }
    
    protected boolean canTriggerWalking()
    {
        return false;
    }

    public void onUpdate()
    {
        if(fuse-- <= 0)
        {
            explode();
        }
        if(!(stopped) && !(exploded))
        {
           double prevVelX = motionX;
          double prevVelY = motionY;
          double prevVelZ = motionZ;
           prevPosX = posX;
           prevPosY = posY;
           prevPosZ = posZ;
           moveEntity(motionX, motionY, motionZ);
    
           boolean collided = false;
         
           if(motionX!=prevVelX)
           {
              motionX = -prevVelX;
              collided = true;
           }
           if(motionZ!=prevVelZ)
           {
              motionZ = -prevVelZ;
           }
    
           if(motionY!=prevVelY)
           {
              motionY = -prevVelY;
              collided = true;
           }
           else
           {
              motionY -= 0.04;
           }
    
           if(collided)
           {
              motionX *= bounceFactor;
              motionY *= bounceFactor;
              motionZ *= bounceFactor;
           }
    
           motionX *= 0.99;
           motionY *= 0.99;
           motionZ *= 0.99;
           if(onGround && (motionX*motionX+motionY*motionY+motionZ*motionZ)<0.02)
           {
              stopped = true;
              motionX = 0;
              motionY = 0;
              motionZ = 0;
           }
        }
    }
    public void onCollideWithPlayer(EntityPlayer entityplayer)
    {
   
    }
    protected void explode()
    {
       if(!exploded)
       {
          exploded = true;
           worldObj.createExplosion(this, posX, posY, posZ, 5F, true);
       }
    }

    public boolean attackEntity(Entity entity, int i)
    {
       super.attackEntityFrom(DamageSource.causeThrownDamage(entity, entity), i);
       explode();
       return false;
    }
    public void writeEntityToNBT(NBTTagCompound nbttagcompound)
    {
       super.writeEntityToNBT(nbttagcompound);
        nbttagcompound.setByte("Fuse", (byte)fuse);
    }

    public void readEntityFromNBT(NBTTagCompound nbttagcompound)
    {
       super.readEntityFromNBT(nbttagcompound);
        fuse = nbttagcompound.getByte("Fuse");
    }
    double bounceFactor;
    int fuse;
    boolean exploded;
    boolean collided;
    boolean stopped;
    
    public ItemStack getEntityItem()
    {
	return new ItemStack(LOZmod.bomb);
    	
    }
}

 

ItemBomb.class:

package dudesmods.lozmod;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class ItemBomb extends Item {

public ItemBomb(int par1) {
	super(par1);
	setMaxStackSize(32);
	setCreativeTab(LOZmod.tabLozMod);
	}

public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {

	if(!entityplayer.capabilities.isCreativeMode) {
		--itemstack.stackSize;
	}

	if (!world.isRemote) {
		world.spawnEntityInWorld(new EntityBomb(world, entityplayer));
	}

	return itemstack;
}


}

 

 

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

  • Author

Anyone ):

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

  • Author

Fixed - forgot to use worldObj.removeEntity(this);

 

-~*Locked*~-

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Guest
This topic is now closed to further replies.

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.