Jump to content

ModEventHandler not working for me


X_Pilot

Recommended Posts

Hello,

 

can you guys help me fix this? It isn't working. I'm trying to make a global warming mod for minecraft as a school project, yet I cannot update an index that is meant to be saved and loaded. Here's my code:

package greg;

import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;

import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.storage.WorldInfo;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import net.minecraftforge.event.world.BlockEvent.PlaceEvent;
import net.minecraftforge.fml.common.Mod.EventHandler;

public class ModEventHandler {

public ArrayList<PollutionLevel> list = new ArrayList<PollutionLevel>();

FileFunctions files = new FileFunctions();

public static int pollutionIndex;
ArrayList<World> initialWorld;
WorldInfo infoWorld = new WorldInfo() {};
public static String worldName;
public static int integer;

public void load(World world){

	worldName = infoWorld.getWorldName();
	int ind;
	files.ReadFromFile(list);

	if(!list.contains(worldName))
	{
		pollutionIndex = 0;     
	}
	else
	{
		ind = list.indexOf(worldName);
		pollutionIndex = list.get(ind).getPol();
		//meant to set the correct pol level

	}
}
@EventHandler
public void onBlockDestroyedByPlayer(BreakEvent event)
{
	pollutionIndex = pollutionIndex + 2;
	if(event.state.getBlock().isWood(event.world, event.pos) == true)
	{
		pollutionIndex = pollutionIndex + 2;
	}
}

@EventHandler
public void onBlockPlacedByPlayer(PlaceEvent event)
{
	int ind;
	if(event.placedBlock.getBlock().isWood(event.world, event.pos) == true)
	{
		pollutionIndex = pollutionIndex - 1;

		if(!list.contains(worldName))
		{
			list.add(new PollutionLevel(worldName, pollutionIndex));
		}
		else
		{
			ind = list.indexOf(worldName);
			list.remove(ind);
			list.add(new PollutionLevel(worldName, pollutionIndex));
		}
	}
}
public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state) {
	pollutionIndex = pollutionIndex +2;
}

}

 

The onBlockDestroyedByPlayer is just testing to see if the class worked, but it doesn't so yeah. I really need help.

 

Here's my main class:

 

package greg;

import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;

import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.world.storage.WorldInfo;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;

@Mod(modid=info.ID, name=info.NAME, version=info.VERS)


public class main {



@Instance(value = "mainID")
public static main instance;


@SidedProxy(clientSide=info.CLIENT + ".ClientProxy", serverSide=info.COMMON + ".CommonProxy")
public static CommonProxy proxy;

@EventHandler
public void preInit(net.minecraftforge.fml.common.event.FMLPreInitializationEvent event) {
	// Stub Method
	MinecraftForge.EVENT_BUS.register(new ModEventHandler());
}

@EventHandler
public void init(FMLInitializationEvent event){
	proxy.registerRenderers();

	MinecraftForge.EVENT_BUS.register(new ModEventHandler());
	MinecraftForge.EVENT_BUS.register(new HUDPol(Minecraft.getMinecraft()));

}


@EventHandler
public void postInit(net.minecraftforge.fml.common.event.FMLPostInitializationEvent event) {
	// Stub Method

}



}



 

Thanks!

Link to comment
Share on other sites

For listening to events from event buses, use @SubscribeEvent. If you look at the Javadocs for @EventHandler, you would see that it is mainly used to manage the lifecycle of your mod

 

I changed it and now I get this crash-log:

 

---- Minecraft Crash Report ----
// On the bright side, I bought you a teddy bear!

Time: 11/17/15 7:26 AM
Description: Initializing game

java.lang.IllegalArgumentException: Method public void greg.ModEventHandler.load(net.minecraft.world.World) has @SubscribeEvent annotation, but takes a argument that is not an Event class net.minecraft.world.World
at net.minecraftforge.fml.common.eventhandler.EventBus.register(EventBus.java:82)
at greg.main.init(main.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:731)
at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:316)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:528)
at net.minecraft.client.Minecraft.run(Minecraft.java:356)
at net.minecraft.client.main.Main.main(Main.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at net.minecraftforge.fml.common.eventhandler.EventBus.register(EventBus.java:82)
at greg.main.init(main.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:731)
at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:316)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:528)

