Jump to content

Using the DifficultyChangeEvent


BadBichShaquonda

Recommended Posts

Hi everyone,

 

I'm having issues using this event. All I did was add a simple logger to it, and it does not log when I change difficulty through commands in game (/difficulty peaceful), while other events do log properly.

Here is the code:

package com.eon.sharkmod.events;

import com.eon.sharkmod.SharkMod;

import net.minecraft.world.Difficulty;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.DifficultyChangeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;

@Mod.EventBusSubscriber(modid = SharkMod.MOD_ID, bus = Bus.FORGE)
public class DifficultyChangeEventHandler {
	
	@SubscribeEvent
	public static void difficultyChangeEvent(DifficultyChangeEvent event) {
		SharkMod.LOGGER.info("testing");
		Difficulty newDiff = event.getDifficulty();
		SharkMod.LOGGER.info("Hey! New dif: " + newDiff + ", old dif: " + event.getOldDifficulty());
		
	}
}

 

Neither of these logs print. Can anyone point me in the right direction? I've tried changing the bus to MOD, even tho I knew it was dumb (it didn't work).

I was also maybe thinking that this event only fires if the difficulty is changed through actual java code (instead of commands), so I tried this:

this.entity.world.getWorldInfo().setDifficulty(Difficulty.HARD);

First, this did change the difficulty but did not fire the event. I also put this line in the tick() method, and then launched my game and tried changing difficulty with commands all while difficulty was changing with the every tick, but nothing logged.

 

What am I doing wrong? Is there some other way of knowing when the difficulty changes? I'd like to adjust my shark's ai goals and stats

 

Thank you!

Link to comment
Share on other sites

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.