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 want to make an item that spawns lightning were the player is looking. problem is I don't have the right code, I think its out dated because I cant find these things in the vec3 class. here is my code

 

package com.OlympiansMod.Item;

import com.OlympiansMod.entity.EntityThunderBolt;
import com.OlympiansMod.entity.EntityUndead;

import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;


public class ZThunderBolt extends Item{
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player){
	if(!player.capabilities.isCreativeMode){
		--itemstack.stackSize;
	}
	//world.playSoundAtEntity(player, "random.fizz", 0.7f, 0.8f);

	//if(!world.isRemote){
	 Vec3 posVec = world.getWorldVec3Pool().getVec3FromPool(player.posX, player.posY + player.getEyeHeight(), player.posZ);
	 Vec3 lookVec = player.getLookVec();
	 MovingObjectPosition mop = world.rayTraceBlocks(posVec, lookVec);

	 int x = mop.blockX;
	 int y = mop.blockY;
	 int z = mop.blockZ;


		EntityLightningBolt Bolt = new EntityLightningBolt(world, 5, 5, 5);
		Bolt.setPosition(player.posX = x , player.posY + y , player.posZ + z);;
		world.spawnEntityInWorld(Bolt);
	//}

	return itemstack;

}


}





 

so yeah what do I do to fix it? btw syntax error on world.getWorldVec3Pool().getVec3FromPool

Im serious don't look at it!!

  • Author

nothing is working I think I need to write a new method. do you know any tutorials for 1.7.10 im confused with the new code. ive looked but I cant seem to find a tutorial anywere.

Im serious don't look at it!!

  • Author

can someone just tell me how to do it because so far nothing is working.

 

public class ZThunderBolt extends Item{
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player){
	if(!player.capabilities.isCreativeMode){
		--itemstack.stackSize;
	}
	//world.playSoundAtEntity(player, "random.fizz", 0.7f, 0.8f);

	//if(!world.isRemote){
	@Override
	 Vec3 posVec = new Vec3(player.posX, player.posY, player.posZ); 
	 Vec3 lookVec = player.getLookVec();
	 MovingObjectPosition mop = world.rayTraceBlocks(posVec, lookVec);

	 int x = mop.blockX;
	 int y = mop.blockY;
	 int z = mop.blockZ;


		EntityLightningBolt Bolt = new EntityLightningBolt(world, 5, 5, 5);
		Bolt.setPosition(player.posX = x , player.posY + y , player.posZ + z);;
		world.spawnEntityInWorld(Bolt);
	//}

	return itemstack;

}


}

Im serious don't look at it!!

You clearly dont understand how to override a method. You need to put @Override above onItemRightClick. Also get rid of all the extra code that doesnt work. If you want to spawn it where the player is looking, why do you need to ray trace when you already use a Vec3 look vector?

You clearly dont understand how to override a method. You need to put @Override above onItemRightClick.

Not to be mean, but you clearly don't understand what @Override actually does - it is simply an extra layer of error-checking within the IDE - it has no effect whatsoever on the compiled code.

 

@OP You probably want to pay more attention to what you are writing in your code:

Bolt.setPosition(player.posX = x , player.posY + y , player.posZ + z);;

Surely you meant plus (+) and not equals (=) ?

 

Also, why are you adding them at all? The raytrace MovingObjectPosition returns the block position that was hit, as in real world block coordinates. If you add the player's position to that, you will get very bizarre numbers.

 

Example:

Player is at 100,64,100 looking east (+x axis); MOP returns a block at 100,64,115 (directly east). Now you add those together, and spawn lightning at 200, 128, 215. Do you really expect to see it?

You clearly dont understand how to override a method. You need to put @Override above onItemRightClick.

Not to be mean, but you clearly don't understand what @Override actually does - it is simply an extra layer of error-checking within the IDE - it has no effect whatsoever on the compiled code.

 

I'm aware of this, just pointing out that thats not where override goes.

  • Author

okay guys but that's not the problem.  I did have a typo but im getting current errors in my code specifically on new Vec3. I don't exactly know how that works. and I do know that the override goes above the method. but at this point im desperate and new to java so.. anyway what else can I do. and I have the raytraceblocks so that it finds the block that the player is looking at and defines the other int.

Im serious don't look at it!!

Yeah, that's the one: Vec3.createVectorHelper. Arguments are the coordinates of the vector you want to create. I don't know what you mean by 'defines the other int' - what int?

 

Listen, I understand you are "desperate" to get this working, but perhaps a time-out to learn about vectors would be helpful? That and going through some basic Java tutorials, of course.

  • Author

ok gotcha coolAlias

 

this isn't working for me in my craft.

package com.OlympiansMod.Item;

import com.OlympiansMod.entity.EntityThunderBolt;
import com.OlympiansMod.entity.EntityUndead;

import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.monster.EntitySlime;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;


public class ZThunderBolt extends Item{
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player){
	if(!player.capabilities.isCreativeMode){
		--itemstack.stackSize;
	}
	//world.playSoundAtEntity(player, "random.fizz", 0.7f, 0.8f);

	if(!world.isRemote){
	 Vec3 posVec = Vec3.createVectorHelper(player.posX, player.posY + player.getEyeHeight(), player.posZ);
	 Vec3 lookVec = player.getLookVec();
	 MovingObjectPosition mop = world.rayTraceBlocks(posVec, lookVec);

	 int x = mop.blockX;
	 int y = mop.blockY;
	 int z = mop.blockZ;

	 System.out.println(x + ","+ y + ","+ z + " " + world.getBlock(x, y, z));

		EntitySlime Bolt = new EntitySlime(world);
		Bolt.setPosition(player.posX + x , player.posY + y , player.posZ + z);
		world.spawnEntityInWorld(Bolt);




}
	return itemstack;
}
}








 

is there anything you think I should change to make it work.

Im serious don't look at it!!

To quote myself in answer to your question:

Also, why are you adding them at all? The raytrace MovingObjectPosition returns the block position that was hit, as in real world block coordinates. If you add the player's position to that, you will get very bizarre numbers.

 

Example:

Player is at 100,64,100 looking east (+x axis); MOP returns a block at 100,64,115 (directly east). Now you add those together, and spawn lightning at 200, 128, 215. Do you really expect to see it?

You didn't listen the first time, so perhaps the second?

your quote is blank?

Not from my end, it isn't, but just in case, here it is, unquoted, again:

 

"Also, why are you adding them at all? The raytrace MovingObjectPosition returns the block position that was hit, as in real world block coordinates. If you add the player's position to that, you will get very bizarre numbers.

 

Example:

Player is at 100,64,100 looking east (+x axis); MOP returns a block at 100,64,115 (directly east). Now you add those together, and spawn lightning at 200, 128, 215. Do you really expect to see it?"

 

In summary, use the coordinates from the MovingObjectPosition, and DO NOT ADD anything, certainly not the player's position. It makes no sense at all to do so, as you can see in the example provided.

  • Author

okay so I get what your saying but I definitely agree with you, I need to learn more about it so yeah. basically for now I made an entity type throwable that spawns the lightning in on impack

Im serious don't look at it!!

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.