Search in sources :

Example 1 with MessageSkyhookSync

use of blusunrize.immersiveengineering.common.util.network.MessageSkyhookSync in project ImmersiveEngineering by BluSunrize.

the class EntitySkylineHook method onUpdate.

@Override
public void onUpdate() {
    EntityPlayer player = null;
    //		if(this.getControllingPassenger() instanceof EntityPlayer)
    //			player = ((EntityPlayer)this.getControllingPassenger());
    List<Entity> list = this.getPassengers();
    if (!list.isEmpty() && list.get(0) instanceof EntityPlayer)
        player = (EntityPlayer) list.get(0);
    if (this.ticksExisted == 1 && !worldObj.isRemote) {
        IELogger.debug("init tick at " + System.currentTimeMillis());
        if (player instanceof EntityPlayerMP)
            ImmersiveEngineering.packetHandler.sendTo(new MessageSkyhookSync(this), (EntityPlayerMP) player);
    }
    super.onUpdate();
    //			return;
    if (subPoints != null && targetPoint < subPoints.length - 1) {
        double dist = subPoints[targetPoint].distanceTo(new Vec3d(posX, posY, posZ));
        IELogger.debug("dist: " + dist);
        if (dist <= 0) {
            this.posX = subPoints[targetPoint].xCoord;
            this.posY = subPoints[targetPoint].yCoord;
            this.posZ = subPoints[targetPoint].zCoord;
            targetPoint++;
            if (player instanceof EntityPlayerMP)
                ImmersiveEngineering.packetHandler.sendTo(new MessageSkyhookSync(this), (EntityPlayerMP) player);
            IELogger.debug("next vertex: " + targetPoint);
            return;
        }
        float speed = 2f;
        if (player != null && player.getActiveItemStack() != null && player.getActiveItemStack().getItem() instanceof ItemSkyhook)
            speed = ((ItemSkyhook) player.getActiveItemStack().getItem()).getSkylineSpeed(player.getActiveItemStack());
        Vec3d moveVec = SkylineHelper.getSubMovementVector(new Vec3d(posX, posY, posZ), subPoints[targetPoint], speed);
        //*speed;
        motionX = moveVec.xCoord;
        //*speed;
        motionY = moveVec.yCoord;
        //*speed;
        motionZ = moveVec.zCoord;
    }
    if (target != null && targetPoint == subPoints.length - 1) {
        TileEntity end = this.worldObj.getTileEntity(target);
        IImmersiveConnectable iicEnd = ApiUtils.toIIC(end, worldObj);
        if (iicEnd == null) {
            this.setDead();
            return;
        }
        Vec3d vEnd = new Vec3d(target.getX(), target.getY(), target.getZ());
        vEnd = Utils.addVectors(vEnd, iicEnd.getConnectionOffset(connection));
        double gDist = vEnd.distanceTo(new Vec3d(posX, posY, posZ));
        IELogger.debug("distance to goal: " + gDist);
        if (gDist <= .3) {
            reachedTarget(end);
            return;
        } else if (gDist > 5) {
            setDead();
            return;
        }
    }
    this.posX += this.motionX;
    this.posY += this.motionY;
    this.posZ += this.motionZ;
    float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
    this.rotationYaw = (float) (Math.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) + 90.0F;
    for (this.rotationPitch = (float) (Math.atan2((double) f1, this.motionY) * 180.0D / Math.PI) - 90.0F; this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) ;
    while (this.rotationPitch - this.prevRotationPitch >= 180.0F) this.prevRotationPitch += 360.0F;
    while (this.rotationYaw - this.prevRotationYaw < -180.0F) this.prevRotationYaw -= 360.0F;
    while (this.rotationYaw - this.prevRotationYaw >= 180.0F) this.prevRotationYaw += 360.0F;
    this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
    this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
    if (this.isInWater()) {
        for (int j = 0; j < 4; ++j) {
            float f3 = 0.25F;
            this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * (double) f3, this.posY - this.motionY * (double) f3, this.posZ - this.motionZ * (double) f3, this.motionX, this.motionY, this.motionZ);
        }
    }
    if (player != null) {
        double dx = this.posX - this.prevPosX;
        double dy = this.posY - this.prevPosY;
        double dz = this.posZ - this.prevPosZ;
        int distTrvl = Math.round(MathHelper.sqrt_double(dx * dx + dy * dy + dz * dz) * 100.0F);
        if (distTrvl > 0)
            player.addStat(IEAchievements.statDistanceSkyhook, distTrvl);
        if (!worldObj.isRemote && SkylineHelper.isInBlock(player, worldObj)) {
        //				setDead();
        //				player.setPosition(posX-3*dx, posY-3*dy+getMountedYOffset(),posZ-3*dz);
        }
    //TODO
    //			if(player instanceof EntityPlayerMP)
    //				if(((EntityPlayerMP)player).getStatFile().func_150870_b(IEAchievements.statDistanceSkyhook)>100000)
    //					player.triggerAchievement(IEAchievements.skyhookPro);
    }
    this.setPosition(this.posX, this.posY, this.posZ);
}
Also used : MessageSkyhookSync(blusunrize.immersiveengineering.common.util.network.MessageSkyhookSync) TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) ItemSkyhook(blusunrize.immersiveengineering.common.items.ItemSkyhook) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)1 ItemSkyhook (blusunrize.immersiveengineering.common.items.ItemSkyhook)1 MessageSkyhookSync (blusunrize.immersiveengineering.common.util.network.MessageSkyhookSync)1 Entity (net.minecraft.entity.Entity)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Vec3d (net.minecraft.util.math.Vec3d)1