Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

My IDE says

onDifficultyChange(Difficulty difficulty, Difficulty oldDifficulty)

in ForgeHooks is never called in all places, not sure why is this happening

  • Author

Can this potentially be a forge bug?

 

EDIT: I was also trying to figure out how/where in the code, zombies despawn when changing to peaceful. Couldn't find it tho

Edited by BadBichShaquonda

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.