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.

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

Featured Replies

Posted

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?

  • Author

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);
        }

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.