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

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.

Uhm, im pretty damn sure the maxDamage parameters are the x, y, z coords :D

How else would minecraft know where to spawn it?

Why are you trying to spawn the entity at (maxDamage, maxDamage, maxDamage)? All three instance of "maxDamage" should be replaced with the x, y, and z coordinates respectively.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Just like you put maxDamage, maxDamage, maxDamage, I suggest you learn Java, learn Java, learn Java.

Maker of the Craft++ mod.

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

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!

  • Author

it says z, y, x cannot be resolved as variables. and btw where do I put MovingObjectPosition mop = Minecraft.getMinecraft().renderViewEntity.rayTrace(200, 1.0F);?

  • Author

I don't want to spend a lot of time learning java as I only would be using it for this and maybe moding other games.

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

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.