Posted April 4, 20196 yr This is expected, but how can I modify my public static void onPlayerWakeUp(final PlayerWakeUpEvent) method so that it runs some code only if I wake up in the morning after successful sleep (i.e, only if I go to bed at night and wake up in the morning without pressing "leave bed") I tried accessing the PlayerWakeUpEvent::getEntityPlayer().world.getDayTime(), but it always returns the time right before I wake up, not after. Here's the code, though I don't think you'll need it: public Main() { instance = this; FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(EventHandler.class); } ... public static class EventHandler { @SubscribeEvent public static void onPlayerWakeUp(final PlayerWakeUpEvent playerWakeUpEvent) { LOGGER.info("{"); LOGGER.info("\tPlayerWakeUpEvent fired."); LOGGER.info("\t" + playerWakeUpEvent.getEntityPlayer().world.getDayTime()); if(playerWakeUpEvent.getEntityPlayer().world.getDayTime() == 0) { LOGGER.info("\tIs day."); IBlockState blockUp = playerWakeUpEvent.getEntityPlayer().world.getBlockState(playerWakeUpEvent.getEntityPlayer().getPosition().up()); LOGGER.info( "\t" + blockUp ); if(blockUp.getBlock() instanceof ModBlockDreamcatcher) { LOGGER.info("\tFound a dreamcatcher above the bed's head."); switch(blockUp.getBlock().getRegistryName().toString()) { case "two:dreamcatcher_loot": LOGGER.info("\tFound a Loot Dreamcatcher! (Gimme the loot!)"); break; default: LOGGER.info("\tFound a dreamcatcher " + ((ModBlockDreamcatcher)blockUp).getRegistryName().toString() + " that didn't match a registry name. "); } } else { LOGGER.info("\tFound a block above the bed's head that wasn't a dreamcatcher. What a disappointment. "); LOGGER.info("\tIt was " + blockUp.getBlock()); } } LOGGER.info("}"); } }
April 8, 20196 yr You can check the time when the event triggers. Also, I would avoid logging pointless info when publishing the mod. This can fill up the log quickly, making useful information hard to find. On 4/5/2019 at 5:26 AM, fallOut015 said: LOGGER.info("\tFound a block above the bed's head that wasn't a dreamcatcher. What a disappointment. "); Edited April 8, 20196 yr by DavidM I can't read Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
April 9, 20196 yr Author 23 hours ago, DavidM said: You can check the time when the event triggers. Also, I would avoid logging pointless info when publishing the mod. This can fill up the log quickly, making useful information hard to find. I'm gonna get rid of all the logger lines when it's published. Also, I tried checking the time, and it just returns the time right before I wake up. Maybe it's the version of forge I'm using? It is a 1.13 beta after all
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.