Jump to content

[1.8] Creating a Fake Client


Vitridax

Recommended Posts

I'm trying to make a mod that adds computer controlled players into the game. I want to make them as close to players as possible (at least in their abilities, the AI probably will be a bit harder). This means that spawners will activate with them nearby, players can't sleep unless my computer ones are in their beds too, death messages etc. I think the easiest way to do this is to make them extend from EntityPlayerMP and be treated as clients. I managed to make several fake clients with the following code:

 

// construct 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
EntityPlayerMP fakePlayer = scm.createPlayerForUser(profile);

SocketAddress address = Minecraft.getMinecraft().getIntegratedServer().getNetworkSystem().addLocalEndpoint();
NetworkManager netManager = NetworkManager.provideLocalClient(address);
NetHandlerPlayServer nhps = new NetHandlerPlayServer(scm.getServerInstance(), netManager, fakePlayer);

scm.initializeConnectionToPlayer(netManager, fakePlayer, nhps);

 

I don't know much about NetworkManager or NetHandlerPlayServer, but I made this code by looking into what happens when someone logs in and just went from there. Is this a good method for making fake clients, or is there an alternate one that is better? I looked around for tutorials and couldn't find any so if there is one please tell me. Also, I'm not looking for FakePlayers (the thing in forge util).

 

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.

Link to comment
Share on other sites

Also, I'm not looking for FakePlayers (the thing in forge util).

 

I already knew about them, but thanks for trying  ;). It seems like people don't have much suggestions so I'll wait another day and then I'll just assume my method is fine and that there are no tutorials on NetworkManager.

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.

Link to comment
Share on other sites

Also, I'm not looking for FakePlayers (the thing in forge util).

 

I already knew about them, but thanks for trying  ;). It seems like people don't have much suggestions so I'll wait another day and then I'll just assume my method is fine and that there are no tutorials on NetworkManager.

 

Ohh... my fault, Sorry.

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

Link to comment
Share on other sites

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.