martiblq Posted May 14, 2020 Posted May 14, 2020 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. Quote
imacatlolol Posted May 14, 2020 Posted May 14, 2020 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. Quote I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.
martiblq Posted May 14, 2020 Author Posted May 14, 2020 (edited) is thet how the crafting table do it? Edited May 14, 2020 by martiblq Quote
imacatlolol Posted May 14, 2020 Posted May 14, 2020 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. Quote I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.
martiblq Posted May 14, 2020 Author Posted May 14, 2020 (edited) 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, 2020 by martiblq Quote
Novârch Posted May 14, 2020 Posted May 14, 2020 (edited) 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, 2020 by Novârch Quote 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".
imacatlolol Posted May 14, 2020 Posted May 14, 2020 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. Quote I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.
martiblq Posted May 14, 2020 Author Posted May 14, 2020 (edited) 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, 2020 by martiblq Quote
Novârch Posted May 14, 2020 Posted May 14, 2020 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. Quote 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".
Recommended Posts
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.