Posted September 14, 201411 yr I've been using: EntityPlayer player = (EntityPlayer)event.entity; or: EntityPlayer player = Minecraft.getMinecraft().thePlayer; in my code, but when I try to test it on a server, I get an error on this line in my main class: public static final KeyHandlerEvents keyBinding = new KeyHandlerEvents(); saying: java.lang.NoClassDefFoundError: net/minecraft/client/entity/EntityClientPlayerMP The content of that class is in the spoiler at the bottom. The rest of the error is here if it matters: [18:43:16] [server thread/ERROR]: Encountered an unexpected exception java.lang.NoClassDefFoundError: net/minecraft/client/entity/EntityClientPlayerMP at com.fandomcraft.main.Main.<clinit>(Main.java:198) ~[Main.class:?] at java.lang.Class.forName0(Native Method) ~[?:1.7.0_51] at java.lang.Class.forName(Unknown Source) ~[?:1.7.0_51] at cpw.mods.fml.common.FMLModContainer.constructMod(FMLModContainer.java:420) ~[FMLModContainer.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51] at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?] at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?] at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) ~[LoadController.class:?] at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187) ~[LoadController.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51] at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?] at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?] at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118) ~[LoadController.class:?] at cpw.mods.fml.common.Loader.loadMods(Loader.java:492) ~[Loader.class:?] at cpw.mods.fml.server.FMLServerHandler.beginServerLoading(FMLServerHandler.java:87) ~[FMLServerHandler.class:?] at cpw.mods.fml.common.FMLCommonHandler.onServerStart(FMLCommonHandler.java:313) ~[FMLCommonHandler.class:?] at net.minecraft.server.dedicated.DedicatedServer.startServer(DedicatedServer.java:120) ~[DedicatedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:455) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762) [MinecraftServer$2.class:?] Caused by: java.lang.ClassNotFoundException: net.minecraft.client.entity.EntityClientPlayerMP at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:188) ~[launchwrapper-1.9.jar:?] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_51] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_51] ... 31 more Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/entity/EntityClientPlayerMP for invalid side SERVER at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:50) ~[forgeSrc-1.7.10-10.13.0.1180.jar:?] at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:276) ~[launchwrapper-1.9.jar:?] at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:174) ~[launchwrapper-1.9.jar:?] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_51] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_51] ... 31 more [18:43:16] [server thread/ERROR]: This crash report has been saved to: C:\Users\Erika\Desktop\FandomCraft\eclipse\.\crash-reports\crash-2014-09-14_18.43.16-server.txt [18:43:16] [server thread/WARN] [FML]: Can't revert to frozen GameData state without freezing first. [18:43:16] [server thread/INFO] [FML]: Applying holder lookups [18:43:16] [server thread/INFO] [FML]: Holder lookups applied [18:43:16] [server thread/INFO] [FML]: The state engine was in incorrect state ERRORED and forced into state SERVER_STOPPED. Errors may have been discarded. [18:43:16] [server thread/INFO] [FML]: The state engine was in incorrect state ERRORED and forced into state AVAILABLE. Errors may have been discarded. Before I added anything that uses EntityPlayer player = (EntityPlayer)event.entity; or EntityPlayer player = Minecraft.getMinecraft().thePlayer; it worked fine on servers, and in single player it works perfectly fine as it is now, so how exactly do I reference the player on a server if not either of those? The class it's pointing at now is this if someone needs to see the whole thing. There's probably other places, but I can't check until this one passes startup: package com.fandomcraft.events; import java.util.Random; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.client.gui.GuiChat; import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.server.MinecraftServer; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.DamageSource; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.EnderTeleportEvent; import org.lwjgl.input.Keyboard; import com.fandomcraft.entity.EntityEnergyBall; import com.fandomcraft.main.Main; import com.fandomcraft.zelda.Oocoo; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.InputEvent; public class KeyHandlerEvents { public static final String ocarina = "keybinds.ocarina"; public static final int key6 = Keyboard.KEY_NUMPAD7 ; public final KeyBinding bind6; public KeyHandlerEvents() { super(); bind6 = new KeyBinding("keybinds.ocarina.time", key6, ocarina); ClientRegistry.registerKeyBinding(bind6); } @SubscribeEvent public void checkKeybind(InputEvent.KeyInputEvent event) { EntityPlayer player = Minecraft.getMinecraft().thePlayer; if (!FMLClientHandler.instance().isGUIOpen(GuiChat.class)) { if (bind6.isPressed()) { World world = player.getEntityWorld(); if(player.inventory.getCurrentItem() !=null && player.inventory.getCurrentItem().getItem() == Main.ocarina && player.inventory.hasItem(Main.song7)) { player.playSound("fandomcraft:ocarina.timeSong", 1F, 1F); String time = keepTime(world); player.addChatMessage(new ChatComponentText("The time " + time + ".")); } else { player.addChatMessage(new ChatComponentText("You can't play that song unless you have the song page and are holding the Ocarina.")); } } } } public int ticks; public String keepTime(World world) { ticks = (int) world.getWorldTime(); if(ticks <= 1000) { return "is approximately 6:00 AM"; } if(ticks > 1000 && ticks <= 2000) { return "is approximately 7:00 AM"; } if(ticks > 2000 && ticks <= 3000) { return "is approximately 8:00 AM"; } if(ticks > 3000 && ticks <= 4000) { return "is approximately 9:00 AM"; } if(ticks > 4000 && ticks <= 5000) { return "is approximately 10:00 AM"; } if(ticks > 5000 && ticks <= 6000) { return "is approximately 11:00 AM"; } if(ticks > 6000 && ticks <= 7000) { return "is approximately 12:00 PM"; } if(ticks > 7000 && ticks <= 8000) { return "is approximately 1:00 AM"; } if(ticks > 8000 && ticks <= 9000) { return "is approximately 2:00 PM"; } if(ticks > 9000 && ticks <= 10000) { return "is approximately 3:00 PM"; } if(ticks > 10000 && ticks <= 11000) { return "is approximately 4:00 PM"; } if(ticks > 11000 && ticks <= 12000) { return "is approximately 5:00 PM"; } if(ticks > 12000 && ticks <= 13000) { return "is approximately 6:00 PM"; } if(ticks > 13000 && ticks <= 14000) { return "is approximately 7:00 PM"; } if(ticks > 14000 && ticks <= 15000) { return "is approximately 8:00 PM"; } if(ticks > 15000 && ticks <= 16000) { return "is approximately 9:00 PM"; } if(ticks > 16000 && ticks <= 17000) { return "is approximately 10:00 PM"; } if(ticks > 17000 && ticks <= 18000) { return "is approximately 11:00 PM"; } if(ticks > 18000 && ticks <= 19000) { return "is approximately 12:00 AM"; } if(ticks > 19000 && ticks <= 20000) { return "is approximately 1:00 AM"; } if(ticks > 20000 && ticks <= 21000) { return "is approximately 2:00 AM"; } if(ticks > 21000 && ticks <= 22000) { return "is approximately 3:00 AM"; } if(ticks > 22000 && ticks <= 23000) { return "is approximately 4:00 AM"; } if(ticks > 23000) { return "is approximately 5:00 AM"; } } }
September 15, 201411 yr Hi You might find this useful for getting the player on the server side http://greyminecraftcoder.blogspot.com.au/2013/10/server-side-class-linkage-map.html Using EntityPlayer player = Minecraft.getMinecraft().thePlayer on the server side will either fail outright or lead to intermittent bugs/crashes if the server thread accesses a client object at the same time as the client thread. -TGG
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.