I'm trying to add a feature to a mod (1.12.2 currently, and ideally 1.8.9 as well) which will allow me to spawn an entity (armor stand) and control its movement. For testing, I'm having the entity copy my movements, offset by x = 2. I need to do everything client-side because I want it to run on a server to which I don't have access. Here is a thread which I am running via a command. "player" is the command sender, "world" is Minecraft.getInstance().world, and "mil" is just the milliseconds between updates.
class EntityThread extends Thread {
Entity player;
int mil;
World world;
EntityThread(EntityPlayer player, World world, int mil) {
this.player = player;
this.mil = mil;
this.world = world;
}
public void run() {
if (this.world.isRemote == true) {
TKRS.message("Not server side.");
}
double x = player.posX + 2;
double y = player.posY;
double z = player.posZ;
double vx = player.motionX;
double vy = player.motionY;
double vz = player.motionZ;
float yaw = player.rotationYaw;
float pitch = player.rotationPitch;
Entity entity = new net.minecraft.entity.item.EntityArmorStand(world, x, y, z);
world.spawnEntity(entity);
for (int i = 0; i < (int)(10000/mil); i++) {
try {
Thread.sleep(this.mil);
} catch (InterruptedException e) {
e.printStackTrace();
}
x = player.posX + 2;
y = player.posY;
z = player.posZ;
vx = player.motionX;
vy = player.motionY;
vz = player.motionZ;
yaw = player.rotationYaw;
pitch = player.rotationPitch;
entity.setLocationAndAngles(x, y, z, yaw, pitch);
entity.setVelocity(vx, vy, vz);
entity.velocityChanged = true;
world.updateEntity(entity);
}
world.removeEntity(entity);
}
}
This works OK both in single-player and on a server, except that it is very jittery because the position is only updating 20 times per second, and the velocity does not update at all. If I provide a server world to the EntityThread (only possible in singleplayer), it is smooth with velocity updates, but lags behind my movements for some reason (client-side world doesn't lag, just jittery).
So my question is, how can I update the velocity for an entity spawned on client-side, without significant lag? I've tried looking up how to simulate clientbound packets from a non-existent server to update the velocity, but no luck so far.