Posted May 14, 20205 yr The version is 1.15. I want something to happen when the block the player is looking at is the same as whatever block. So it would be somethis like this if(the block the player is looking at == Blocks.a block) { } I just don't know how to check.
May 14, 20205 yr Entity#pick may be the method you want to use; it emits a ray that collides with blocks in the world. The first parameter is the range, the second is the "partial ticks" (you can just put a value of 1), and the third is if it should work on fluids. The returned RayTraceResult will tell you what kind of thing it hit, as well as its position. From there, you can get the block at that position. I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.
May 14, 20205 yr What are you even trying to do? If you're trying to interact with a block you can just override onBlockActivated in your block class. Read the vanilla code for the crafting table. I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.
May 14, 20205 yr Author I want to get an item in my inventory when i rightclick a specific block with a specigic item. I did the item part with an if in an event class. Can i put another if inside the first one that checks if the block is the right one? Edited May 14, 20205 yr by martiblq
May 14, 20205 yr 8 minutes ago, martiblq said: I want to get an item in my inventory when i rightclick a specific block with a specigic item. I did the item part with an if in an event class. Can i put another if inside the first one that checks if the block is the right one? If at least one of those is something you added raytracing is redundant. 11 minutes ago, imacatlolol said: If you're trying to interact with a block you can just override onBlockActivated in your block class. Edited May 14, 20205 yr by Novârch It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".
May 14, 20205 yr 10 minutes ago, martiblq said: I want to get an item in my inventory when i rightclick a specific block with a specigic item. I did the item part with an if in an event class. Can i put another if inside the first one that checks if the block is the right one? If the block you're trying use is your own block, just override onBlockActivated as I mentioned and put in the code to check the item in your hand. If the item you're using is your own item, override the item's onItemUse function. If neither of them are your own, use the PlayerInteractEvent$RightClickBlock event. I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.
May 14, 20205 yr Author Spoiler if(event.getPlayer().getHeldItem(Hand.MAIN_HAND).getItem() == Items.NETHER_STAR) { } this is the code for the held item. i can't just paste it in the block Edited May 14, 20205 yr by martiblq
May 14, 20205 yr 4 minutes ago, martiblq said: Reveal hidden contents if(event.getPlayer().getHeldItem(Hand.MAIN_HAND).getItem() == Items.NETHER_STAR) { } this is the code for the held item. i can't just paste it in the block Of course you can't, 39 minutes ago, imacatlolol said: use the PlayerInteractEvent$RightClickBlock event. It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".
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.