Jump to content

Recommended Posts

Posted

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("}");
        }
    }

 

Posted (edited)

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 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.

 

 

Posted
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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.