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 would like to learn how to render a block in the world (a set distance from the player) when a player holds right-click on an item. Can anybody point me in the right direction? Here is what I have so far:

 

@Override
    public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn,
    		EnumHand hand) {
    	Vec3d look = playerIn.getLookVec();
    	float distance = 10.0F;
    	double dx = playerIn.posX + (look.xCoord * distance);
    	double dy = playerIn.posY + (look.yCoord * distance);
    	double dz = playerIn.posZ + (look.zCoord * distance);
    	BlockPos position = new BlockPos(dx, dy, dz);
    		
      	//RENDER THE BLOCK AT THE POSITION ABOVE
      
    	return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand);
    }

 

  • Author
4 minutes ago, diesieben07 said:

So, do you want the block to hide again when the player releases the button?

Yes, I do.

  • Author
9 minutes ago, diesieben07 said:

Ok. I can think of a few possible ways to address that.

 

First thing that comes to mind is to check (carefully) in getActualState in your Block class whether the player is looking at that block and holding right click. Then schedule a re-render (using notifyBlockUpdate) when the player starts or stops right-clicking the block.

Now you can apply that knowledge to the IBlockState, which lets you change the model.

 

I'm actually trying to go for something that behaves more like this:

 

https://youtu.be/IjVQVAt7j0U?t=38

 

Does that give a better idea?

  • Author
37 minutes ago, diesieben07 said:

You should be able to do that with RenderWorldLastEvent.

 

Great! That works. Now how do I tell that event to only render when right-click is being held? On the onRightClick method I set a flag to true, but how do I set it to false when right-click isn't being held any more?

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.