Search in sources :

Example 1 with Linear

use of com.microsoft.Malmo.Schemas.AnimationDecorator.Linear in project malmo by Microsoft.

the class AnimationDecoratorImplementation method update.

@Override
public void update(World world) {
    this.tickCounter++;
    if (this.tickCounter < this.params.getTicksPerUpdate()) {
        this.tickCounter++;
        return;
    }
    this.frameCount++;
    this.tickCounter = 0;
    BlockPos oldpos = new BlockPos(this.origin);
    if (this.params.getLinear() != null) {
        Linear linear = this.params.getLinear();
        double dx = this.velocity.xCoord;
        double dy = this.velocity.yCoord;
        double dz = this.velocity.zCoord;
        if (this.drawContext.getMax().xCoord + dx > linear.getCanvasBounds().getMax().getX() + 1.0 || this.drawContext.getMin().xCoord + dx < linear.getCanvasBounds().getMin().getX())
            dx = -dx;
        if (this.drawContext.getMax().yCoord + dy > linear.getCanvasBounds().getMax().getY() + 1.0 || this.drawContext.getMin().yCoord + dy < linear.getCanvasBounds().getMin().getY())
            dy = -dy;
        if (this.drawContext.getMax().zCoord + dz > linear.getCanvasBounds().getMax().getZ() + 1.0 || this.drawContext.getMin().zCoord + dz < linear.getCanvasBounds().getMin().getZ())
            dz = -dz;
        this.velocity = new Vec3(dx, dy, dz);
        this.origin = this.origin.add(this.velocity);
    } else {
        try {
            double x = EvaluationHelper.eval(this.params.getParametric().getX(), this.frameCount, this.rng);
            double y = EvaluationHelper.eval(this.params.getParametric().getY(), this.frameCount, this.rng);
            double z = EvaluationHelper.eval(this.params.getParametric().getZ(), this.frameCount, this.rng);
            this.origin = new Vec3(x, y, z);
        } catch (Exception e) {
            // Just fail and move on.
            System.out.println("ERROR - check syntax of equations for animation.");
        }
    }
    BlockPos newpos = new BlockPos(this.origin);
    if (oldpos.equals(newpos))
        return;
    try {
        this.drawContext.setOrigin(this.origin);
        this.drawContext.Draw(this.params.getDrawingDecorator(), MinecraftServer.getServer().getEntityWorld());
        this.drawContext.clearPrevious(MinecraftServer.getServer().getEntityWorld());
    } catch (Exception e) {
        System.out.println("ERROR - can not draw animation.");
    }
}
Also used : Vec3(net.minecraft.util.Vec3) BlockPos(net.minecraft.util.BlockPos) Linear(com.microsoft.Malmo.Schemas.AnimationDecorator.Linear)

Example 2 with Linear

use of com.microsoft.Malmo.Schemas.AnimationDecorator.Linear in project malmo by Microsoft.

the class AnimationDecoratorImplementation method parseParameters.

@Override
public boolean parseParameters(Object params) {
    if (params == null || !(params instanceof AnimationDecorator))
        return false;
    this.params = (AnimationDecorator) params;
    // Initialise starting positions / velocities:
    if (this.params.getLinear() != null) {
        Linear linear = this.params.getLinear();
        this.origin = new Vec3(linear.getInitialPos().getX().doubleValue(), linear.getInitialPos().getY().doubleValue(), linear.getInitialPos().getZ().doubleValue());
        this.velocity = new Vec3(linear.getInitialVelocity().getX().doubleValue(), linear.getInitialVelocity().getY().doubleValue(), linear.getInitialVelocity().getZ().doubleValue());
        this.minCanvas = new Vec3(linear.getCanvasBounds().getMin().getX(), linear.getCanvasBounds().getMin().getY(), linear.getCanvasBounds().getMin().getZ());
        this.maxCanvas = new Vec3(linear.getCanvasBounds().getMax().getX(), linear.getCanvasBounds().getMax().getY(), linear.getCanvasBounds().getMax().getZ());
    } else {
        // Initialise a RNG:
        long seed = 0;
        String strSeed = this.params.getParametric().getSeed();
        if (strSeed == null || strSeed == "" || strSeed.equals("random"))
            seed = System.currentTimeMillis();
        else
            seed = Long.parseLong(strSeed);
        this.rng = new Random(seed);
        try {
            double x = EvaluationHelper.eval(this.params.getParametric().getX(), 0, this.rng);
            double y = EvaluationHelper.eval(this.params.getParametric().getY(), 0, this.rng);
            double z = EvaluationHelper.eval(this.params.getParametric().getZ(), 0, this.rng);
            this.origin = new Vec3(x, y, z);
        } catch (Exception e) {
            // Malformed equations.
            System.out.println("ERROR: malformed equations in animation - check these:");
            System.out.println("        " + this.params.getParametric().getX());
            System.out.println("        " + this.params.getParametric().getY());
            System.out.println("        " + this.params.getParametric().getZ());
        }
    }
    return true;
}
Also used : Random(java.util.Random) AnimationDecorator(com.microsoft.Malmo.Schemas.AnimationDecorator) Vec3(net.minecraft.util.Vec3) Linear(com.microsoft.Malmo.Schemas.AnimationDecorator.Linear)

Aggregations

Linear (com.microsoft.Malmo.Schemas.AnimationDecorator.Linear)2 Vec3 (net.minecraft.util.Vec3)2 AnimationDecorator (com.microsoft.Malmo.Schemas.AnimationDecorator)1 Random (java.util.Random)1 BlockPos (net.minecraft.util.BlockPos)1