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