Posted November 16, 20159 yr 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!
November 16, 20159 yr 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 catch(Exception e) { } Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).
November 17, 20159 yr Author 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?
November 17, 20159 yr Author Where do you call load(World)? Also, you should probably use a WorldSavedData for this. Where should I call load(World)? I don't think I am currently calling it
November 17, 20159 yr Author 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.
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.