Jump to content

[1.10] Render a block in the world


zerofall

Recommended Posts

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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

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.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.