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

no answer?

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

so a simple if statement testing

!world.isRemote

should do it?

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.

@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

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

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.