Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted
comment_138421

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()
   {
     super();
   setMaxStackSize(1).setFull3D();
   }
   @Override
   public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,EntityPlayer par3EntityPlayer) {
       if(par3EntityPlayer.capabilities.isCreativeMode||par3EntityPlayer.inventory.consumeInventoryItem(Mineturnedmain.RpgAmmo))
       {
           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;
       }
@SideOnly(Side.CLIENT)
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.

comment_138611

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!

comment_138967

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

comment_138986

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 :)

 

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.