**Warning**: this will not give you code to copy and paste. You will have to read and ALREADY understand how to program and how to use modloader.

Current

Spear

To be added

Custom bow and arrow

grenade

any other requests

**Spear**

Spoiler:

]This Tut comes out of the fact that I have not found any code to simply make a spear, and most just tell u to use the bow and arrow code. So I took the time to get one working.

Step 1 make a item, it doesn't matter what it is named. Now take this piece of code and add it to the onItemRightClick, or onPlayerStoppedUsing, or where ever you want it to launch your spear at.

(the 2.0F in the code is force so you can change it to any number you would like.)

there is more you can do but i wont get into it because it can easily be found.

also after or before this statement is where you can decrease item stack or set damage like so:

so next you guessed it we must create the EntitySpear class.

this will easily be done by copying the arrow code then renaming it to spear.

next we must change what item it gives you back.

so change item.arrow to mod_******.Spear here

Now if i didn't miss any changes and you followed this, when you spawn you spear it should be a white cube because it doesn't have a render class.

so again we copy the arrow's render class and of course change it to spear.

i used this spear design so every thing i do is based off this which is twice the length of the arrow or 32 pixels.

First change your image location to what image your using, this doesn't require modloader commands.

And the only other thing needed to be changed is the variable( with my version on mcp) F which is multiplied by 2, as you can see in the last row.

From there you can add many different functions to it.

Step 1 make a item, it doesn't matter what it is named. Now take this piece of code and add it to the onItemRightClick, or onPlayerStoppedUsing, or where ever you want it to launch your spear at.

(the 2.0F in the code is force so you can change it to any number you would like.)

//the 2.0F can be multiplied or done whatever to to change the force. EntitySpear entityspear = new EntitySpear(world, entityplayer, 2.0F); world.spawnEntityInWorld(entityspear);This will create and spawn the spear with the set velocity.

there is more you can do but i wont get into it because it can easily be found.

also after or before this statement is where you can decrease item stack or set damage like so:

// checks if is not in creative and then consumes a spear if (!entityplayer.capabilities.isCreativeMode){ entityplayer.inventory.consumeInventoryItem(mod_Tutorial.Spear.shiftedIndex); } //4 can be changed to anything entityspear.setDamage(4);Step 2

so next you guessed it we must create the EntitySpear class.

this will easily be done by copying the arrow code then renaming it to spear.

next we must change what item it gives you back.

so change item.arrow to mod_******.Spear here

