Jump to content

Recommended Posts

Posted

I can spawn a cow, but it seems only on the client side.  The cow disappears after a moment, which is my clue that it is only happening on client side.

 

I figured the best approach was to send a message to the server, and then spawn the cow within that context.  I was able to send the message successfully, and verified that the "side" is "SERVER", but when I attempt to spawn the cow, it again appears to spawn on the client instead.

 

Apologies in advance.  Long time programmer, but this minecraft modding has me back to the "hello world" stage apparently.

 

Here's the code (in my message handler class) that receives the message from client side:

 

	@Override
	public IMessage onMessage(MoshMessage message, MessageContext ctx) {

		// this works as expected, indicating (I think) that I have received a message from client-side.
		System.out.println("I got a message [" + message.msg + "] from " + ctx.getServerHandler().playerEntity.getDisplayName());

		// this says "SERVER" as expected
		System.out.println("side: " + ctx.side.toString());

		// this works as expected, time is set to 0
		ctx.getServerHandler().playerEntity.worldObj.setWorldTime(0);

		// This DOESN'T work as expected.  The cow is spawned client-side and disappears soon after.
		// I want it to spawn on server-side.
		Entity e = new EntityCow(ctx.getServerHandler().playerEntity.worldObj);
		e.posX = ctx.getServerHandler().playerEntity.posX;
		e.posY = ctx.getServerHandler().playerEntity.posY;
		e.posZ = ctx.getServerHandler().playerEntity.posZ;			
		ctx.getServerHandler().playerEntity.worldObj.spawnEntityInWorld(e);

		return null;
	}

 

I'm probably overlooking a simple concept here so I would appreciate any guidance.

 

Thanks,

John

Posted

I've run into a problem similar to this before, and it's definitely not your fault. :P

 

You need to set the entity's angles too.

e.setLocationAndAngles(player.posX, player.posY, player.posZ, 0, 0);

Kain

Posted

Did the trick.  Thank you much!  Odd that the pitch and yaw aren't set to 0 by default - oh well.

 

Follow up, if I can trouble you a bit more: 

 

My end goal is to be able to spawn a player model (as an NPC) and assign arbitrary AI to it.  EntityPlayerMP seems too heavy for this purpose, because it contains a lot of logic for an actual "player", and I just want the NPC version of it. 

 

Is this something I need to put together manually (model/texture -> class extended from EntityLivingBase)?  If so, no worries, I'll figure it out.

 

I was looking at extending from EntityVillager perhaps?  But I want to use the player model, so maybe a custom binding - not sure still exploring.

 

Thanks again,

John

 

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.