-- Initialization --
Details:
Stacktrace:
at net.minecraft.client.Minecraft.run(Minecraft.java:356)
at net.minecraft.client.main.Main.main(Main.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)

-- System Details --
Details:
Minecraft Version: 1.8
Operating System: Mac OS X (x86_64) version 10.10.5
Java Version: 1.8.0_40, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 663116824 bytes (632 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.10 FML v8.0.99.99 Minecraft Forge 11.14.3.1543 4 mods loaded, 4 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
UCHI	mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) 
UCHI	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.8-11.14.3.1543.jar) 
UCHI	Forge{11.14.3.1543} [Minecraft Forge] (forgeSrc-1.8-11.14.3.1543.jar) 
UCHE	GWM{0.0.1} [Global Warming Mod] (bin) 
Loaded coremods (and transformers): 
Launched Version: 1.8
LWJGL: 2.9.2
OpenGL: Intel HD Graphics 3000 OpenGL Engine GL version 2.1 INTEL-10.0.35, Intel Inc.
GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because ARB_framebuffer_object is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

Using VBOs: No
Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: []
Current Language: English (US)
Profiler Position: N/A (disabled)

 

Help?

Link to comment
Share on other sites

You should not be calling it at all, you should not be having it. You should be using WorldSavedData, as I said.

 

Can I modify the class? Or how do you suggest I implement it? I was planning on having my own ArrayList to store the data and then retrieve it, which is what the load(World) functions does. I was going to have the unload(World) function saving the data.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • @bluedisgusted That actually fully fixed it, thank you so much
    • Hi, I would like to know how to create multiple hitboxes for the player like the ender dragon. I've searched everywhere but I haven't found anything.
    • FOLKWIN EXPERT RECOVERY is the crypto hero we all need in the ongoing battle against cryptocurrency theft. With the rise in popularity of digital assets like Bitcoin and Ethereum, crypto crime has also been on the rise as hackers look to steal funds stored in virtual wallets. Many a crypto investor has fallen victim to clever scams and hacking schemes that drain wallets of their precious coins. But fear not, for FOLKWIN EXPERT RECOVERY has arrived as a beacon of hope for those who have had their hard-earned crypto stolen. This service is like a superhero for tracking down lost or stolen cryptocurrency, utilizing their advanced forensic technology and expertise to follow the blockchain paper trail and identify where your funds have gone. Their team of ethical hackers act like detectives, piecing together crypto transactions and unmasking the thieves behind complex cybercrimes. No case is too difficult for FOLKWIN EXPERT RECOVERY; they have recovered millions in stolen crypto assets from around the globe. Their mission is to reunite victims with their lost funds and bring criminals who prey on cryptocurrency investors to justice. With their help, those who have been robbed of their digital fortunes now have a crypto guardian to call upon in their time of need. FOLKWIN EXPERT RECOVERY gives victims the hope that all is not lost forever when crypto theft occurs.For support, Contact details is: TELEGRAM: @FOLKWIN_EXPERT_RECOVERY, EMAIL: FOLKWINEXPERTRECOVERY at TECH-CENTER dot COM, WEBSITE: WWW.FOLKWINEXPERTRECOVERY.COM .  are the heroes we need in the ongoing battle to make cryptocurrency ownership safe and secure for all. Get FOLKWIN EXPERT RECOVERY on your side when you have issues like this by dialing: Do this and thank me later. God Blessings to all, I'm forever grateful oh God for the successful recovery. I recommend FOLKWIN EXPERT RECOVERY the best ever and i'm so happy i got all my lost money back. Best Regards. Pamela K Ingram.
    • Made it work. As a note, one of the times it didn't recognize the recipe cause the MOD_ID constant I was using somewhere was NOT referencing my MOD_ID but rather another static variable with the same name. Maybe OP is having a similar problem
    • What exactly is the issue?
  • Topics

×
×
  • Create New...

Important Information

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