Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [Solved] [1.15.2] Events are not fired
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 2
uiytt

[Solved] [1.15.2] Events are not fired

By uiytt, March 22, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

uiytt    4

uiytt

uiytt    4

  • Stone Miner
  • uiytt
  • Members
  • 4
  • 67 posts
Posted March 22, 2020 (edited)

Hi, I really don't understand why my even is never fired...

package fr.uiytt.test;
import net.minecraftforge.event.DifficultyChangeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class Events {

	
	@SubscribeEvent
	public void test(final DifficultyChangeEvent event) {
		System.out.println("test1 " + event.getDifficulty().getTranslationKey());
	}
	
	
}

 

I have declared it in my mod main class with :

MinecraftForge.EVENT_BUS.register(new Events());

Thanks for your help

Edited March 23, 2020 by uiytt
  • Quote

Share this post


Link to post
Share on other sites

MyRedAlien43    0

MyRedAlien43

MyRedAlien43    0

  • Tree Puncher
  • MyRedAlien43
  • Members
  • 0
  • 37 posts
Posted March 22, 2020

I'm pretty sure you need to register the class itself, not an instance of it....
Correct me if I'm wrong

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2402

Draco18s

Draco18s    2402

  • Reality Controller
  • Draco18s
  • Members
  • 2402
  • 15924 posts
Posted March 22, 2020
9 minutes ago, MyRedAlien43 said:

I'm pretty sure you need to register the class itself, not an instance of it....
Correct me if I'm wrong

You can do either.

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

MyRedAlien43    0

MyRedAlien43

MyRedAlien43    0

  • Tree Puncher
  • MyRedAlien43
  • Members
  • 0
  • 37 posts
Posted March 22, 2020
1 hour ago, Draco18s said:

You can do either.

I am irrelevant then

  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    818

TheGreyGhost

TheGreyGhost    818

  • Reality Controller
  • TheGreyGhost
  • Members
  • 818
  • 3280 posts
Posted March 23, 2020

You can register either the class or an instance, but it affects which methods get checked for events!

 

If you register the class: static methods are checked for events

If you register an instance of the class, non-static methods are checked for events.

 

In this case I think you've registered it correctly.

I suggest you troubleshoot it by putting a breakpoint in the forge code, at the point that it posts the DifficultyChangeEvent.

That will tell you if your registration has failed.

(Search project and library for usages of DifficultyChangeEvent)

 

-TGG

  • Thanks 1
  • Quote

Share this post


Link to post
Share on other sites

uiytt    4

uiytt

uiytt    4

  • Stone Miner
  • uiytt
  • Members
  • 4
  • 67 posts
Posted March 23, 2020
10 hours ago, TheGreyGhost said:

You can register either the class or an instance, but it affects which methods get checked for events!

 

If you register the class: static methods are checked for events

If you register an instance of the class, non-static methods are checked for events.

 

In this case I think you've registered it correctly.

I suggest you troubleshoot it by putting a breakpoint in the forge code, at the point that it posts the DifficultyChangeEvent.

That will tell you if your registration has failed.

(Search project and library for usages of DifficultyChangeEvent)

 

-TGG

AH

it seems that the problem only comes from DifficultyChangeEvent.
I don't care about this event, I only used it as a test, it works fine with another event...

So yeah my events work :D

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 2
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Wintersky20
      Modifying / Replacing Vanilla Blocks (1.16.X)

      By Wintersky20 · Posted 17 minutes ago

      Ok , I'll try it  Thanks for the replay I'll let you know if is working 
    • AurenX
      Modifying / Replacing Vanilla Blocks (1.16.X)

      By AurenX · Posted 22 minutes ago

      Note: I am using registry events instead of deferred registry so if someone chimes in on a difference that works better than listen to them. this method still works so i am yet to be motivated to change. I am able to replace blocks using the RegistryEvent.Register<Block>. I get the old resource location ForgeRegistries.BLOCKS.getKey(oldBlock); and set the custom block with that blocks registry location newBlock.setRegistryName(resourceLocation); ForgeRegistries.BLOCKS.register(newBlock); I also replace the Item (again i dont know if this is still needed as doing so still works so i have yet to change it)
    • Thorius
      I don't know how forge works

      By Thorius · Posted 32 minutes ago

      Did you run your server?  
    • Wintersky20
      Modifying / Replacing Vanilla Blocks (1.16.X)

      By Wintersky20 · Posted 34 minutes ago

      Ok guys .. So , I'm trying to replace a vanilla block in 1.16.4 but no luck! First I created a Workspace like I always do .. I created a block class for my replaced block: public class ExempleBlock extends CactusBlock /*just an ex.*/ { public ExempleBlock() { super(AbstractBlock.Properties.from(Blocks.CACTUS)); } } Then I tried to register it : First method( copied from an old 1.12 mod by rwTema ) @Mod.EventHandler/* not in 1.16*/ public void preinit(FMLPreInitializationEvent event) {/* not in 1.16 , I think*/ Block blockDietHopper = new BlockDietHopper(); ForgeRegistries.BLOCKS.register(blockDietHopper); } Then I tried to do this with a new registry event //from the exemple mod private void setup(final FMLCommonSetupEvent event){ Block ex = new ExempleBlock(); ForgeRegistries.BLOCKS.register(ex); } no luck Then I tried this : @Mod(ExempleMain.MOD_ID) public class ExempleMain { public static final String MOD_ID = "id"; private static final Logger LOGGER = LogManager.getLogger(); public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "minecraft"); public static final RegistryObject<Block> BETTER_EXEMPLE = BLOCKS.register("exemple_block", () -> new ExempleBlock()); public ExempleMain() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener(this::setup); ExempleMain.BLOCKS.register(bus); } private void setup(final FMLCommonSetupEvent event){} } No luck   The idea is , I want to modify the TileEntity or the TESR for the vanilla blocks (ex: tools hovering on enchanting table , Nethar anchor GUI, Composter GUI, etc)   Note: I use IntelliJ and mdk-1.16.4-35.1.37   And Thanks for every topic
    • Mark74
      I don't know how forge works

      By Mark74 · Posted 38 minutes ago

      I dont have that folder, should i create it?
  • Topics

    • Wintersky20
      2
      Modifying / Replacing Vanilla Blocks (1.16.X)

      By Wintersky20
      Started 34 minutes ago

    • Mark74
      4
      I don't know how forge works

      By Mark74
      Started 1 hour ago

    • Klarks
      39
      [1.16.4] How i can open a container by clicking on my mob

      By Klarks
      Started Saturday at 09:56 PM

    • MKR0902
      0
      1.12.2 Forge Server Not starting with command arguements

      By MKR0902
      Started 58 minutes ago

    • Amazinwave
      0
      Amazinwave

      By Amazinwave
      Started 1 hour ago

  • Who's Online (See full list)

    • Thorius
    • Talp1
    • Trynthlas
    • Rosy162
    • Jason_Whittaker
    • DoctorC
    • AubriTheHuman
    • AurenX
    • Wintersky20
    • Formal Feather
    • babyfarkmcgeezax
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [Solved] [1.15.2] Events are not fired
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community