if (inGround && doesArrowBelongToPlayer && arrowShake <= 0 && par1EntityPlayer.inventory.addItemStackToInventory(new ItemStack(mod_Tutorial.Spear, 1))) { worldObj.playSoundAtEntity(this, "random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F); par1EntityPlayer.onItemPickup(this, 1); setDead(); }Also change the original damage source to this

if (shootingEntity == null) { damagesource = DamageSource.causeThrownDamage(this, this); } else { damagesource = DamageSource.causeThrownDamage(this, shootingEntity); }As always there is so much more that could be changed but I wont be getting into that right now.

Now if i didn't miss any changes and you followed this, when you spawn you spear it should be a white cube because it doesn't have a render class.

so again we copy the arrow's render class and of course change it to spear.

i used this spear design so every thing i do is based off this which is twice the length of the arrow or 32 pixels.

First change your image location to what image your using, this doesn't require modloader commands.

And the only other thing needed to be changed is the variable( with my version on mcp) F which is multiplied by 2, as you can see in the last row.

float f = 0.0F; float f1 = 0.5F; float f2 = (float)(0 + i * 10) / 32F; float f3 = (float)(5 + i * 10) / 32F; float f4 = 0.0F; float f5 = 0.15625F; float f6 = (float)(5 + i * 10) / 32F; float f7 = (float)(10 + i * 10) / 32F; //here f1 = f1 * 2;Last in your mod_**** put this line to allow the render to work.

public void addRenderer(Map map) { map.put(EntitySpear.class, new RenderSpear()); }And if all was done correctly(by you and me) you should have a working spear.

From there you can add many different functions to it.

**No drop in spear/arrow**

Spoiler:

Any problems you may have i would be glad to help with, I dont know everthing but i can atleast give it a try.
For this it is really simple, in basic form all you have to do is remove any part that changes the movement(X,Y,Z) so here is how i did it

So just delete anything commented out or one case change numbers.

This is all in the Entitywhatever class

**Warning this may not work perfectly because i have not tested it any extreme, just that it works.**So just delete anything commented out or one case change numbers.

This is all in the Entitywhatever class

protected void entityInit() { } public void setArrowHeading(double par1, double par3, double par5, float par7, float par8) { float f = MathHelper.sqrt_double(par1 * par1 + par3 * par3 + par5 * par5); par1 /= f; par3 /= f; par5 /= f; //change this set of statments par1 += par1;// this is what we change par3 += par3; par5 += par5; // to here par1 *= par7; par3 *= par7; par5 *= par7; motionX = par1; motionY = par3; motionZ = par5; float f1 = MathHelper.sqrt_double(par1 * par1 + par5 * par5); prevRotationYaw = rotationYaw = (float)((Math.atan2(par1, par5) * 180D) / Math.PI); prevRotationPitch = rotationPitch = (float)((Math.atan2(par3, f1) * 180D) / Math.PI); ticksInGround = 0; } public void setVelocity(double par1, double par3, double par5) { motionX = par1; motionY = par3; motionZ = par5; if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(par1 * par1 + par5 * par5); prevRotationYaw = rotationYaw = (float)((Math.atan2(par1, par5) * 180D) / Math.PI); prevRotationPitch = rotationPitch = (float)((Math.atan2(par3, f) * 180D) / Math.PI); prevRotationPitch = rotationPitch; prevRotationYaw = rotationYaw; setLocationAndAngles(posX, posY, posZ, rotationYaw, rotationPitch); ticksInGround = 0; } } public void onUpdate() { super.onUpdate(); if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); prevRotationYaw = rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / Math.PI); prevRotationPitch = rotationPitch = (float)((Math.atan2(motionY, f) * 180D) / Math.PI); } int i = worldObj.getBlockId(xTile, yTile, zTile); if (i > 0) { Block.blocksList[i].setBlockBoundsBasedOnState(worldObj, xTile, yTile, zTile); AxisAlignedBB axisalignedbb = Block.blocksList[i].getCollisionBoundingBoxFromPool(worldObj, xTile, yTile, zTile); if (axisalignedbb != null && axisalignedbb.isVecInside(Vec3D.createVector(posX, posY, posZ))) { inGround = true; } } if (arrowShake > 0) { arrowShake--; } if (inGround) { int j = worldObj.getBlockId(xTile, yTile, zTile); int k = worldObj.getBlockMetadata(xTile, yTile, zTile); if (j != inTile || k != inData) { inGround = false; //motionX *= rand.nextFloat() * 0.2F; // motionY *= rand.nextFloat() * 0.2F; // motionZ *= rand.nextFloat() * 0.2F; ticksInGround = 0; ticksInAir = 0; return; } ticksInGround++; if (ticksInGround == 1200) { setDead(); } return; } ticksInAir++; Vec3D vec3d = Vec3D.createVector(posX, posY, posZ); Vec3D vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ); MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks_do_do(vec3d, vec3d1, false, true); vec3d = Vec3D.createVector(posX, posY, posZ); vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ); if (movingobjectposition != null) { vec3d1 = Vec3D.createVector(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } Entity entity = null; List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D)); double d = 0.0D; for (int l = 0; l < list.size(); l++) { Entity entity1 = (Entity)list.get(l); if (!entity1.canBeCollidedWith() || entity1 == shootingEntity && ticksInAir < 5) { continue; } float f5 = 0.3F; AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand(f5, f5, f5); MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec3d, vec3d1); if (movingobjectposition1 == null) { continue; } double d1 = vec3d.distanceTo(movingobjectposition1.hitVec); if (d1 < d || d == 0.0D) { entity = entity1; d = d1; } } if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if (movingobjectposition != null) { if (movingobjectposition.entityHit != null) { float f1 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ); int j1 = (int)Math.ceil((double)f1 * damage); if (arrowCritical) { j1 += rand.nextInt(j1 / 2 + 2); } DamageSource damagesource = null; if (shootingEntity == null) { damagesource = DamageSource.causeThrownDamage(this, this); } else { damagesource = DamageSource.causeThrownDamage(this, shootingEntity); } if (isBurning()) { movingobjectposition.entityHit.setFire(5); } if (movingobjectposition.entityHit.attackEntityFrom(damagesource, j1)) { if (movingobjectposition.entityHit instanceof EntityLiving) { ((EntityLiving)movingobjectposition.entityHit).arrowHitTempCounter++; if (field_46027_au > 0) { float f7 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); if (f7 > 0.0F) { movingobjectposition.entityHit.addVelocity((motionX * (double)field_46027_au * 0.60000002384185791D) / (double)f7, 0.10000000000000001D, (motionZ * (double)field_46027_au * 0.60000002384185791D) / (double)f7); } } } } else { //motionX *= -0.10000000149011612D; // motionY *= -0.10000000149011612D; // motionZ *= -0.10000000149011612D; // rotationYaw += 180F; // prevRotationYaw += 180F; ticksInAir = 0; } } else { xTile = movingobjectposition.blockX; yTile = movingobjectposition.blockY; zTile = movingobjectposition.blockZ; inTile = worldObj.getBlockId(xTile, yTile, zTile); inData = worldObj.getBlockMetadata(xTile, yTile, zTile); // motionX = (float)(movingobjectposition.hitVec.xCoord - posX); // motionY = (float)(movingobjectposition.hitVec.yCoord - posY); // motionZ = (float)(movingobjectposition.hitVec.zCoord - posZ); float f2 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ); posX -= (motionX / (double)f2) * 0.05000000074505806D; posY -= (motionY / (double)f2) * 0.05000000074505806D; posZ -= (motionZ / (double)f2) * 0.05000000074505806D; worldObj.playSoundAtEntity(this, "random.bowhit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F)); inGround = true; arrowShake = 7; arrowCritical = false; } } if (arrowCritical) { for (int i1 = 0; i1 < 4; i1++) { worldObj.spawnParticle("crit", posX + (motionX * (double)i1) / 4D, posY + (motionY * (double)i1) / 4D, posZ + (motionZ * (double)i1) / 4D, -motionX, -motionY + 0.20000000000000001D, -motionZ); } } posX += motionX; posY += motionY; posZ += motionZ; float f3 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / Math.PI); for (rotationPitch = (float)((Math.atan2(motionY, f3) * 180D) / Math.PI); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) { } for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) { } for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) { } for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) { } //rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F; // rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F; float f4 = 0.99F; float f6 = 0.05F; if (isInWater()) { for (int k1 = 0; k1 < 4; k1++) { float f8 = 0.25F; worldObj.spawnParticle("bubble", posX - motionX * (double)f8, posY - motionY * (double)f8, posZ - motionZ * (double)f8, motionX, motionY, motionZ); } f4 = 0.8F; } // motionX *= f4; // motionY *= f4; // motionZ *= f4; // motionY -= f6; setPosition(posX, posY, posZ); }