Posted February 21, 201510 yr 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.
February 21, 201510 yr @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.
February 21, 201510 yr 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.
February 21, 201510 yr @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
February 21, 201510 yr the code works fine except when i'm looking on a block; in all the other cases i don't care
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.