Posted April 23, 20169 yr Hi, I'm confuse with the way the PlayerInteractEvent is working in 1.9 I would guess that the event always would return the coordinates de player is looking at, but apparently, for the Main Hand it does return the block the player is looking at, while for the Off Hand it returns the coordinates the player is standing on. Am I right, or I'm missing something here? This is the code: @SubscribeEvent public void onPlayerInteractEvent(PlayerInteractEvent event) { World world = event.getWorld(); BlockPos pos = event.getPos(); EntityPlayer player = event.getEntityPlayer(); if(!world.isRemote) { System.out.println(event.getPos()); System.out.println(event.getHand()); if(world.getBlockState(pos).getBlock() instanceof BlockCrops) { System.out.println("Crops!!!"); } }//END WORLD NO REMOTE } And here is an screenshot ingame and what is show on console. (It didn't print twice, I did right click twice) PS: How can I tell if the event was triggered by a Left click or a Right click? Thanks a lot.
April 23, 20169 yr In 1.9, PlayerInteractEvent has a separate nested subclass for each type of player interaction. Subscribe to one of these rather than PlayerInteractEvent itself. I suggest you use Log4J like the rest of Minecraft/Forge rather than printing directly to stdout. FMLPreInitializationEvent#getModLog will return a Logger that will log messages with your mod ID, store this somewhere and use it to write to the log. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
April 23, 20169 yr Author Thanks Choonster, I will take a look into that Log4j I'm using the event RightClickBlock now that works way better for what I was needing
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.