MC Modding
Please register and join the community!

[1.8.1] Throwable Explosive

View previous topic View next topic Go down

[1.8.1] Throwable Explosive

Post by Strengthowns on Fri Jul 01, 2011 8:47 am

Throwable Explosive

Spoiler:
mod_Namehere
Code:
package net.minecraft.src;

public class mod_Namehere extends BaseMod
{

    public static Item Namehere = (new ItemNamehere(9000)).setItemName("Namehere");

    public mod_Namehere()
    {
        Namehere.iconIndex = ModLoader.addOverride("/gui/items.png", "/Namehere.png");
        ModLoader.AddName(Namehere, "Namehere");
        ModLoader.AddRecipe((new ItemStack(Namehere, 1)), new Object[] {
      "###", "###", "###", Character.valueOf('#'), Block.dirt
      });
    }
   
   public String Version()
    {
        return "1.7.3";
    }
}

ItemNamehere
Code:
package net.minecraft.src;
 
public class ItemNamehere extends Item
{
 
    public ItemNamehere(int i)
    {
        super(i);
      maxStackSize = 64;
        NamehereID = shiftedIndex;
    }
 
    public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
    {
       world.entityJoinedWorld(new EntityNamehere(world, entityplayer));
       --itemstack.stackSize;
        return itemstack;
    }
 
    public static int NamehereID;
}

EntityNamehere
Code:
package net.minecraft.src;
 
public class EntityNamehere extends EntityItem
{
 
    public EntityNamehere(World world)
    {
        super(world);
        setSize(0.5F, 0.5F);
        yOffset = height / 2.0F;
        item = new ItemStack(Item.itemsList[ItemNamehere.NamehereID]);
        bounceFactor = 0.6;
        exploded = false;
        stopped = false;
        fuse = 0;
    }
    public EntityNamehere(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.8);
        prevPosX = posX;
        prevPosY = posY;
        prevPosZ = posZ;
 
        fuse = fuseLength;
    }
    public EntityNamehere(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(null, posX, posY, posZ, 5F);
       }
    }
 
    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;
}

Help: mod_Namehere

1. Everything here is the same as normal.

Help: ItemNamehere

1. Same as normal, change all the Namehere's.

Help: EntityNamehere

1. I won't explain everything here, as after looking at it closely you should understand the idea of it.

2. First off, change the bounce factor at the top to whatever you want.

3. More advanced modders can mess around with the other stuff.

4. Towards the bottom where it has this:
Code:
    protected void explode()
    {
       if(!exploded)
       {
          exploded = true;
           worldObj.createExplosion(null, posX, posY, posZ, 5F);
       }
    }
change the 5F to how big you want the explosion to be.

5. Leave the rest and...Done! Enjoy your new throwable explosive!
avatar
Strengthowns
Admin

Posts : 79
Join date : 2011-06-14
Location : Right here!

View user profile http://www.mcmodding.4umer.com

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by lcass on Wed Oct 26, 2011 1:23 pm

when i try this the causethrowndamage bit goes red and dosn't work !!!!

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by lcass on Wed Oct 26, 2011 1:33 pm

how would you make it do napalm or even in portal 2 speed gel

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by bottz2 on Thu Oct 27, 2011 1:35 am

how do i make i glow and not explode like a glowstick

bottz2
Member

Posts : 14
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by breakyorself on Thu Oct 27, 2011 2:23 am

Shouldn`t be looking at throwable explosive you should look at the items tutorial and i suggest putting this is requests.
avatar
breakyorself
Member

Posts : 60
Join date : 2011-10-19

View user profile

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by bottz2 on Thu Oct 27, 2011 2:30 am

well i want to be able to through the glowstick

bottz2
Member

Posts : 14
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by breakyorself on Thu Oct 27, 2011 3:00 am

You should still put it in help or requests.
avatar
breakyorself
Member

Posts : 60
Join date : 2011-10-19

View user profile

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by lcass on Thu Oct 27, 2011 11:11 am

remove the causethrowdamage part it dosn't work also the glowstick Idea seems nice

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by breakyorself on Thu Oct 27, 2011 6:16 pm

You would also have to remove the code where it blows up Neutral.
avatar
breakyorself
Member

Posts : 60
Join date : 2011-10-19

View user profile

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by lcass on Thu Oct 27, 2011 6:20 pm

acctually no here is the code you need if you want to fix it
Code:
package net.minecraft.src;
 
public class Entitynukethrow extends EntityItem
{
 
    public Entitynukethrow(World world)
    {
        super(world);
        setSize(0.5F, 0.5F);
        yOffset = height / 2.0F;
        item = new ItemStack(Item.itemsList[nukethrow.nukethrowID]);
        bounceFactor = 0.9;
        exploded = false;
        stopped = false;
        fuse = 120;
    }
    public Entitynukethrow(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.8);
        prevPosX = posX;
        prevPosY = posY;
        prevPosZ = posZ;
 
        fuse = fuseLength;
    }
    public Entitynukethrow(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(null, posX, posY, posZ, 50F);
      }
    }
 
    public boolean attackEntity(Entity entity, int i)
    {
      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;
}

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by breakyorself on Thu Oct 27, 2011 6:21 pm

Still need it to glow.
avatar
breakyorself
Member

Posts : 60
Join date : 2011-10-19

View user profile

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by lcass on Thu Oct 27, 2011 6:34 pm

you want the item to glow. add this code then I think it will work add it to the
mod_item.class
Code:
public static item namehere = new namehere(ID,0).setLightValue(1.0F)

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by breakyorself on Thu Oct 27, 2011 7:58 pm

I ment he still wants it to glow but that should help him
avatar
breakyorself
Member

Posts : 60
Join date : 2011-10-19

View user profile

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by lcass on Thu Oct 27, 2011 10:01 pm

yer I think it will work like that but what exactly do you mean by "glow" you mean like a texture around it if your going to do that you will need to declare a new item entity and a new void that makes it follow on click or just add it o the texture

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by breakyorself on Thu Oct 27, 2011 11:16 pm

I`m not the one who wanted it -.-.
avatar
breakyorself
Member

Posts : 60
Join date : 2011-10-19

View user profile

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by lcass on Thu Oct 27, 2011 11:17 pm

-.-

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by MrCreeper07 on Fri Oct 28, 2011 1:25 am

hey I'm having trouble getting the spoilers work!! They never open and I want to make a creeper bomb for my mod. I don't get why its not that popular when it has 10 new blocks, rainbow soup, a tool set, and 3 mobs?? I think people like explosives so this will help my mod a lot.
avatar
MrCreeper07
Member

Posts : 18
Join date : 2011-10-23

View user profile

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by bottz2 on Fri Oct 28, 2011 2:11 am

by glow i mean like give of light

bottz2
Member

Posts : 14
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by lcass on Fri Oct 28, 2011 2:13 am

Use my code then

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by mastereric on Fri Oct 28, 2011 2:16 am

@MrCreeper07 Wow, that's a lot of stuff! and rainbow soup! MMM Rainbow soup...
I think your mod isn't popular because nobody knows about it! Put a link in your signature! Put your modHere!
Back on topic!
I likely won't use this but its just cool to know its here!
avatar
mastereric
Member

Posts : 30
Join date : 2011-10-26

View user profile

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by bottz2 on Fri Oct 28, 2011 2:26 am

icass ur light code only works for blocks

bottz2
Member

Posts : 14
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by lcass on Fri Oct 28, 2011 2:41 am

It's lcass I will see if I can get it fixed nut from what I know no such block has worked

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] Throwable Explosive

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum