Jump to content

Recommended Posts

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

Posted

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

Posted

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?

Posted

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?

Posted

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.

Posted

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

Posted

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.

Posted

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

Posted

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?

Posted

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.

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.

Announcements



×
×
  • Create New...

Important Information

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