Jump to content

Prevent damage?


Omegaa

Recommended Posts

Hello, I've been making a new mod and I added this code:

@Override
 public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer Entityplayer) {

Vec3 look = Entityplayer.getLookVec();
 MovingObjectPosition Coord = Entityplayer.rayTrace(300, 1);
 EntityLightningBolt Lightning = new EntityLightningBolt(world, 1, 1, 1);
 Lightning.setPosition(Coord.blockX,Coord.blockY,Coord.blockZ);
 world.spawnEntityInWorld(Lightning);
 return itemStack;

 

to make lightning on right click, however in creative it works but in survival it damages the player, how can I prevent it from hurting the player but still hurt mobs and other players.

 

 

Link to comment
Share on other sites

You have to store the player's UUID in the lightning entity (getEntityData() gives you an NBTTagCompound to store your stuff in).

Then in EntityStruckByLighningEvent you then check if the player is the one that issued the lighting, by checking the UUID again. If they are, cancel the event.

 

I have tried a few times but couldn't seem to get the right code...

Could you give a example please?

Link to comment
Share on other sites

	 EntityLightningBolt Lightning = new EntityLightningBolt(world, 1, 1, 1);
 Lightning.setPosition(Coord.blockX,Coord.blockY,Coord.blockZ);
 world.spawnEntityInWorld(Lightning);

 

Sigh.

 

Do you know what those 1s being passed to the constructor mean?

 

No, clearly you don't.

 

They're the entity's starting position.

 

EntityLightningBolt Lightning = new EntityLightningBolt(world, Coord.blockX,Coord.blockY,Coord.blockZ);

 

Amzanig!

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Ok I fixed it slightly since Draco helped..

Thanks Draco!

Here is my current code:

	public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer Entityplayer) {


	Vec3 look = Entityplayer.getLookVec();
	MovingObjectPosition Coord = Entityplayer.rayTrace(300, 1);
	         EntityLightningBolt Lightning = new EntityLightningBolt(world, 1, 1, 1);
	         Lightning.setPosition(Coord.blockX,Coord.blockY+1,Coord.blockZ);
	         world.spawnEntityInWorld(Lightning);
	  
	return itemStack;

but now I'm getting fire underneath me, I have tried to remove it but couldn't, any ideas?

Link to comment
Share on other sites

Here is my current code...

 

Fixed slightly since Draco helped..

 

Current code posted is identical to old code.

 

Anyway, your inability to kill the fire probably has to do with the fact that onItemRightClick is client-side-only.  When I was doing this kind of stuff, I had to use packets to properly make right-click functionality work correctly.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Here is my current code...

 

Fixed slightly since Draco helped..

 

Current code posted is identical to old code.

 

 

Anyway, your inability to kill the fire probably has to do with the fact that onItemRightClick is client-side-only.  When I was doing this kind of stuff, I had to use packets to properly make right-click functionality work correctly.

 

Current code posted is identical to old code.

Lightning.setPosition(Coord.blockX,Coord.blockY+1,Coord.blockZ);

Coord.blockY+1

+1

 

 

Link to comment
Share on other sites

Current code posted is identical to old code.

Lightning.setPosition(Coord.blockX,Coord.blockY+1,Coord.blockZ);

Coord.blockY+1

+1

 

But you didn't even change the thing I pointed out.

Capture.png

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.

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.