Jump to content

Inaccurate lightning strikes?


TLHPoE

Recommended Posts

I just semi-finished my lightning sword. It basically shoots lightning where the player is pointing when they right click. Only problem is that the flames from the lightning strike spawn right next to the player. Is there anyway to stop this?

 

    public ItemStack onItemRightClick(ItemStack par1ItemStack, World world, EntityPlayer player)
    {
    	
    	Random r = new Random();
    	
        player.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
        
        par1ItemStack.damageItem(3, player);
        
        Vec3 vec3 = player.getPosition(1.0F);
        Vec3 vec3a = player.getLook(1.0F);
        Vec3 vec3b = vec3.addVector(vec3a.xCoord * 64, vec3a.yCoord * 64, vec3a.zCoord * 64);

        MovingObjectPosition movingobjectposition = world.clip(vec3, vec3b);
        
        if(movingobjectposition != null) //null check
        {
        	
            world.spawnEntityInWorld(new EntityLightningBolt(world, movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ));
        	
        }
        
        return par1ItemStack;
        
    }

Kain

Link to comment
Share on other sites

I believe that that is set in the actual entity file itself. You could always just go through all the fire blocks within a certain radius around the player and clear the them every time you click... But that is a bit inefficient. So I am not to sure on this...

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Huh.  I'm not having that problem.

 

Though I did have a weird problem where the item onRightClick method would only be partially functional; as if it was running client-side only (that is, it was running on the server side as well, but that changes to entities wouldn't stick,* as if they'd been done client side).

 

*My one test before I moved over to a packet based system dealt with healing the player with that function.  I didn't try other effects, like lightning and so on, simply went "fine, this isn't working as expected" and shoved everything into packets.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

My sword:

 

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
    	 float f = 1.0F;
         float f1 = par3EntityPlayer.prevRotationPitch + (par3EntityPlayer.rotationPitch - par3EntityPlayer.prevRotationPitch) * f;
         float f2 = par3EntityPlayer.prevRotationYaw + (par3EntityPlayer.rotationYaw - par3EntityPlayer.prevRotationYaw) * f;
         
         double d = par3EntityPlayer.prevPosX + (par3EntityPlayer.posX - par3EntityPlayer.prevPosX) * (double)f;
         double d1 = (par3EntityPlayer.prevPosY + (par3EntityPlayer.posY - par3EntityPlayer.prevPosY) * (double)f + 1.6200000000000001D) - (double)par3EntityPlayer.yOffset;
         double d2 = par3EntityPlayer.prevPosZ + (par3EntityPlayer.posZ - par3EntityPlayer.prevPosZ) * (double)f;
         
         Vec3 vec3d = Vec3.createVectorHelper(d, d1, d2);
         
         float f3 = MathHelper.cos(-f2 * 0.01745329F - 3.141593F);
         float f4 = MathHelper.sin(-f2 * 0.01745329F - 3.141593F);
         float f5 = -MathHelper.cos(-f1 * 0.01745329F);
         float f6 = MathHelper.sin(-f1 * 0.01745329F);
         float f7 = f4 * f5;
         float f8 = f6;
         float f9 = f3 * f5;
         
         double d3 = 5000D;
        
         Vec3 vec3d1 = vec3d.addVector((double)f7 * d3, (double)f8 * d3, (double)f9 * d3);
         
         MovingObjectPosition movingobjectposition = par2World.rayTraceBlocks_do_do(vec3d, vec3d1, false, true);
         
         if (movingobjectposition == null){
         
        	 return par1ItemStack;
         }
         
         if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE){
         
        	 int i = movingobjectposition.blockX;
             int j = movingobjectposition.blockY;
             int k = movingobjectposition.blockZ;
             
             for(int m = 0; m < 5; m++){
             
            	 par2World.spawnEntityInWorld(new EntityLightningBolt(par2World, i, j, k));
             }
         
             par1ItemStack.damageItem(20, par3EntityPlayer);
         }
         return par1ItemStack;
     }

Link to comment
Share on other sites

Looks just about the same as what I do.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.