Jump to content

Recommended Posts

Posted

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:

 

 

public class EntityPMPlayer extends EntityPlayerMP {

 

public EntityPMPlayer(MinecraftServer server, WorldServer world,GameProfile profile, ItemInWorldManager interactionManager) {

super(server, world, profile, interactionManager);

 

}

 

}

 

 

 

Error:

 

 

[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

 

 

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.

Posted

Here is the code I use to spawn the player.

 

 

 

//create profile

ServerConfigurationManager scm = MinecraftServer.getServer().getConfigurationManager();

 

String username = "Player_" + (scm.playerEntityList.size() + 1);

UUID uuid = UUID.nameUUIDFromBytes(username.getBytes(Charsets.UTF_8));

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);

 

 

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.

Posted

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.

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.

Posted

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).

 

1.7.10 is no longer supported by forge, you are on your own.

  • 2 weeks later...
Posted

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.

 

 

[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

 

 

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.

Posted

Bump

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.

Posted

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.

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.

Posted

Bump.

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.

Posted

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.

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.

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



×
×
  • Create New...

Important Information

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