Jump to content

[1.7.10][SOLVED]Detect Item Left Click


Recommended Posts

Guest Abrynos
Posted

I wondered, how to detect, if a player leftclicks my item inside of my item class... if you say that doesn't work I'll use an EventHandler.

Guest Abrynos
Posted

@Override
public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack){
EntityPlayer player = (EntityPlayer)entityLiving;
Vec3 look = player.getLookVec();
EntityLargeFireball fireball = new EntityLargeFireball(player.getEntityWorld(), player, 1, 1, 1);
fireball.setPosition(player.posX + look.xCoord * 5, player.posY + look.yCoord * 5, player.posZ + look.zCoord * 5);
fireball.accelerationX = look.xCoord * 0.1;
fireball.accelerationY = look.yCoord * 0.1;
fireball.accelerationZ = look.zCoord * 0.1;
player.getEntityWorld().spawnEntityInWorld(fireball);

return false;
}

 

somehow this spawns 2 fireballs everytime i leftclick with the item... It's not all the code, but the rest is only some nbt thing to make sure there is only every third time spawning a fireball, but it's only a few if statements and no loops, so it shouldn't be the source of the second fireball.

Guest Abrynos
Posted

so a simple if statement testing

!world.isRemote

should do it?

Guest Abrynos
Posted

Just found another problem:

 

When I'm looking at a block while leftclicking it spawns a fireball everytime... no matter, what the nbtTag says. (like mentioned, it should only do it every third time) :/ I generally want to prevent spawning a fireball when looking at a block, so that the player doesn't blow himself up.

Guest Abrynos
Posted

@Override
public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack)
{
if(entityLiving instanceof EntityPlayer){
	EntityPlayer player = (EntityPlayer)entityLiving;

	NBTTagCompound nbtTag = stack.getTagCompound();
	if (nbtTag == null) {
		nbtTag = new NBTTagCompound();
		stack.setTagCompound(nbtTag);
	}


	if(nbtTag.getString("one") == "Left"){
		if((nbtTag.getString("two") == "Left") || (nbtTag.getString("two") == "Right")){
			nbtTag.setString("three", "Left");
		}
		else{
			nbtTag.setString("two", "Left");
		}
	}
	else{
		nbtTag.setString("one", "Left");
	}		

	if(nbtTag.getString("one") != "" && nbtTag.getString("two") != "" && nbtTag.getString("three") != ""){
		if(nbtTag.getString("one") == "Left" && nbtTag.getString("two") == "Left" && nbtTag.getString("three") == "Left"){
			Vec3 look = player.getLookVec();
			EntityLargeFireball fireball = new EntityLargeFireball(player.getEntityWorld(), player, 1, 1, 1);
			fireball.setPosition(player.posX + look.xCoord * 5, player.posY + look.yCoord * 5, player.posZ + look.zCoord * 5);
			fireball.accelerationX = look.xCoord * 0.1;
			fireball.accelerationY = look.yCoord * 0.1;
			fireball.accelerationZ = look.zCoord * 0.1;
			if(!player.getEntityWorld().isRemote){
				player.getEntityWorld().spawnEntityInWorld(fireball);
			}
			nbtTag.setString("one", "");
			nbtTag.setString("two", "");
			nbtTag.setString("three", "");
		}
	}
        return false;
}
return false;
}

 

the thing with the 3 nbtTags is because i got a similar thing in the Overridden onItemRightClick-method. to make spells

Guest Abrynos
Posted

the code works fine except when i'm looking on a block; in all the other cases i don't care xD

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.