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

Can someone please explain to me what is wrong with this class? I have registered it in my CommonProxy class but it doesn't seem to register properly. None of the events inside the class seem to work.

I used MinecraftForge.EVENT_BUS.register(new IYPEventHandler()); under init in my CommonProxy class, I also tried to put it under preInit which did nothing.

EventHandler Class:

 

public class IYPEventHandler {

public static Random random;
public static double rand;
public Random r = new Random();

@SubscribeEvent
public void onEntityDrop(LivingDropsEvent event){
	if(event.entityLiving instanceof EntityWolf){
	if(r.nextInt(100/100) == 0){
	if(event.entity.isBurning())
		event.entityLiving.dropItem(IYPItems.CookedWolf, r.nextInt(3) + 1);
	}
	else{
		event.entityLiving.dropItem(IYPItems.RawWolf, r.nextInt(3) + 1);
		}
	}
@SubscribeEvent
public void onBlockBreak(BreakEvent event){
	EntityPlayer player = event.getPlayer();

			if (!player.capabilities.isCreativeMode && player.isPotionActive(IYPItems.SpicyPotion));
				EntityItem item = new EntityItem(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ(), new ItemStack(event.state.getBlock()));
				event.world.spawnEntityInWorld(item);
}

 

Any help appreciated

Aside from several serious Java errors (e.g. a semi-colon after a condition: 'if (condition);') and formatting issues (e.g. funky / unclear nesting of if statements), it is possible that you aren't actually calling whatever CommonProxy method is supposed to register it.

 

Show your CommonProxy and your main class.

if(r.nextInt(100/100) == 0)

 

Why do you have math here?

 

if(r.nextInt(1) == 0)

 

Or better yet

 

if(true)

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.

Or better yet

 

*crickets*

 

I figured that was self-evident. ;D

But yes, ommiting the line entirely would be equivalent.

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.

  • Author

The reason I have the math is because I'm going to change the chance and it was just one way I thought of doing chance out of 100. Here is my CommonProxy class

 

public class CommonProxy {

public void preInit(FMLPreInitializationEvent preEvent){


	IYPBlocks.initBlocks();
	IYPItems.initItems();

	IYPRecipes.initRecipes();
	IYPSmelting.initSmelting();

}

public void init(FMLInitializationEvent event){

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

}

public void postInit(FMLPostInitializationEvent postEvent){

}
}

 

Main Modding Class:

 


@Mod(modid = IYPGlobal.MOD_ID, name = IYPGlobal.MOD_NAME, version = IYPGlobal.VERSION)

public class Main {

@Instance(IYPGlobal.MOD_ID)
public static Main instance;

@SidedProxy(clientSide = IYPGlobal.IYP_CLIENT_PROXY, serverSide = IYPGlobal.IYP_COMMON_PROXY)
public static CommonProxy proxy;

@EventHandler
public void preInit(FMLPreInitializationEvent preEvent){

	this.proxy.preInit(preEvent);
}

@EventHandler
public void init(FMLInitializationEvent event){

	this.proxy.init(event);
}

@EventHandler
public void postInit(FMLPostInitializationEvent postEvent){

	this.proxy.postInit(postEvent);
}
}

Your event handler class name:

 

public class IYPEventHandler

 

How you're registering the event in CommonProxy:

 

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

 

Notice anything peculiar? :)

  • Author

Yeah I saw that and changed it, it still doesn't work though, the class was originally called IYPDropHandler and I changed it to IYPEventHandler, even with IYPEventHandler registered in my CommonProxy class, I'm still having the original issue.

  • Author

Everything seems correct, I get no errors in my console... I'm guessing the EventHandler class just isn't registering properly

  • Author

Sorry about the inconvenience but for some reason it randomly started working now, I reset eclipse and it works fine now, thanks though everyone!

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.