Jump to content

onItemRightClick Spawn Entity Relative to Player Position at a Certain Height -s


gurujive

Recommended Posts

I'm looking to spawn an entity above the player at such n such height on right click when shift is held.

 

This is what I have, but no matter where my player is it will only spawn at 8 and not follow my players position:

public class ItemOrb extends Item
{
    public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
    {
        if (!playerIn.capabilities.isCreativeMode)
        {
            --itemStackIn.stackSize;
        }
        worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.4F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
        if (!worldIn.isRemote && !playerIn.isSneaking())
        {
            EntityOrb entitythrowable = new EntityOrb(worldIn, playerIn);
            entitythrowable.func_184538_a(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
            worldIn.spawnEntityInWorld(entitythrowable);
        }
        else if (!worldIn.isRemote && playerIn.isSneaking())
        {
        	EntityOrb entitythrowable = new EntityOrb(worldIn, playerIn);
            entitythrowable.func_184538_a(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 0.0F, 0.0F);
            entitythrowable.posY = 8;
            entitythrowable.addVelocity(0.0, -0.3, 0.0);
            worldIn.spawnEntityInWorld(entitythrowable);
        }
        playerIn.addStat(StatList.getObjectUseStats(this));
        return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
    }
}

 

 

What I'm really aiming to do here is get it so when I shift and right click the entity will somehow or another make impact with my player. The entity making impact with the player travels through entities and blocks and has no gravity. At the current height it is spawned in at 0 0 0, it does not make impact with the player like it needs to.

 

The above works, but only if my player is at the right world height... Is there a way to do this to where it will spawn above my player a distance of 8 no matter where he is?

Link to comment
Share on other sites

i got it :)

 

else if (!worldIn.isRemote && playerIn.isSneaking())
        {
        	
        	EntityOrb entitythrowable = new EntityOrb(worldIn, playerIn);
        	playerIn.posY = 7;
            entitythrowable.func_184538_a(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 0.001F, 0.0F);
            entitythrowable.addVelocity(0.0, -0.1, 0.0); 
            worldIn.spawnEntityInWorld(entitythrowable);
        }

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.