Jump to content

[1.7.10]Spawning Lightning Bolts


Recommended Posts

I am attempting to make a item that when right clicked will shoot lightning bolts. However I have tried everything and cannot get lightning bolts to spawn. Does anyone have any idea of how I could do this?

Here is the items class:

package com.mineturnedmod.mineturned.items;

import com.mineturnedmod.mineturned.EntityBolt;
import com.mineturnedmod.mineturned.EntityRpg;
import com.mineturnedmod.mineturned.Mineturnedmain;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class MjolnirClass extends Item
   public MjolnirClass()
   public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,EntityPlayer par3EntityPlayer) {
           par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
           if (!par2World.isRemote)
               par2World.spawnEntityInWorld(new EntityLightningBolt(par2World, maxDamage, maxDamage, maxDamage));
           return par1ItemStack;
public void registerIcons(IIconRegister reg){
	this.itemIcon = reg.registerIcon("morecraftingmod:iron_sword_");
   } }


The problem is on the line spawn in world. The maxDamage is the default constructor that it tells me to put there but it doesn't spawn the lightning bolt.

Link to comment
Share on other sites

You mean where the player is looking at / the cross-hair is pointed to?

Players may not always face vertically.

You can try using

MovingObjectPosition mop = Minecraft.getMinecraft().renderViewEntity.rayTrace(200, 1.0F);

It may help, considering you know how to extract data from the variable 'mop'.

Link to comment
Share on other sites

What, we can get the block the player is looking at at the server without packages?

I am pretty sure that i used some really complicated algorithm to archive this using the players head rotation. DAMN! (Cause I didn't want to add packages just for this one function.)


You put the x y z values by using EntityLightningBolt(par2World, z, y, x).  (yeah, its definitely zyx, not xyz :P)

Here could be your advertisement!

Link to comment
Share on other sites

I suggest you just use

onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)

wich gives u the x,y,z coords off the block clicked.

note this will not work for clicking on air water and lava

Link to comment
Share on other sites

I wanted to do the same as you. Diesieben07 helped me and i figured out how to make them spawn.


Basically i used getMovingObjectPositionFromPlayer(...) that i copied in the class of my item, rename into getDistanceFromPlayer(...) and modified a bit in order to be able to adjust the distance the player can right-click (as diesieben07 suggested) and not the rayTrace(...) which is only client side. Then i test if the world is remote and if not i spawn the lightning.


You can have a look at the solution i used at the end of this topic :  http://www.minecraftforge.net/forum/index.php/topic,27030.0.html


Hope it helps :)


PS : i also think that you should learn Java before trying to create your mod. It will be easier to understand how everything work :)


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.

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.