Throwable Explosive
mod_Namehere
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
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
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:
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!
1
http://www.minecraftforum.net/topic/435006-172-slymask3s-mods-new-mod-old-tnt/
Thank You. :biggrin.gif: