Posted February 3, 20178 yr 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); }
February 3, 20178 yr Author 4 minutes ago, diesieben07 said: So, do you want the block to hide again when the player releases the button? Yes, I do.
February 3, 20178 yr 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?
February 3, 20178 yr 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.