chylex Posted April 12, 2013 Posted April 12, 2013 Hello, I've been trying to make this working for several hours and it's getting frustrating I'm trying to register an event in @Init (tried @PreInit too) method, but it's never firing. I can register the event in load() or the mod constructor, but it only works in the client, if I put the mod on the server, it throws an error. Source code: Reveal hidden contents package cz.chylex.minimod.HeavyAnvils; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.entity.item.EntityFallingSand; import net.minecraft.server.MinecraftServer; import net.minecraft.src.BaseMod; import net.minecraft.src.ModLoader; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @Mod(modid="chylex_HeavyAnvils", name="Heavy Anvils", version="1.0") @NetworkMod(clientSideRequired=false, serverSideRequired=false) public class mod_HeavyAnvils extends BaseMod{ @Instance("chylex_HeavyAnvils") public static mod_HeavyAnvils instance; private Set<EntityFallingSand> anvils = new HashSet<EntityFallingSand>(); @Init public void initialize(FMLInitializationEvent event){ // <-- never fires System.out.println("test"); MinecraftForge.EVENT_BUS.register(this); } @Override public String getName(){ return "MM Heavy Anvils"; } @Override public String getVersion(){ return "1.0"; } @Override public void load(){ //MinecraftForge.EVENT_BUS.register(this); <-- this works in client, server throws error ModLoader.setInGameHook(this,true,true); } @SideOnly(Side.CLIENT) @Override public boolean onTickInGame(float time, Minecraft minecraftInstance){ onTick(); return true; } @SideOnly(Side.SERVER) @Override public boolean onTickInGame(MinecraftServer minecraftServer){ onTick(); return true; } private void onTick(){ for(Iterator<EntityFallingSand> iter=anvils.iterator(); iter.hasNext(){ EntityFallingSand e=iter.next(); if (e.onGround){ int x=(int)Math.floor(e.posX),y=(int)Math.floor(e.posY-1),z=(int)Math.floor(e.posZ); int block=e.worldObj.getBlockId(x,y,z); if (block==Block.glass.blockID||block==Block.thinGlass.blockID||block==Block.glowStone.blockID){ e.worldObj.setBlock(x,y,z,0); } iter.remove(); } } } @ForgeSubscribe public void onEntityJoinWorld(EntityJoinWorldEvent e){ if (!e.world.isRemote&&e.entity instanceof EntityFallingSand){ EntityFallingSand fs=(EntityFallingSand)e.entity; if (fs.blockID==Block.anvil.blockID)anvils.add(fs); } } } The "test" message never shows up, and the event isn't registered. If I register it inside the constructor or load(), client works flawlessly, but this error shows up on the server (started it inside Eclipse, but the same error is thrown if I run the server from .jar and put the mod inside mods folder): Reveal hidden contents 2013-04-12 15:14:11 [iNFO] [ForgeModLoader] Forge Mod Loader version 5.1.8.611 for Minecraft 1.5.1 loading 2013-04-12 15:14:11 [iNFO] [ForgeModLoader] Java is Java HotSpot 64-Bit Server VM, version 1.7.0_02, running on Windows 7:amd64:6.1, installed at C:\Program Files\Java\jre7 2013-04-12 15:14:11 [iNFO] [ForgeModLoader] Managed to load a deobfuscated Minecraft name- we are in a deobfuscated environment. Skipping runtime deobfuscation 2013-04-12 15:14:11 [iNFO] [sTDOUT] 229 recipes 2013-04-12 15:14:11 [iNFO] [sTDOUT] 27 achievements 2013-04-12 15:14:12 [iNFO] [Minecraft-Server] Starting minecraft server version 1.5.1 2013-04-12 15:14:12 [iNFO] [MinecraftForge] Attempting early MinecraftForge initialization 2013-04-12 15:14:12 [iNFO] [sTDOUT] MinecraftForge v7.7.1.611 Initialized 2013-04-12 15:14:12 [iNFO] [ForgeModLoader] MinecraftForge v7.7.1.611 Initialized 2013-04-12 15:14:12 [iNFO] [sTDOUT] Replaced 85 ore recipies 2013-04-12 15:14:12 [iNFO] [MinecraftForge] Completed early MinecraftForge initialization 2013-04-12 15:14:12 [iNFO] [ForgeModLoader] Reading custom logging properties from D:\MCP\MCP7_151_minimods_forge\mcp\jars\config\logging.properties 2013-04-12 15:14:12 [OFF] [ForgeModLoader] Logging level for ForgeModLoader logging is set to ALL 2013-04-12 15:14:12 [iNFO] [ForgeModLoader] Searching D:\MCP\MCP7_151_minimods_forge\mcp\jars\mods for mods 2013-04-12 15:14:13 [iNFO] [ForgeModLoader] Forge Mod Loader has identified 4 mods to load 2013-04-12 15:14:13 [iNFO] [mcp] Activating mod mcp 2013-04-12 15:14:13 [iNFO] [FML] Activating mod FML 2013-04-12 15:14:13 [iNFO] [Forge] Activating mod Forge 2013-04-12 15:14:13 [iNFO] [mod_HeavyAnvils] Activating mod mod_HeavyAnvils 2013-04-12 15:14:13 [iNFO] [ForgeModLoader] Configured a dormant chunk cache size of 0 2013-04-12 15:14:13 [iNFO] [Minecraft-Server] Loading properties 2013-04-12 15:14:13 [iNFO] [Minecraft-Server] Default game type: SURVIVAL 2013-04-12 15:14:13 [iNFO] [Minecraft-Server] Generating keypair 2013-04-12 15:14:13 [iNFO] [Minecraft-Server] Starting Minecraft server on *:25565 2013-04-12 15:14:13 [WARNING] [Minecraft-Server] **** SERVER IS RUNNING IN OFFLINE/INSECURE MODE! 2013-04-12 15:14:13 [WARNING] [Minecraft-Server] The server will make no attempt to authenticate usernames. Beware. 2013-04-12 15:14:13 [WARNING] [Minecraft-Server] While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose. 2013-04-12 15:14:13 [WARNING] [Minecraft-Server] To change this, set "online-mode" to "true" in the server.properties file. 2013-04-12 15:14:13 [iNFO] [sTDERR] java.lang.NoClassDefFoundError: net/minecraft/client/multiplayer/NetClientHandler 2013-04-12 15:14:13 [iNFO] [sTDERR] at java.lang.Class.getDeclaredMethods0(Native Method) 2013-04-12 15:14:13 [iNFO] [sTDERR] at java.lang.Class.privateGetDeclaredMethods(Unknown Source) 2013-04-12 15:14:13 [iNFO] [sTDERR] at java.lang.Class.privateGetPublicMethods(Unknown Source) 2013-04-12 15:14:13 [iNFO] [sTDERR] at java.lang.Class.privateGetPublicMethods(Unknown Source) 2013-04-12 15:14:13 [iNFO] [sTDERR] at java.lang.Class.getMethods(Unknown Source) 2013-04-12 15:14:13 [iNFO] [sTDERR] at net.minecraftforge.event.EventBus.register(EventBus.java:28) 2013-04-12 15:14:13 [iNFO] [sTDERR] at cz.chylex.minimod.HeavyAnvils.mod_HeavyAnvils.load(mod_HeavyAnvils.java:49) 2013-04-12 15:14:13 [iNFO] [sTDERR] at cpw.mods.fml.common.modloader.ModLoaderModContainer.init(ModLoaderModContainer.java:537) 2013-04-12 15:14:13 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2013-04-12 15:14:13 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 2013-04-12 15:14:13 [iNFO] [sTDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 2013-04-12 15:14:13 [iNFO] [sTDERR] at java.lang.reflect.Method.invoke(Unknown Source) 2013-04-12 15:14:13 [iNFO] [sTDERR] at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) 2013-04-12 15:14:13 [iNFO] [sTDERR] at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45) 2013-04-12 15:14:13 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) 2013-04-12 15:14:13 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) 2013-04-12 15:14:13 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.post(EventBus.java:267) 2013-04-12 15:14:13 [iNFO] [sTDERR] at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:165) 2013-04-12 15:14:13 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2013-04-12 15:14:13 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 2013-04-12 15:14:13 [iNFO] [sTDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 2013-04-12 15:14:13 [iNFO] [sTDERR] at java.lang.reflect.Method.invoke(Unknown Source) 2013-04-12 15:14:13 [iNFO] [sTDERR] at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) 2013-04-12 15:14:13 [iNFO] [sTDERR] at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45) 2013-04-12 15:14:13 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) 2013-04-12 15:14:13 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) 2013-04-12 15:14:13 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.post(EventBus.java:267) 2013-04-12 15:14:13 [iNFO] [sTDERR] at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:98) 2013-04-12 15:14:13 [iNFO] [sTDERR] at cpw.mods.fml.common.Loader.initializeMods(Loader.java:689) 2013-04-12 15:14:13 [iNFO] [sTDERR] at cpw.mods.fml.server.FMLServerHandler.finishServerLoading(FMLServerHandler.java:93) 2013-04-12 15:14:13 [iNFO] [sTDERR] at cpw.mods.fml.common.FMLCommonHandler.onServerStarted(FMLCommonHandler.java:357) 2013-04-12 15:14:13 [iNFO] [sTDERR] at net.minecraft.server.dedicated.DedicatedServer.startServer(DedicatedServer.java:140) 2013-04-12 15:14:13 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:429) 2013-04-12 15:14:13 [iNFO] [sTDERR] at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16) 2013-04-12 15:14:13 [iNFO] [sTDERR] Caused by: java.lang.ClassNotFoundException: net.minecraft.client.multiplayer.NetClientHandler 2013-04-12 15:14:13 [iNFO] [sTDERR] at cpw.mods.fml.relauncher.RelaunchClassLoader.findClass(RelaunchClassLoader.java:211) 2013-04-12 15:14:13 [iNFO] [sTDERR] at java.lang.ClassLoader.loadClass(Unknown Source) 2013-04-12 15:14:13 [iNFO] [sTDERR] at java.lang.ClassLoader.loadClass(Unknown Source) 2013-04-12 15:14:13 [iNFO] [sTDERR] ... 34 more 2013-04-12 15:14:13 [iNFO] [sTDERR] Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/multiplayer/NetClientHandler for invalid side SERVER 2013-04-12 15:14:13 [iNFO] [sTDERR] at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:50) 2013-04-12 15:14:13 [iNFO] [sTDERR] at cpw.mods.fml.relauncher.RelaunchClassLoader.runTransformers(RelaunchClassLoader.java:292) 2013-04-12 15:14:13 [iNFO] [sTDERR] at cpw.mods.fml.relauncher.RelaunchClassLoader.findClass(RelaunchClassLoader.java:199) 2013-04-12 15:14:13 [iNFO] [sTDERR] ... 36 more 2013-04-12 15:14:13 [sEVERE] [Minecraft-Server] Encountered an unexpected exception NoClassDefFoundError java.lang.NoClassDefFoundError: net/minecraft/client/multiplayer/NetClientHandler at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.privateGetPublicMethods(Unknown Source) at java.lang.Class.privateGetPublicMethods(Unknown Source) at java.lang.Class.getMethods(Unknown Source) at net.minecraftforge.event.EventBus.register(EventBus.java:28) at cz.chylex.minimod.HeavyAnvils.mod_HeavyAnvils.load(mod_HeavyAnvils.java:49) at cpw.mods.fml.common.modloader.ModLoaderModContainer.init(ModLoaderModContainer.java:537) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) at com.google.common.eventbus.EventBus.post(EventBus.java:267) at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:165) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) at com.google.common.eventbus.EventBus.post(EventBus.java:267) at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:98) at cpw.mods.fml.common.Loader.initializeMods(Loader.java:689) at cpw.mods.fml.server.FMLServerHandler.finishServerLoading(FMLServerHandler.java:93) at cpw.mods.fml.common.FMLCommonHandler.onServerStarted(FMLCommonHandler.java:357) at net.minecraft.server.dedicated.DedicatedServer.startServer(DedicatedServer.java:140) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:429) at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16) Caused by: java.lang.ClassNotFoundException: net.minecraft.client.multiplayer.NetClientHandler at cpw.mods.fml.relauncher.RelaunchClassLoader.findClass(RelaunchClassLoader.java:211) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 34 more Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/multiplayer/NetClientHandler for invalid side SERVER at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:50) at cpw.mods.fml.relauncher.RelaunchClassLoader.runTransformers(RelaunchClassLoader.java:292) at cpw.mods.fml.relauncher.RelaunchClassLoader.findClass(RelaunchClassLoader.java:199) ... 36 more 2013-04-12 15:14:13 [sEVERE] [Minecraft-Server] This crash report has been saved to: D:\MCP\MCP7_151_minimods_forge\mcp\jars\.\crash-reports\crash-2013-04-12_15.14.13-server.txt I have no idea why it's trying to load the NetClientHandler class on the server, just because I'm trying to register an event, can't find any references to that class in my mod, I'm simply clueless. I have the latest Forge version for 1.5.1 (just to be 100% sure, I redownloaded it about 30 minutes ago). Thanks for help Quote
SanAndreaP Posted April 12, 2013 Posted April 12, 2013 Quote public class mod_HeavyAnvils extends BaseMod seriously? Quote Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter Quote This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
chylex Posted April 12, 2013 Author Posted April 12, 2013 On 4/12/2013 at 5:03 PM, SanAndreasP said: Quote public class mod_HeavyAnvils extends BaseMod seriously? Oops, somehow I automatically assumed it was supposed to work like that, didn't realize it's just for ModLoader compatibility... Explains many weird things I've encountered, anyways it works now, thanks a lot Quote
Recommended Posts
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.