Vitridax Posted March 2, 2016 Posted March 2, 2016 Edit: This first question is resolved. Scroll down to see my later questions. I created an entity (EntityPMPlayer) that extends EntityPlayerMP. When I tried spawning it in the exact same way I spawned an EntityPlayerMP the console spat out an error that it was missing the method <init>(net.minecraft.world.World). Why does it do this with my entity but not with EntityPlayerMP, and how can I fix it? EntityPMPlayer: Reveal hidden contents public class EntityPMPlayer extends EntityPlayerMP { public EntityPMPlayer(MinecraftServer server, WorldServer world,GameProfile profile, ItemInWorldManager interactionManager) { super(server, world, profile, interactionManager); } } Error: Reveal hidden contents [21:20:18] [Client thread/ERROR] [FML]: A severe problem occurred during the spawning of an entity java.lang.NoSuchMethodException: com.playermod.entity.playermob.EntityPMPlayer.<init>(net.minecraft.world.World) at java.lang.Class.getConstructor0(Class.java:3082) ~[?:1.8.0_45] at java.lang.Class.getConstructor(Class.java:1825) ~[?:1.8.0_45] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:93) [EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:56) [EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.access$000(EntitySpawnHandler.java:31) [EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler$1.run(EntitySpawnHandler.java:46) [EntitySpawnHandler$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_45] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_45] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709) [FMLCommonHandler.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1070) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_45] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_45] at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_45] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] [21:20:18] [Client thread/FATAL] [FML]: Exception caught executing FutureTask: java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.NoSuchMethodException: com.playermod.entity.playermob.EntityPMPlayer.<init>(net.minecraft.world.World) java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.NoSuchMethodException: com.playermod.entity.playermob.EntityPMPlayer.<init>(net.minecraft.world.World) at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_45] at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_45] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:710) [FMLCommonHandler.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1070) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_45] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_45] at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_45] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: com.playermod.entity.playermob.EntityPMPlayer.<init>(net.minecraft.world.World) at com.google.common.base.Throwables.propagate(Throwables.java:160) ~[guava-17.0.jar:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:142) ~[EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:56) ~[EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.access$000(EntitySpawnHandler.java:31) ~[EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler$1.run(EntitySpawnHandler.java:46) ~[EntitySpawnHandler$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_45] at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_45] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709) ~[FMLCommonHandler.class:?] ... 11 more Caused by: java.lang.NoSuchMethodException: com.playermod.entity.playermob.EntityPMPlayer.<init>(net.minecraft.world.World) at java.lang.Class.getConstructor0(Class.java:3082) ~[?:1.8.0_45] at java.lang.Class.getConstructor(Class.java:1825) ~[?:1.8.0_45] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:93) ~[EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:56) ~[EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.access$000(EntitySpawnHandler.java:31) ~[EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler$1.run(EntitySpawnHandler.java:46) ~[EntitySpawnHandler$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_45] at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_45] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709) ~[FMLCommonHandler.class:?] ... 11 more Quote I am very busy on the weekdays so don't expect me to make more than one post per day. If you curse in your responses to me I will smite you. It's as simple as that.
Vitridax Posted March 2, 2016 Author Posted March 2, 2016 Here is the code I use to spawn the player. Reveal hidden contents //create profile ServerConfigurationManager scm = MinecraftServer.getServer().getConfigurationManager(); String username = "Player_" + (scm.playerEntityList.size() + 1); UUID uuid = UUID.nameUUIDFromBytes(username.getBytes(Charsets.UTF_); GameProfile profile = new GameProfile(uuid, username); // login WorldServer overworldServer = MinecraftServer.getServer().worldServerForDimension(0); ItemInWorldManager worldItemManager = new ItemInWorldManager(overworldServer); //this works // EntityPlayerMP player = new EntityPlayerMP(MinecraftServer.getServer(), overworldServer, profile, worldItemManager); //this doesn't EntityPMPlayer player = new EntityPMPlayer(MinecraftServer.getServer(), overworldServer, profile, worldItemManager); SocketAddress address = Minecraft.getMinecraft().getIntegratedServer().getNetworkSystem().addLocalEndpoint(); NetworkManager netManager = NetworkManager.provideLocalClient(address); NetHandlerPlayServer nhps = new NetHandlerPlayServer(scm.getServerInstance(), netManager, player); scm.initializeConnectionToPlayer(netManager, player, nhps); Quote I am very busy on the weekdays so don't expect me to make more than one post per day. If you curse in your responses to me I will smite you. It's as simple as that.
GotoLink Posted March 2, 2016 Posted March 2, 2016 It does this because the constructor is missing. Explicit constructors need to be defined by the child class. See Java constructor rules. Quote
Vitridax Posted March 3, 2016 Author Posted March 3, 2016 On 3/2/2016 at 4:03 PM, GotoLink said: It does this because the constructor is missing. Explicit constructors need to be defined by the child class. See Java constructor rules. I know. The only problem is that I can't do a constructor with super(world) because EntityPlayerMP doesn't have that constructor either, but for some reason it works. I don't know how to do a constructor that just has one parameter (World world) while still referring to the EntityPlayerMP constructor (super(server, world, profile, interactionManager)) without making up lots of hard coded things to fill in the blanks. Quote I am very busy on the weekdays so don't expect me to make more than one post per day. If you curse in your responses to me I will smite you. It's as simple as that.
Ernio Posted March 3, 2016 Posted March 3, 2016 When entity is spawned on server a packet is sent to client telling to spawn client-sided representation of that entity. Those 2 entities are bound by entityId. All entities should have constructor that has one arg: World, because that is how they will be spawned on client (internally using that constructor). Now - EntityPlayer is different. While all other entities have one shared class, a player has class for Client and Server: Server: EntityPlayerMP Client: EntityPlayerSP + EntityOtherPlayerMP It is obvious that player is a special entity. So solution: DON'T EXTEND EntityPlayer! Make goddamn entity that behaves like player - it is much simpler and works better. And if you really want to make extension to players - you will need sided implementations (MP and OtherSP probably) and some ASM to make it work NICE. Without ASM you will messup a lot of things. It is not possible to spawn player like a normal mob. You need handlers that handle EntityPlayer (INetHandler). Quote Quote 1.7.10 is no longer supported by forge, you are on your own.
Vitridax Posted March 13, 2016 Author Posted March 13, 2016 Ok, so I've found a few problems that I can't seem to handle in the past few days. At first I kept trying to use the entity that extended from EntityPlayerMP, but there were so many things to override that I decided to just have a custom net handler only (extends from NetHandlerPlayServer, I called it NetHandlerPMPlayServer). I can link it with a player just fine, but for some reason EntityPlayerMP only updates(super.onUpdate()) when its net handler recieves a packet from the client (C03PacketPlayer), which is sent every tick in EntityPlayerSP's onUpdate(). Of course, my players don't have a client (except for the EntityOtherPlayerMP, which doesn't really count), so they aren't being updated. I tried to make my net handler "send itself" the packet in it's update() method, but that wasn't being called either. Instead I tried using the event PlayerTickEvent to call NetHandlerPMPlayer.update() whenever the EntityOtherPlayerMP version of my player ticked. This worked fine, but when I created an sent the packet in NetHandlerPMPlayer.update() MC crashes with a net.minecraft.network.ThreadQuickExitException. If you don't read ALL the above you might get confused, so just read it. In the end I have two questions: -Why isn't NetHandlerPMPlayServer.update() being called in vanilla code somewhere? -How can I make my net handler "send" itself packets? GitHub Source: https://github.com/Vitridax/PlayerMod.git Sorry if the files are a bit messy with all the comments everywhere. If you can't find something just ask. Edit: Crash. Sorry I forgot about it earlier. Reveal hidden contents [09:49:44] [Client thread/ERROR] [FML]: Exception caught during firing event net.minecraftforge.fml.common.gameevent.TickEvent$PlayerTickEvent@5db94eaf: net.minecraft.network.ThreadQuickExitException [09:49:44] [Client thread/ERROR] [FML]: Index: 1 Listeners: [09:49:44] [Client thread/ERROR] [FML]: 0: NORMAL [09:49:44] [Client thread/ERROR] [FML]: 1: ASM: com.playermod.event.PlayerModFMLEventHandler@4f3d49e4 playerTick(Lnet/minecraftforge/fml/common/gameevent/TickEvent$PlayerTickEvent;)V (some stuff omitted about unloading world) [09:49:51] [Client thread/FATAL]: Reported exception thrown! net.minecraft.util.ReportedException: Ticking entity at net.minecraft.world.World.updateEntities(World.java:1830) ~[World.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:2176) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1080) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_45] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_45] at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_45] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] Caused by: net.minecraft.network.ThreadQuickExitException Quote I am very busy on the weekdays so don't expect me to make more than one post per day. If you curse in your responses to me I will smite you. It's as simple as that.
Vitridax Posted March 14, 2016 Author Posted March 14, 2016 Bump Quote I am very busy on the weekdays so don't expect me to make more than one post per day. If you curse in your responses to me I will smite you. It's as simple as that.
Dylem Posted March 14, 2016 Posted March 14, 2016 For your first question, you could override EntityLivingBase's onEntityUpdate Quote
Vitridax Posted March 14, 2016 Author Posted March 14, 2016 On 3/14/2016 at 4:39 PM, Dylem said: For your first question, you could override EntityLivingBase's onEntityUpdate For what Entity? I can't change any vanilla classes and I'm trying not to use my old entity (EntityPMPlayerServer) because of all the problems it causes. Instead I'm just using the NetHandlerPMPlayServer. Or are you talking about the very first question I asked on March 2nd? That's resolved because I'm not using EntityPMPlayerServer anymore. Quote I am very busy on the weekdays so don't expect me to make more than one post per day. If you curse in your responses to me I will smite you. It's as simple as that.
Vitridax Posted March 16, 2016 Author Posted March 16, 2016 Bump. Quote I am very busy on the weekdays so don't expect me to make more than one post per day. If you curse in your responses to me I will smite you. It's as simple as that.
Vitridax Posted March 21, 2016 Author Posted March 21, 2016 I managed to solve my problems by myself. It took a week of many tests and crashes, but at least it was very informative. For the first question, my NetHandler wasn't being updated because it's manager was a client side manager. The server side manager it was connected to was stored in a private list in the NetworkSystem, so I got it using reflection, and used it for my NetHandler instead. For the second question, right now I'm just creating packets in NetHandlerPMPlayServer.update() and calling the correct method to handle the packet. I'm not sure if this will cause problems later, but for now it works. Quote I am very busy on the weekdays so don't expect me to make more than one post per day. If you curse in your responses to me I will smite you. It's as simple as that.
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.