Java Code Examples for net.minecraft.entity.player.EntityPlayer.moveEntity()

The following are Jave code examples for showing how to use moveEntity() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: SerenityCE   File: PredictionEngine.java   View Source Code Vote up 4 votes
public Vec3 predictPlayerLocation(EntityPlayer player, int ticksIntoFuture) {
    if (playerPositions.containsKey(player)) {
        List<Vec3> pastPositions = playerPositions.get(player);
        if (pastPositions.size() > 1) {
            Vec3 first = pastPositions.get(0);

            List<Vec3> deltas = new LinkedList<>();
            Vec3 previous = first;
            for (Vec3 position : pastPositions) {
                deltas.add(position.subtract(previous));
                previous = position;
            }

            Vec3 mean = Vec3.ORIGIN;
            for (Vec3 delta : deltas)
                mean = mean.add(delta);

            mean = mean.divideElements(deltas.size());

            EntityPlayer simulated = new EntityOtherPlayerMP(mc.theWorld, player.getGameProfile());
            simulated.noClip = false;
            simulated.setPosition(player.posX, player.posY, player.posZ);
            for (int i = 0; i < ticksIntoFuture; i++) {
                double x = mean.x, y = mean.y, z = mean.z;
                simulated.moveEntity(x, y, z);

                if (!player.capabilities.isFlying) {
                    y = y * 0.8 - 0.02;
                }
                if (simulated.onGround && y < 0) {
                    y = 0;
                }

                x *= 0.99;
                z *= 0.99;

                mean = new Vec3(x, y, z);
            }

            return new Vec3(simulated.posX, simulated.posY, simulated.posZ);
        }
    }
    return null;
}